def sine_wave(t): global theta, sine_trail, sine_plot_xratio, max_sine_points, dev dev.fill_white() drawfrm.draw_frame(dev,frm) drawfrm.draw_axis(dev, data) drawfrm.draw_grid(dev, data, 1) thk=0.001*dev.frm.hgt() x1 = r1*np.cos(theta) y1 = r1*np.sin(theta) dev.circle(0, 0, r1, lcol=color.BLACK, lthk=thk) rr2=6 rr3=5 dev.circle(x1, y1, r2, fcol=color.BLACK) x2 = sint_trail_xpos y2 = y1 sine_trail = [y2]+sine_trail[:max_sine_points] for i,p in enumerate(sine_trail): x3 = sint_trail_xpos+i*sine_plot_xratio deg = int(i/max_sine_points*350.0) #sym.set_color_all(color.hsv(deg,1,1)) #dev.symbol(x3,p,sym,True) dev.circle(x3,p,r2,fcol=color.hsv(deg,1,1)) dev.circle(x2, y2, r2, fcol=color.BLACK) dev.line(x1, y1,x2, y2, color.BLUE, lthk=thk) theta += dtheta
def fixed_tree(dev, order, length, angle): global posx, posy, ctbl, dlength, prv_posx, prv_posy, dev_ani, movie dx = length * sin(angle) dy = length * cos(angle) scale = random.random() prv_posx = posx prv_posy = posy posx -= dx posy += dy dev.line(prv_posx, prv_posy, posx, posy, ctbl[int(length - 1)], length * dlength * 0.04 * dev.frm.hgt()) if length <= 10: col = color.hsv(0, scale, 1) fruit = symbol.Circle(scale * 0.01, dev.frm.hgt(), 0.001) fruit.set_color(col, col) dev.begin_symbol(fruit) dev.symbol(posx, posy, fruit) dev.end_symbol() if movie: #print("append img") #clips.append(ImageClip(dev_ani.get_image()).set_duration(1)) clips.append(ImageClip(dev_ani.get_image()).set_duration(0.1)) if order > 0: fixed_tree(dev, order - 1, length * 0.8, angle + 0.5) fixed_tree(dev, order - 1, length * 0.8, angle - 0.5) posx += dx posy -= dy
def square_wave(t): global dev, theta, sine_track_list, final_wave, duration thk=0.003*dev.frm.hgt() thk1=thk*4 dev.fill_white() draw_grid(dev) x0 = 0 y0 = 0 yy = 0 tx = 0 ty = 0 if t > 0: if t in duration: nn.append(nn[-1]+2) sine_track_list.append([0]) for i, n in enumerate(nn): amp = coef/n x1 = amp*np.cos(theta*n) y1 = amp*np.sin(theta*n) dev.line(tx,ty,tx+x1,ty+y1,color_list[i%len(color_list)], thk1*(1-i*0.1)) #dev.line(tx,ty,tx+x1,ty+y1,(20,20,20), thk2) #if i > 0: # dev.circle(tx,ty, amp, lcol=color_list[i%len(color_list)], lthk=thk1) sine_track_list[i] = [y1]+sine_track_list[i][:max_sine_points] yy += y1 tx += x1 ty += y1 final_wave = [yy]+final_wave[:max_sine_points] dev.line(tx, ty, sint_trail_xpos, yy, lcol=color.BLACK, lthk=thk) # plot points for i, pnts in enumerate(sine_track_list): for j, p in enumerate(pnts): x3 = sint_trail_xpos+j*sine_plot_xratio #dev.circle(x3,p,r4,fcol=color.BLACK) dev.circle(x3,p,r4,fcol=color_list[i%len(color_list)]) for i,p in enumerate(final_wave): x3 = sint_trail_xpos+i*sine_plot_xratio deg = int(i/max_sine_points*350.0) dev.circle(x3,p,r3,fcol=color.hsv(deg,1,1)) tt.polyline = dev.lpolyline tt.polygon = dev.lpolygon tt.str = 'n = %d'%len(nn) text.write_text(dev, tt) theta += dtheta
def create_polygon_list(): side = 1.7 jump = 2.2 * side sx = -5.6 sy = 5.6 j = 0 i = 1 y = sy nstart = 3 nend = 19 step = 170 / (nend - nstart) for n in range(nstart, nend, 1): x = sx + j * jump plist.append( geom.Polygon(x, y, n, side, color.BLACK, 0.001, color.hsv((n - 3) * step, 1, 1), True)) j += 1 if j % 4 == 0: y = sy - i * jump j = 0 i += 1
def julia(dev): global wid, hgt zoom = 1 moveX = 0 moveY = 0 maxIterations = 300 # pick some values for the constant c, # this determines the shape of the Julia Set cRe = -0.7 cIm = 0.27015 #loop through every pixel for x in range(wid): for y in range(hgt): # calculate the initial real and imaginary part of z, # based on the pixel location and zoom # and position values newRe = 1.5 * (x - wid / 2) / (0.5 * zoom * wid) + moveX newIm = (y - hgt / 2) / (0.5 * zoom * hgt) + moveY # start the iteration process for i in range(maxIterations): # remember value of previous iteration oldRe = newRe oldIm = newIm # the actual iteration, the real and imaginary part are calculated newRe = oldRe * oldRe - oldIm * oldIm + cRe newIm = 2 * oldRe * oldIm + cIm # if the point is outside the circle with radius 2: stop if (newRe * newRe + newIm * newIm) > 4: break # use color model conversion to get rainbow palette, # make brightness black if maxIterations reached col = color.hsv(i % 256, 1, 1 if i < maxIterations else 0) dev.set_pixel(x, y, col)