Variable urban grid in color and scale
Published in
1 min readSep 19, 2018
rules:
- set the grid of 5*5 squares
- use sine function to let the scale of squares variable
- I divided the grids into 4 sectors. According to the position of mouse, the grid will have different color gradient when mouse is in different sectors.
def setup():
size(800,800)
background(250,250,100)
global road, blocksPerNeighborhood, blocksPerRow,blocksPerCol,blockLength,ANG
ANG=0
blocksPerNeighborhood = 25
blocksPerRow = int(sqrt(blocksPerNeighborhood))
blocksPerCol = int(sqrt(blocksPerNeighborhood))
blockLength = int((width/blocksPerRow))
rectMode(CENTER)
frameRate(10)
def draw():
global ANG
background(255)
#make blocks
for r in range(blocksPerRow):
for c in range(blocksPerCol):
with pushMatrix():
translate(0.5*blockLength+r*blockLength,
0.5*blockLength+c*blockLength)
if (width-blockLength)*0.5<mouseX and (height-blockLength)*0.5<mouseY:
fill((ANG*(r)*(c))%255,(ANG*(r)*(c))%255,(ANG*(r)*(c))%255,128)
rect(0,0,100*sin(ANG/5),
100*sin(ANG/5))
elif (width-blockLength)*0.5<mouseX and (height-blockLength)*0.5>mouseY:
fill((ANG*(r)*(c))%255,(ANG*(r)*(c))%255,128,(ANG*(r)*(c))%255)
rect(0,0,100*sin(ANG/5),
100*sin(ANG/5))
elif (width-blockLength)*0.5>mouseX and (height-blockLength)*0.5<mouseY:
fill((ANG*(r)*(c))%255,128,(ANG*(r)*(c))%255,(ANG*(r)*(c))%255)
rect(0,0,100*sin(ANG/5),
100*sin(ANG/5))
else:
fill(128,(ANG*(r)*(c))%255,(ANG*(r)*(c))%255,(ANG*(r)*(c))%255)
rect(0,0,100*sin(ANG/5),
100*sin(ANG/5))
ANG +=0.02