# This program draws n boxes spaced evenly (distance 1) along a line, rotated by # an angle of 'spindiff' radians relative to each other. (Dimension given by 'edge'). # Moving back and forth along the line is the "redbox", whose color is red. # Each box has its color adjusted towards green (how fast is given by 'reddecay') # This gives an effect of a red trail behind the redbox. The boxes are also rotated. from visual import * # Parameters governing motion, size, and colors. spindiff = 0.08 reddecay = 0.05 nboxes = 180 edge = 1. boxlist=[] for boxnum in range(nboxes): theta = boxnum * spindiff ## the angle of the box x = boxnum - nboxes/2. + 0.5 ## x-position of box center abox = box(height=edge*5, width=edge, length=edge, x=x, color=color.green, axis=(0,cos(theta),sin(theta))) abox.number = boxnum ## can add attributes to box boxlist = boxlist + [abox] ## add the temporary abox to list redbox = 0 ## start redbox at far left redmove = 1 ## start it moving to the right t = 0 ## repeat the dynamics forever while 1: # rate(40) t = t + 1 boxlist[redbox].color = color.red redbox = redbox + redmove if (redbox == nboxes - 1): redmove = -1 ## all the way to the right? move back left if (redbox == 0): redmove = 1 ## if all the way to the left, move right for abox in boxlist: abox.axis = (0,cos((abox.number+t)*spindiff),sin((abox.number+t)*spindiff)) ## The following line mixes current color and the green color to update the color ## Eventually, this turns a red box to a green box. abox.color = (1.-reddecay) * vector(abox.color) + reddecay * vector(color.green)