Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import random
- from turtle import Turtle
- from colorsys import hsv_to_rgb
- from math import sin, ceil, cos, pi
- rectsPerPen = 100
- rectSize = 100
- equation = lambda x, y, time: (sin(y) + cos(x) + time) % 2 / 2
- scaleX,scaleY=.005,.005
- scaleX/=pi/rectSize
- scaleY/=pi/rectSize
- grayscale=False
- pen=Turtle()
- pen.hideturtle()
- canvas=pen.getscreen()
- canvas.tracer(0, 0)
- oldPenPool, newPenPool = [], []
- width, height = canvas.window_width(),canvas.window_height()
- for pool in [oldPenPool, newPenPool]:
- for i in range(ceil(width * height / rectsPerPen)):
- pen = Turtle()
- pen.hideturtle()
- pen.setundobuffer(0)
- pool.append(pen)
- def rect(pen, x, y, width, height, color):
- pen.penup()
- pen.goto(x + width, y)
- pen.pendown()
- pen.pencolor(color)
- pen.fillcolor(color)
- if width == 1 and height == 1:
- pen.dot()
- return
- elif width == 1:
- pen.sety(y - height)
- return
- elif height == 1:
- pen.setx(x + width)
- return
- pen.begin_fill()
- for i in range(2):
- pen.right(90)
- pen.forward(width)
- pen.right(90)
- pen.forward(height)
- pen.end_fill()
- def toWindowCoords(x, y):
- return x - width / 2, -y + height / 2
- time = 0
- speed = .1
- while True:
- i = -1
- for w in range(0, width, rectSize):
- for h in range(0, height, rectSize):
- i += 1
- x, y = toWindowCoords(w, h)
- shade=equation(w*scaleX, h*scaleY, time)
- rect(newPenPool[int(i / rectsPerPen)], x, y, rectSize, rectSize, hsv_to_rgb(shade, 1, 1) if not grayscale else [shade,shade,shade])
- if i % rectsPerPen == 0:
- oldPenPool[int(i / rectsPerPen) - 1].clear()
- canvas.update()
- time += speed
- tempPenPool = oldPenPool
- oldPenPool = newPenPool
- newPenPool = tempPenPool
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement