Interactive Grid

Jiacheng Zhou
1 min readSep 19, 2018
def setup():
size(800,800)
noStroke()
background(0)

global grid, max_dist, d, distcolor, w
grid=[[2]*8 for n in range(8)]
print (grid)
max_dist = dist(0, 0, width, height)
w=40
def draw():
# for i in range(0, width):
# i+=20
# for j in range(0, height):
# j+=20
# distcolor=dist(mouseX, mouseY, i, j)
# d=distcolor/max_dist * 35
# strokeWeight(1)
# stroke(200)
# if (distcolor>max_dist):
# fill(255)
# else:
# fill(distcolor*255/2000)

# ellipse(i, j, d, d)
x=0
y=0
stroke(0)
sp = 10
for row in range(width/w):
for col in range(height/w):
if int(mouseX/w)%2==0 and mouseX>=(x+col*w) and mouseX<=(x+(col+1)*w) and int(mouseY/w)%2==0 and mouseY>=(y+row*w) and mouseY<=(y+(row+1)*w):
fill(255,0,0)
else:
fill(250)
rect(x+col * (w), y+row * (w), w, w)
x=x+w
y=y+w
x=0

The white square will turn red if you put the mouse onto it.

--

--