Processing-Examples.js 6.7 KB

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