radii = [.1, 1] arc_chance = .5 arcangles = range(0, 360, 45) + [1, 359, 360] distances = [1,-.1,0,0,.1,1] distances = distances + [2*d for d in distances] + [5*d for d in distances] radii = radii + [2*d for d in radii] + [5*d for d in radii] from math import * from random import * def path(x, y, n): print "O%d sub (#1=radius)" % n print "F100" print "G0 X%f Y%f" % (x, y) print "O%d if [#1 NE 0]" % (n+1) print "G41.1 D#1" print "O%d endif" % (n+1) for i in range(4): x, y = move(x, y) print "G40" x, y = move(x, y) print "O%d endsub" % n return x, y def move(x,y): if random() < arc_chance: x, y = arc(x, y) else: x, y = line(x, y) return x, y def arc(x, y): direction = randrange(2) print "G%d" % (direction+2), theta = choice(arcangles) theta1 = choice(arcangles) r = choice(radii) ox = -cos(theta)*r oy = -sin(theta)*r print "I%f J%f" % (ox, oy), x = x + ox + cos(theta1)*r y = y + oy + sin(theta1)*r print "X%f Y%f" % (x, y) return x, y def line(x, y): dx = choice(distances) dy = choice(distances) x = x + dx y = y + dy print "G1 X%f Y%f" % (x,y) return x, y j=0 for sx in range(-100, 101, 50): for sy in range(-100, 101, 50): path(sx, sy, j) print "F100" print "G21" print "O%d call [0]" % j #print "O%d call [-1]" % j #print "O%d call [1]" % j j = j + 2 print "m2"