Skip to content

Instantly share code, notes, and snippets.

@oolong32
Last active November 22, 2016 21:55
Show Gist options
  • Save oolong32/37fe994105f82264060f8e281a4ed82d to your computer and use it in GitHub Desktop.
Save oolong32/37fe994105f82264060f8e281a4ed82d to your computer and use it in GitHub Desktop.
Rasterize Page for Drawbot, Fill Raster with Instances of Object
import time
from random import randrange
# create new page
newPage('A3Landscape')
# set margins for RISO
margin_x = 23
margin_y = 37
# set number of fields
NUM_X = 12
NUM_Y = 8
class THING(object):
def __init__(self, x, y, w, h, r):
self.x = x
self.y = y
self.w = w
self.h = h
self.rad = r
def drawthings(self):
oval(self.x + (self.w-self.rad)/2, self.y + (self.h-self.rad)/2, self.rad, self.rad)
def singleField(w, h, num_x, num_y):
offset_x = w % num_x / 2
offset_y = h % num_y / 2
w_col = int((w - offset_x * 2) / num_x)
h_hor = int((h - offset_y * 2) / num_y)
return { "width": w_col, "height": h_hor, "offset_x": offset_x, "offset_y": offset_y }
# get properties of single field as object
props = singleField(width() - 2 * margin_x, height() - 2 * margin_y, NUM_X, NUM_Y)
raster = []
# generate lists containing indexes of raster fields
for row in range(NUM_Y):
raster.append([])
for col in range(NUM_X):
raster[row].append([row, col])
print raster
things = []
for r in range(0, len(raster)):
for f in range(0, len(raster[r])):
# set up values used as arguments for the objects
x = f * props["width"] + props["offset_x"] + margin_x
y = r * props["height"] + props["offset_y"] + margin_y
w = props["width"]
h = props["height"]
# differing radii
#rad = randrange(int(min(w, h) * .5), int(min(w, h) * .8))
# equal radii
rad = int(min(w, h)*0.7)
things.append(THING(x, y, w, h, rad))
for c in things:
stroke(0)
fill(None)
c.drawthings()
timestr = time.strftime("%Y%m%d-%H%M%S")
saveImage(["~/Desktop/things_" + timestr + ".pdf"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment