Processing-Examples.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. smalltalk.addPackage('Processing-Examples', {});
  2. smalltalk.addClass('ProcessingClock', smalltalk.Object, ['processing', 'centerX', 'centerY', 'maxArmLength'], 'Processing-Examples');
  3. smalltalk.addMethod(
  4. "_draw",
  5. smalltalk.method({
  6. selector: "draw",
  7. category: 'not yet classified',
  8. fn: function () {
  9. var self = this;
  10. var drawBlock;
  11. drawBlock = function () {var now;var hoursPosition;var minutesPosition;var secondsPosition;smalltalk.send(self['@processing'], "_background_", [224]);now = smalltalk.send(smalltalk.Date || Date, "_new", []);hoursPosition = smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(now, "_hours", []), "_\\\\", [12]), "__plus", [smalltalk.send(now, "_minutes", [])]), "__slash", [60]), "__slash", [12]);smalltalk.send(self, "_drawArm_lengthScale_weight_", [hoursPosition, 0.5, 5]);minutesPosition = smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(now, "_minutes", []), "__plus", [smalltalk.send(now, "_seconds", [])]), "__slash", [60]), "__slash", [60]);smalltalk.send(self, "_drawArm_lengthScale_weight_", [minutesPosition, 0.8, 3]);secondsPosition = smalltalk.send(smalltalk.send(now, "_seconds", []), "__slash", [60]);return smalltalk.send(self, "_drawArm_lengthScale_weight_", [secondsPosition, 0.9, 1]);};
  12. return drawBlock;
  13. },
  14. args: [],
  15. source: "draw\x0a| drawBlock |\x0a\x0adrawBlock := [\x0a | now hoursPosition minutesPosition secondsPosition | \x0a processing background: 224.\x0a \x0a now := Date new.\x0a \x0a \x22Moving hours arm by small increments\x22\x0a hoursPosition := now hours \x5c\x5c 12 + now minutes / 60 / 12.\x0a self drawArm: hoursPosition lengthScale: 0.5 weight: 5.\x0a \x0a \x22Moving minutes arm by small increments\x22\x0a minutesPosition := now minutes + now seconds / 60 / 60.\x0a self drawArm: minutesPosition lengthScale: 0.80 weight: 3.\x0a\x0a \x22Moving hour arm by second increments\x22\x0a secondsPosition := now seconds / 60.\x0a self drawArm: secondsPosition lengthScale: 0.90 weight: 1.\x0a ].\x0a\x0a^drawBlock",
  16. messageSends: ["background:", "new", "/", "+", "minutes", "\x5c\x5c\x5c\x5c", "hours", "drawArm:lengthScale:weight:", "seconds"],
  17. referencedClasses: ["Date"]
  18. }),
  19. smalltalk.ProcessingClock);
  20. smalltalk.addMethod(
  21. "_drawArm_lengthScale_weight_",
  22. smalltalk.method({
  23. selector: "drawArm:lengthScale:weight:",
  24. category: 'not yet classified',
  25. fn: function (aPosition, aLengthScale, aWeight) {
  26. var self = this;
  27. var myDX;
  28. var myDY;
  29. smalltalk.send(self['@processing'], "_strokeWeight_", [aWeight]);
  30. myDX = smalltalk.send(self['@centerX'], "__plus", [smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.Math || Math, "_sin_", [smalltalk.send(smalltalk.send(aPosition, "__star", [2]), "__star", [smalltalk.send(smalltalk.Math || Math, "_PI", [])])]), "__star", [aLengthScale]), "__star", [self['@maxArmLength']])]);
  31. myDY = smalltalk.send(self['@centerY'], "__minus", [smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.Math || Math, "_cos_", [smalltalk.send(smalltalk.send(aPosition, "__star", [2]), "__star", [smalltalk.send(smalltalk.Math || Math, "_PI", [])])]), "__star", [aLengthScale]), "__star", [self['@maxArmLength']])]);
  32. smalltalk.send(self['@processing'], "_line_y_dX_dy_", [self['@centerX'], self['@centerY'], myDX, myDY]);
  33. return self;
  34. },
  35. args: ["aPosition", "aLengthScale", "aWeight"],
  36. source: "drawArm: aPosition lengthScale: aLengthScale weight: aWeight\x0a| myDX myDY |\x0aprocessing strokeWeight: aWeight.\x0amyDX := centerX \x0a\x09\x09\x09+ ((Math sin: (aPosition * 2 * Math PI))\x0a\x09\x09\x09* aLengthScale * maxArmLength).\x0amyDY := centerY \x0a\x09\x09\x09- ((Math cos: (aPosition * 2 * Math PI))\x0a\x09\x09\x09* aLengthScale * maxArmLength).\x0a\x0aprocessing line: centerX y: centerY dX: myDX dy: myDY.",
  37. messageSends: ["strokeWeight:", "+", "*", "sin:", "PI", "-", "cos:", "line:y:dX:dy:"],
  38. referencedClasses: ["Math"]
  39. }),
  40. smalltalk.ProcessingClock);
  41. smalltalk.addMethod(
  42. "_initialize",
  43. smalltalk.method({
  44. selector: "initialize",
  45. category: 'not yet classified',
  46. fn: function () {
  47. var self = this;
  48. self['@processing'] = Processing.instances[0];
  49. self['@centerX'] = smalltalk.send(smalltalk.send(self['@processing'], "_width", []), "__slash", [2]);
  50. self['@centerY'] = smalltalk.send(smalltalk.send(self['@processing'], "_height", []), "__slash", [2]);
  51. self['@maxArmLength'] = smalltalk.send(smalltalk.Math || Math, "_min_or_", [self['@centerX'], self['@centerY']]);
  52. return self;
  53. },
  54. args: [],
  55. source: "initialize\x0aprocessing := <Processing.instances[0]>.\x0acenterX := processing width / 2.\x0acenterY := processing height / 2.\x0amaxArmLength := Math min: centerX or: centerY.",
  56. messageSends: ["/", "width", "height", "min:or:"],
  57. referencedClasses: ["Math"]
  58. }),
  59. smalltalk.ProcessingClock);
  60. smalltalk.addMethod(
  61. "_processing",
  62. smalltalk.method({
  63. selector: "processing",
  64. category: 'not yet classified',
  65. fn: function () {
  66. var self = this;
  67. return self['@processing'];
  68. },
  69. args: [],
  70. source: "processing\x0a^processing",
  71. messageSends: [],
  72. referencedClasses: []
  73. }),
  74. smalltalk.ProcessingClock);
  75. smalltalk.addMethod(
  76. "_init",
  77. smalltalk.method({
  78. selector: "init",
  79. category: 'not yet classified',
  80. fn: function () {
  81. var self = this;
  82. var clock;
  83. var processing;
  84. var block;
  85. clock = smalltalk.send(smalltalk.ProcessingClock || ProcessingClock, "_new", []);
  86. processing = smalltalk.send(clock, "_processing", []);
  87. block = smalltalk.send(clock, "_draw", []);
  88. processing.draw = block;
  89. return self;
  90. },
  91. args: [],
  92. source: "init\x0a| clock processing block |\x0aclock := ProcessingClock new .\x0aprocessing := clock processing.\x0ablock := clock draw.\x0a<processing.draw=block>\x0a ",
  93. messageSends: ["new", "processing", "draw"],
  94. referencedClasses: ["ProcessingClock"]
  95. }),
  96. smalltalk.ProcessingClock.klass);