2
0

Processing-Examples.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. return smalltalk.withContext(function($ctx1) { var $1;
  12. drawBlock=(function(){
  13. var now,hoursPosition,minutesPosition,secondsPosition;
  14. return smalltalk.withContext(function($ctx2) { _st(self["@processing"])._background_((224));
  15. now=_st((smalltalk.Date || Date))._new();
  16. now;
  17. hoursPosition=_st(_st(_st(_st(_st(now)._hours()).__backslash_backslash((12))).__plus(_st(now)._minutes())).__slash((60))).__slash((12));
  18. hoursPosition;
  19. _st(self)._drawArm_lengthScale_weight_(hoursPosition,(0.5),(5));
  20. minutesPosition=_st(_st(_st(_st(now)._minutes()).__plus(_st(now)._seconds())).__slash((60))).__slash((60));
  21. minutesPosition;
  22. _st(self)._drawArm_lengthScale_weight_(minutesPosition,(0.8),(3));
  23. secondsPosition=_st(_st(now)._seconds()).__slash((60));
  24. secondsPosition;
  25. return _st(self)._drawArm_lengthScale_weight_(secondsPosition,(0.9),(1));
  26. }, function($ctx2) {$ctx2.fillBlock({now:now,hoursPosition:hoursPosition,minutesPosition:minutesPosition,secondsPosition:secondsPosition},$ctx1)})});
  27. $1=drawBlock;
  28. return $1;
  29. }, function($ctx1) {$ctx1.fill(self,"draw",{drawBlock:drawBlock}, smalltalk.ProcessingClock)})},
  30. args: [],
  31. 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",
  32. messageSends: ["background:", "new", "/", "+", "minutes", "\x5c\x5c", "hours", "drawArm:lengthScale:weight:", "seconds"],
  33. referencedClasses: ["Date"]
  34. }),
  35. smalltalk.ProcessingClock);
  36. smalltalk.addMethod(
  37. "_drawArm_lengthScale_weight_",
  38. smalltalk.method({
  39. selector: "drawArm:lengthScale:weight:",
  40. category: 'not yet classified',
  41. fn: function (aPosition, aLengthScale, aWeight) {
  42. var self = this;
  43. var myDX;
  44. var myDY;
  45. smalltalk.send(self['@processing'], "_strokeWeight_", [aWeight]);
  46. 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']])]);
  47. 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']])]);
  48. smalltalk.send(self['@processing'], "_line_y_dX_dy_", [self['@centerX'], self['@centerY'], myDX, myDY]);
  49. return self;
  50. },
  51. args: ["aPosition", "aLengthScale", "aWeight"],
  52. 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.",
  53. messageSends: ["strokeWeight:", "+", "*", "sin:", "PI", "-", "cos:", "line:y:dX:dy:"],
  54. referencedClasses: ["Math"]
  55. }),
  56. smalltalk.ProcessingClock);
  57. smalltalk.addMethod(
  58. "_initialize",
  59. smalltalk.method({
  60. selector: "initialize",
  61. category: 'not yet classified',
  62. fn: function () {
  63. var self = this;
  64. self['@processing'] = Processing.instances[0];
  65. self['@centerX'] = smalltalk.send(smalltalk.send(self['@processing'], "_width", []), "__slash", [2]);
  66. self['@centerY'] = smalltalk.send(smalltalk.send(self['@processing'], "_height", []), "__slash", [2]);
  67. self['@maxArmLength'] = smalltalk.send(smalltalk.Math || Math, "_min_or_", [self['@centerX'], self['@centerY']]);
  68. return self;
  69. },
  70. args: [],
  71. source: "initialize\x0aprocessing := <Processing.instances[0]>.\x0acenterX := processing width / 2.\x0acenterY := processing height / 2.\x0amaxArmLength := Math min: centerX or: centerY.",
  72. messageSends: ["/", "width", "height", "min:or:"],
  73. referencedClasses: ["Math"]
  74. }),
  75. smalltalk.ProcessingClock);
  76. smalltalk.addMethod(
  77. "_processing",
  78. smalltalk.method({
  79. selector: "processing",
  80. category: 'not yet classified',
  81. fn: function () {
  82. var self = this;
  83. return self['@processing'];
  84. },
  85. args: [],
  86. source: "processing\x0a^processing",
  87. messageSends: [],
  88. referencedClasses: []
  89. }),
  90. smalltalk.ProcessingClock);
  91. smalltalk.addMethod(
  92. "_init",
  93. smalltalk.method({
  94. selector: "init",
  95. category: 'not yet classified',
  96. fn: function () {
  97. var self = this;
  98. var clock;
  99. var processing;
  100. var block;
  101. clock = smalltalk.send(smalltalk.ProcessingClock || ProcessingClock, "_new", []);
  102. processing = smalltalk.send(clock, "_processing", []);
  103. block = smalltalk.send(clock, "_draw", []);
  104. processing.draw = block;
  105. return self;
  106. },
  107. args: [],
  108. source: "init\x0a| clock processing block |\x0aclock := ProcessingClock new .\x0aprocessing := clock processing.\x0ablock := clock draw.\x0a<processing.draw=block>\x0a ",
  109. messageSends: ["new", "processing", "draw"],
  110. referencedClasses: ["ProcessingClock"]
  111. }),
  112. smalltalk.ProcessingClock.klass);