Processing-Examples.st 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. Smalltalk current createPackage: 'Processing-Examples' properties: #{}!
  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. initialize
  36. processing := <Processing.instances[0]>.
  37. centerX := processing width / 2.
  38. centerY := processing height / 2.
  39. maxArmLength := Math min: centerX or: centerY.
  40. !
  41. processing
  42. ^processing
  43. ! !
  44. !ProcessingClock class methodsFor: 'not yet classified'!
  45. init
  46. | clock processing block |
  47. clock := ProcessingClock new .
  48. processing := clock processing.
  49. block := clock draw.
  50. <processing.draw=block>
  51. ! !