2
0

Processing-Examples.st 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. Smalltalk createPackage: 'Processing-Examples'!
  2. Object subclass: #ProcessingClock
  3. instanceVariableNames: 'processing centerX centerY maxArmLength'
  4. package: 'Processing-Examples'!
  5. !ProcessingClock methodsFor: 'not yet classified'!
  6. draw
  7. | drawBlock |
  8. drawBlock := [
  9. | now hoursPosition minutesPosition secondsPosition |
  10. processing background: 224.
  11. now := Date new.
  12. "Moving hours arm by small increments"
  13. hoursPosition := ((now hours \\ 12) + (now minutes / 60 )) /12 .
  14. self drawArm: hoursPosition lengthScale: 0.5 weight: 5.
  15. "Moving minutes arm by small increments"
  16. minutesPosition := (now minutes + (now seconds / 60))/60.
  17. self drawArm: minutesPosition lengthScale: 0.80 weight: 3.
  18. "Moving hour arm by second increments"
  19. secondsPosition := now seconds / 60.
  20. self drawArm: secondsPosition lengthScale: 0.90 weight: 1.
  21. ].
  22. ^drawBlock
  23. !
  24. drawArm: aPosition lengthScale: aLengthScale weight: aWeight
  25. | myDX myDY |
  26. processing strokeWeight: aWeight.
  27. myDX := centerX
  28. + ((Math sin: (aPosition * 2 * Math PI))
  29. * aLengthScale * maxArmLength).
  30. myDY := centerY
  31. - ((Math cos: (aPosition * 2 * Math PI))
  32. * aLengthScale * maxArmLength).
  33. processing line: centerX y: centerY dX: myDX dy: myDY.
  34. !
  35. firstProcessingInstance
  36. <return Processing.instances[0]>
  37. !
  38. initialize
  39. processing := self firstProcessingInstance.
  40. centerX := processing width / 2.
  41. centerY := processing height / 2.
  42. maxArmLength := Math min: centerX or: centerY.
  43. !
  44. processing
  45. ^processing
  46. ! !
  47. !ProcessingClock class methodsFor: 'not yet classified'!
  48. init
  49. | clock processing block |
  50. clock := ProcessingClock new .
  51. processing := clock processing.
  52. block := clock draw.
  53. processing at: 'draw' put: block
  54. ! !