Week 10 — Bouncing Colors

JIANWEI LI
Data Mining the City
1 min readNov 10, 2017
def setup():
size (500,400)
global x,y,xSpeed,ySpeed
x = 100
y = 90
# psydo code?
xSpeed = 1 # 1pixel per second
ySpeed = 1

def draw():
fill(x,255-y,255-(x+y)/2)
noStroke()

global x,y,xSpeed,ySpeed

x = x +xSpeed
y = y +ySpeed

if x == width:
xSpeed = (-1+1/x)
if y == height:
ySpeed = (-1+1/y)
if x == 0:
xSpeed = 1
if y ==0:
ySpeed = 1
ellipse(x,y,y/2,x/2)

--

--