We Recommend

Learning Python Learning Python
The authors of Learning Python show you enough essentials of the Python scripting language to enable you to begin solving problems right away, then reveal more powerful aspects of the language one at a time. This approach is sure to appeal to programmers and system administrators who have urgent problems and a preference for learning by semi-guided experimentation.


Posted By

n3x on 07/29/07


Tagged

nodebox


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

vvarp


motion blur arrows


Published in: Python 


URL: http://vimeo.com/218013

This NodeBox script is a quick hack; ugly code, no documentation, but I was asked about it, so here it is. Apparently each dot in the dots list is a list that contains, in this order, x coordinate, y coordinate, orientation, and scale of an arrow. From this you should be able to figure out the rest, the code isn't that long after all.

  1. import math
  2.  
  3. width, height = 600, 480
  4. #width, height = 300, 240
  5.  
  6. size(width, height)
  7. speed(30)
  8.  
  9. def rotatePoint(x, y, centreX, centreY, degrees):
  10. angle = (degrees / 180.0) * math.pi
  11. x -= centreX
  12. y -= centreY
  13. x, y = math.cos(angle)*x - math.sin(angle)*y, math.sin(angle)*x + math.cos(angle)*y
  14. x += centreX
  15. y += centreY
  16. return (x, y)
  17.  
  18. def setup():
  19. global frame
  20. frame = 0
  21. global dots
  22. # (y - x)*10.0
  23. dots = [[30*x, 30*y, (x + y)*20.001, 1.0] for x in xrange(-20, 20) for y in xrange(-14, 14)]
  24. #dots = [[30*x, 30*y, (x + y)*20.001, 1.0] for x in xrange(-10, 10, 1) for y in xrange(-8, 8, 1)]
  25. #dots = [[30*x, 30*y, (x + y)*20.001, 1.0] for x in xrange(-20, 20, 6) for y in xrange(-14, 14, 6)]
  26.  
  27. def stepDots():
  28. global dots
  29. for d in dots:
  30. d[2] += (math.sqrt(math.pow(d[0]*0.3, 2) + math.pow(d[1]*0.2, 2)))*0.08
  31. d[3] = math.sin(math.radians(d[2])/5.0)
  32. xInc, yInc = rotatePoint(1.76, 0.0, 0.0, 0.0, -1.0*(d[2] % 360))
  33. sc = math.pow(1.0 - d[3], 2.8)
  34. if d[3] < 0:
  35. sc *= -1.0
  36. d[0] += xInc*sc
  37. d[1] += yInc*sc
  38.  
  39. def drawObject(x, y, o):
  40. for z in xrange(-12, 13, 5):
  41. xOff, yOff = rotatePoint(z, 0.0, 0.0, 0.0, -1.0*o)
  42. arrow(x + xOff, y + yOff, 30)
  43.  
  44. def draw():
  45. global frame
  46. global distort
  47. global dots
  48.  
  49. stepDots()
  50. nofill()
  51. strokewidth(5) # 5
  52. colormode(HSB)
  53. translate(300, 240)
  54. #translate(150, 120)
  55. #rotate(-1.3 * frame)
  56. for d in dots:
  57. push()
  58. o = d[2] % 360
  59. rotate(o)
  60. stroke(math.sin(d[3]*20.0)*0.1 + (math.sin(frame/48.0)*0.4 + 0.5), 0.7, 0.5, 0.125 - abs(d[3]*0.25))
  61. scale(d[3]*10.15)
  62. #rect(d[0], d[1], 10, 10)
  63. drawObject(d[0], d[1], o)
  64. pop()
  65.  
  66. frame += 1

Report this snippet 

You need to login to post a comment.