This is an early attempt at generative art. I’m using both python and Processing (Python mode). For this example, I wanted to build code which would generate a grid based on several parameters. Here’s one of the more colorful attempts.
And here’s the code:
def setup():
size(800,900)
colorMode(HSB,360,100,100)
background(0,0,90) #white
#noFill()
def draw():
xcenter = width / 2
ycenter = height / 2
border = 40 #num pixels for border all sides
gutter = 8
numcols = 10
numrows = (float(height) / float(width)) * numcols
#numrows = 8
shapeWidth = ((width - 2*border) / numcols) - gutter
shapeArray = []
stroke(0,0,0)
#stroke(255,100,100)
strokeWeight(2)
for rows in range(int(numrows)):
for cols in range(numcols):
#add colorful shapes
fill(map(cols, 0, numcols, 0, 255),map(rows, 0, int(numrows), 100,80),map(rows, 0, int(numrows), 100,80))
s=createShape()
s.beginShape()
#basic square
halfw = shapeWidth / 2
s.vertex(0-halfw,0-halfw)
s.vertex(shapeWidth-halfw, 0-halfw)
s.vertex(shapeWidth-halfw, shapeWidth-halfw)
s.vertex(0-halfw, shapeWidth-halfw)
s.endShape(CLOSE)
s.rotate(radians((rows*cols)+rows))
#s.rotate((random(0,TWO_PI)))
if cols == 0:
xgap = 0
else:
xgap = gutter
if rows == 0:
ygap = 0
else:
ygap = gutter
#shape(s,cols*(shapeWidth+xgap)+border+halfw,rows*(shapeWidth+ygap)+border+halfw+((cols+1)**(rows/2.75)))
shape(s,cols*(shapeWidth+xgap)+border+halfw,rows*(shapeWidth+ygap)+border+halfw)
shapeArray.append(s)
noLoop()