Processing-Examples.js 6.7 KB

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