Processing-Examples.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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,myDY;
  44. return smalltalk.withContext(function($ctx1) { _st(self["@processing"])._strokeWeight_(aWeight);
  45. myDX=_st(self["@centerX"]).__plus(_st(_st(_st((smalltalk.Math || Math))._sin_(_st(_st(aPosition).__star((2))).__star(_st((smalltalk.Math || Math))._PI()))).__star(aLengthScale)).__star(self["@maxArmLength"]));
  46. myDY=_st(self["@centerY"]).__minus(_st(_st(_st((smalltalk.Math || Math))._cos_(_st(_st(aPosition).__star((2))).__star(_st((smalltalk.Math || Math))._PI()))).__star(aLengthScale)).__star(self["@maxArmLength"]));
  47. _st(self["@processing"])._line_y_dX_dy_(self["@centerX"],self["@centerY"],myDX,myDY);
  48. return self}, function($ctx1) {$ctx1.fill(self,"drawArm:lengthScale:weight:",{aPosition:aPosition,aLengthScale:aLengthScale,aWeight:aWeight,myDX:myDX,myDY:myDY}, smalltalk.ProcessingClock)})},
  49. args: ["aPosition", "aLengthScale", "aWeight"],
  50. 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.",
  51. messageSends: ["strokeWeight:", "+", "*", "sin:", "PI", "-", "cos:", "line:y:dX:dy:"],
  52. referencedClasses: ["Math"]
  53. }),
  54. smalltalk.ProcessingClock);
  55. smalltalk.addMethod(
  56. "_firstProcessingInstance",
  57. smalltalk.method({
  58. selector: "firstProcessingInstance",
  59. category: 'not yet classified',
  60. fn: function (){
  61. var self=this;
  62. return smalltalk.withContext(function($ctx1) { return Processing.instances[0];
  63. return self}, function($ctx1) {$ctx1.fill(self,"firstProcessingInstance",{}, smalltalk.ProcessingClock)})},
  64. args: [],
  65. source: "firstProcessingInstance\x0a\x0a\x09<return Processing.instances[0]>",
  66. messageSends: [],
  67. referencedClasses: []
  68. }),
  69. smalltalk.ProcessingClock);
  70. smalltalk.addMethod(
  71. "_initialize",
  72. smalltalk.method({
  73. selector: "initialize",
  74. category: 'not yet classified',
  75. fn: function (){
  76. var self=this;
  77. return smalltalk.withContext(function($ctx1) { self["@processing"]=_st(self)._firstProcessingInstance();
  78. self["@centerX"]=_st(_st(self["@processing"])._width()).__slash((2));
  79. self["@centerY"]=_st(_st(self["@processing"])._height()).__slash((2));
  80. self["@maxArmLength"]=_st((smalltalk.Math || Math))._min_or_(self["@centerX"],self["@centerY"]);
  81. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{}, smalltalk.ProcessingClock)})},
  82. args: [],
  83. source: "initialize\x0aprocessing := self firstProcessingInstance.\x0acenterX := processing width / 2.\x0acenterY := processing height / 2.\x0amaxArmLength := Math min: centerX or: centerY. ",
  84. messageSends: ["firstProcessingInstance", "/", "width", "height", "min:or:"],
  85. referencedClasses: ["Math"]
  86. }),
  87. smalltalk.ProcessingClock);
  88. smalltalk.addMethod(
  89. "_processing",
  90. smalltalk.method({
  91. selector: "processing",
  92. category: 'not yet classified',
  93. fn: function (){
  94. var self=this;
  95. return smalltalk.withContext(function($ctx1) { var $1;
  96. $1=self["@processing"];
  97. return $1;
  98. }, function($ctx1) {$ctx1.fill(self,"processing",{}, smalltalk.ProcessingClock)})},
  99. args: [],
  100. source: "processing\x0a^processing",
  101. messageSends: [],
  102. referencedClasses: []
  103. }),
  104. smalltalk.ProcessingClock);
  105. smalltalk.addMethod(
  106. "_init",
  107. smalltalk.method({
  108. selector: "init",
  109. category: 'not yet classified',
  110. fn: function (){
  111. var self=this;
  112. var clock,processing,block;
  113. return smalltalk.withContext(function($ctx1) { clock=_st((smalltalk.ProcessingClock || ProcessingClock))._new();
  114. processing=_st(clock)._processing();
  115. block=_st(clock)._draw();
  116. _st(processing)._at_put_("draw",block);
  117. return self}, function($ctx1) {$ctx1.fill(self,"init",{clock:clock,processing:processing,block:block}, smalltalk.ProcessingClock.klass)})},
  118. args: [],
  119. source: "init\x0a| clock processing block |\x0aclock := ProcessingClock new .\x0aprocessing := clock processing.\x0ablock := clock draw.\x0aprocessing at: 'draw' put: block\x0a ",
  120. messageSends: ["new", "processing", "draw", "at:put:"],
  121. referencedClasses: ["ProcessingClock"]
  122. }),
  123. smalltalk.ProcessingClock.klass);