from extruder_turtle import ExtruderTurtle import math t = ExtruderTurtle() ## Set up the turtle t.name("seven-star.gcode") t.setup(x=100, y=100) t.rate(700) for l in range(30): ## Draw a seven-pointed star for k in range(7): t.forward(50) t.right(6 * math.pi / 7) ## Move to the next layer t.lift(0.3) ## Save to a GCODE file t.finish()
import random HAIRLENGTH = 1 HAIR_ANGLE = math.pi / 2 EXT_DENSITY = 0.01 # 0.02 FEEDRATE = 700 NUM_HAIRS = 200 LAYER_HEIGHT = 0.3 DIAMETER = 80 NUM_SIDES = 5 LAYERS = 200 dtheta = 2 * math.pi / NUM_HAIRS dx = DIAMETER * math.sin(dtheta / 2) t = ExtruderTurtle() ## Set up the turtle t.name("flex-circle.gcode") t.setup(x=100, y=100) t.rate(FEEDRATE) t.set_density(EXT_DENSITY) for l in range(LAYERS): for k in range(NUM_HAIRS): t.right(dtheta) t.forward(dx) t.left(HAIR_ANGLE) t.forward(HAIRLENGTH) t.dwell(50) t.forward(-2 * HAIRLENGTH)
from extruder_turtle import ExtruderTurtle import math t = ExtruderTurtle() t.name("complex-walk.gcode") t.setup(x=100, y=100) t.rate(700) N = 75 period = 224 angle = 2 * math.pi / N for l in range(30): for k in range(period + 1): t.forward(2) t.right(angle * k * (k - 1) / 2) t.lift(0.3) t.finish()
from extruder_turtle import ExtruderTurtle import math N = 60 RADIUS = 12 dtheta = 2 * math.pi / N dx = RADIUS * dtheta dr = -5 / N MAX_HEIGHT = 10 t = ExtruderTurtle() t.name("spiral-tower.gcode") t.setup(x=100, y=100) t.set_density(0.05) t.rate(1000) for l in range(40): radius = RADIUS prop = l / 40 while radius > 0: t.move_lift(dx, prop * MAX_HEIGHT * (-dr) / RADIUS) t.right(dtheta) radius += dr dx = radius * dtheta t.lift(0.2) while radius < RADIUS: radius += -dr dx = radius * dtheta t.left(dtheta) t.move_lift(-dx, prop * MAX_HEIGHT * dr / RADIUS)
from extruder_turtle import ExtruderTurtle import math t = ExtruderTurtle() t.name("euler-spiral.gcode") t.setup(x=100, y=100) t.rate(700) t.set_density(0.5) length = 0 dl = 5 for i in range(200): length += dl t.move(dl) t.right(2 * math.pi * length * dl / 10) dl = 5 / length t.finish()
from extruder_turtle import ExtruderTurtle import math import random N = 79 ## For best results, this should be a modulus for which ## 2 is a primitive root modulo N DIAMETER = 50 dtheta = 2*math.pi/N dx = DIAMETER*math.sin(dtheta/2) n = 1 t = ExtruderTurtle() ## Set up the turtle t.name("not-a-cardioid.gcode") t.setup(x=100, y=100) t.rate(700) for l in range(50): ## Draw a circle t.set_density(0.07) t.left(dtheta/2) for k in range(N): t.right(dtheta) t.move(dx) t.right(dtheta/2) ## Draw several chords for i in range(10): t.dwell(100) t.set_density(0.03)
from extruder_turtle import ExtruderTurtle import math instr = "frrfrrfrr" sub_rules = { "f": "flfrrflf", "r": "r", "l": "l" } NUM_GENS = 4 sidelength = 50 t = ExtruderTurtle() t.name("evolving_snowflake.gcode") t.setup(x=100, y=100) t.rate(700) for g in range(NUM_GENS): for l in range(40): progress = l/40 gap_length = progress*sidelength/3 long_length = (sidelength - gap_length)/2 for r in instr: if r == "f": t.forward(long_length) t.left(math.pi/3) t.forward(gap_length) t.right(2*math.pi/3) t.forward(gap_length)
from extruder_turtle import ExtruderTurtle import math t = ExtruderTurtle() ## Set up the turtle t.name("tall-bumpy-star.gcode") t.setup(x=100, y=100) t.rate(1000) t.set_density(0.2) t.lift(2) for l in range(50): ## Draw a seven-pointed star for k in range(7): t.forward(50) t.right(6 * math.pi / 7) ## Move to the next layer t.lift(0.6) # 0.5 gets too squished # 1 gets too bumpy ## Save to a GCODE file t.finish()
from extruder_turtle import ExtruderTurtle import math t = ExtruderTurtle() ## Set up turtle t.name("bumpy-nonplanar-star.gcode") t.setup(x=100, y=100) t.rate(500) for l in range(30): ## Track progress vert_prop = l / 30 ## Draw a seven-pointed star for k in range(7): ## Each line is slightly parabolically curved ## The bottom layer is completely flat, but ## subsequent layers are increasingly curved for x in range(-25, 26): horiz_prop = x / 25 t.forward_lift(1, -vert_prop * horiz_prop * 0.3) t.right(6 * math.pi / 7) ## Move to the next layer t.lift(0.15) t.penup() for k in range(7): for x in range(-25, 26): horiz_prop = x / 25
from extruder_turtle import ExtruderTurtle import math t = ExtruderTurtle() ## Set up the turtle t.name("feedrate-test.gcode") t.setup(x=100, y=100) ## Parameters min_rate = 200 max_rate = 10000 height = 200 for l in range(height): ## Feedrate increases linearly from one layer to the next, ## making the extruder move faster and faster t.rate(min_rate + l * (max_rate - min_rate) / height) ## Draw a square for k in range(4): t.move(30) t.right(math.pi / 2) ## Move to the next layer t.lift(0.3) ## Save to a GCODE file t.finish()
import math import random HAIRLENGTH = 1 HAIR_ANGLE = math.pi/3 EXT_DENSITY = 0.05 FEEDRATE = 500 NUM_HAIRS = 15 LAYER_HEIGHT = 0.15 SIDELENGTH = 25 NUM_SIDES = 5 LAYERS = 100 dx = SIDELENGTH/(NUM_HAIRS+1) t = ExtruderTurtle() ## Set up the turtle t.name("furry-prism.gcode") t.setup(x=100, y=100) t.rate(FEEDRATE) t.set_density(EXT_DENSITY) for l in range(LAYERS): ## Draw a pentagon for k in range(NUM_SIDES): t.move(dx) for n in range(NUM_HAIRS): t.left(HAIR_ANGLE) t.move(HAIRLENGTH) t.move(-HAIRLENGTH)
from extruder_turtle import ExtruderTurtle import math t = ExtruderTurtle() ## Set up the turtle t.name("bumpy-star.gcode") t.setup(x=100, y=100) t.rate(700) t.set_density(0.3) t.lift(1) for l in range(9): # height of 10.5 ## Draw a seven-pointed star for k in range(7): t.forward(50) t.right(6 * math.pi / 7) ## Move to the next layer t.lift( 1.2 ) # 0.7 for first demo, 0.6 for second demo, 0.9 for third demo, 1.2 for fourth demo # 0.5 gets too squished # 1 gets too bumpy ## Save to a GCODE file t.finish()
from extruder_turtle import ExtruderTurtle import math t = ExtruderTurtle() t.name("curly-line.gcode") t.setup(x=100, y=100) t.rate(700) t.set_density(0.2) t.lift(1) t.forward(100) t.left(math.pi / 2) t.penup() t.lift(10) t.forward(20) t.lift(-10) t.left(math.pi / 2) t.lift(1) t.pendown() t.forward(100) t.right(math.pi / 2) t.penup() t.lift(10) t.forward(20) t.lift(-10) t.right(math.pi / 2) t.lift(1) t.pendown() t.forward(100)
from extruder_turtle import ExtruderTurtle import math t = ExtruderTurtle() ## Set up turtle t.name("nonplanar-star.gcode") t.setup(x=100, y=100) t.rate(500) for l in range(30): ## Track progress vert_prop = l / 30 ## Draw a seven-pointed star for k in range(7): ## Each line is slightly parabolically curved ## The bottom layer is completely flat, but ## subsequent layers are increasingly curved for x in range(-25, 26): horiz_prop = x / 25 t.forward_lift(1, -vert_prop * horiz_prop * 0.3) t.right(6 * math.pi / 7) ## Move to the next layer t.lift(0.15) ## Save to a GCODE file t.finish()
from extruder_turtle import ExtruderTurtle import math ## Parameters for the cylinder N = 100 RADIUS = 20 PERIODS = 3 AMPLITUDE = 6 dtheta = 2 * math.pi / N dx = RADIUS * dtheta t = ExtruderTurtle() ## Set up the turtle t.name("nonplanar-column.gcode") t.setup(x=100, y=100) t.set_density(0.05) t.rate(900) ## First layers, "building up" the oscillations for l in range(20): prop = l / 20 for k in range(N): angle = k * dtheta t.forward_lift( dx, PERIODS * AMPLITUDE * prop * math.sin(PERIODS * angle) / N) t.right(dtheta) t.lift(0.25 / N) ## Later layers, with full oscillations
from extruder_turtle import ExtruderTurtle import math t = ExtruderTurtle() t.name("stretchy-line.gcode") t.setup(x=100, y=100) t.rate(900) t.set_density(0.05) for l in range(10): t.forward(20) t.right(math.pi / 2) t.forward(5) t.left(math.pi / 2) t.forward(2) t.left(math.pi / 2) t.forward(10) t.right(math.pi / 2) t.forward(2) t.right(math.pi / 2) t.forward(5) t.left(math.pi / 2) t.forward(20) t.right(math.pi) t.lift(0.3) t.finish()
from extruder_turtle import ExtruderTurtle import math import random N = 100 DIAMETER = 50 dtheta = 2*math.pi/N dx = DIAMETER*math.sin(dtheta/2) t = ExtruderTurtle() ## Set up the turtle t.name("dreamcatcher.gcode") t.setup(x=100, y=100) t.rate(700) for l in range(50): ## Draw a circle t.set_density(0.07) t.left(dtheta/2) for k in range(N): t.right(dtheta) t.forward(dx) t.right(dtheta/2) ## Draw a random chord on the circle t.dwell(100) t.set_density(0.03) rand_angle = dtheta*random.randint(1,N)/2 t.right(rand_angle) t.forward(DIAMETER*math.sin(rand_angle))
from extruder_turtle import ExtruderTurtle import math import random t = ExtruderTurtle() t.name("random-hourglass.gcode") t.setup(x=100, y=100) t.rate(500) t.set_density(0.04) for l in range(240 * 7): t.forward(10 * math.sqrt(12 * (l / (240 * 7) - 1 / 2)**2 + 1)) t.right(2 * math.pi / 7 + math.pi * random.random() / 500) t.lift(0.2 / 7) t.lift(1) t.extrude(0.4) t.lift(-1) t.dwell(200) t.finish()
from extruder_turtle import ExtruderTurtle import math instr = "A" sub_rules = { "A": "+BF-AFA-FB+", "B": "-AF+BFB+FA-", "F": "F", "+": "+", "-": "-" } GENS = 5 sidelength = 50 / 2**GENS t = ExtruderTurtle() t.name("hilbert.gcode") t.setup(x=100, y=100) t.set_density(0.05) t.rate(800) for g in range(GENS): new_instr = "" for r in instr: new_instr += sub_rules[r] instr = new_instr for l in range(10): for r in instr: if r == "F": t.forward(sidelength)
import random BUMPLENGTH = 1 ## 2 BUMP_ANGLE = math.pi / 3 BUMP_DENSITY = 0.16 ## 0.08 EXT_DENSITY = 0.05 # 0.05 FEEDRATE = 900 LAYER_HEIGHT = 0.3 DIAMETER = 40 NUM_SIDES = 50 LAYERS = 100 dtheta = 2 * math.pi / NUM_SIDES dx = DIAMETER * math.sin(dtheta / 2) t = ExtruderTurtle() ## Set up the turtle t.name("braille-ca.gcode") t.setup(x=100, y=100) t.rate(FEEDRATE) t.set_density(EXT_DENSITY) ca = [0] * NUM_SIDES ca[0] = 1 on_states = [1, 2, 3, 4] # Wolfram's "Rule 30" for l in range(LAYERS): for k in range(NUM_SIDES): t.right(dtheta) t.forward(dx)
from extruder_turtle import ExtruderTurtle import math import random t = ExtruderTurtle() t.name("random-cone.gcode") t.setup(x=100, y=100) t.rate(700) t.set_density(0.02) for l in range(80 * 7): t.forward(20 - l * 20 / (80 * 7)) t.right(2 * math.pi / 7 + math.pi * random.random() / 500) t.lift(0.3 / 7) t.lift(1) t.extrude(0.8) t.lift(-1) t.dwell(200) t.finish()
import random HAIRLENGTH = 3 ## 2 HAIR_ANGLE = math.pi / 6 HAIR_DENSITY = 0.16 ## 0.08 EXT_DENSITY = 0.06 # 0.05 FEEDRATE = 900 LAYER_HEIGHT = 0.3 DIAMETER = 40 NUM_SIDES = 50 LAYERS = 50 dtheta = 2 * math.pi / NUM_SIDES dx = DIAMETER * math.sin(dtheta / 2) t = ExtruderTurtle() ## Set up the turtle t.name("braille-directed.gcode") t.setup(x=100, y=100) t.rate(FEEDRATE) t.set_density(EXT_DENSITY) for l in range(LAYERS): for k in range(NUM_SIDES): t.right(dtheta) t.forward(dx) if random.random() < HAIR_DENSITY: t.penup() t.left(HAIR_ANGLE) t.forward(HAIRLENGTH)
from extruder_turtle import ExtruderTurtle import math t = ExtruderTurtle() t.name("stretchy-material.gcode") t.setup(x=100, y=100) t.rate(900) t.set_density(0.05) for l in range(5): for r in range(5): for n in range(4): t.forward(10) t.right(math.pi / 2) t.forward(4) t.left(math.pi / 2) t.forward(2) t.left(math.pi / 2) t.forward(8) t.right(math.pi / 2) t.forward(2) t.right(math.pi / 2) t.forward(4) t.left(math.pi / 2) sgn = (-1)**(r % 2) t.forward(10) t.left(math.pi / 2 * sgn) t.forward(14) t.left(math.pi / 2 * sgn) t.left(math.pi / 2)
from extruder_turtle import ExtruderTurtle import math import random SIDELENGTH = 25 GAPLENGTH = 1 NUM_SIDES = 5 LAYERS = 100 t = ExtruderTurtle() ## Set up the turtle t.name("gappy-prism.gcode") t.setup(x=100, y=100) t.rate(700) for l in range(LAYERS): ## Draw a pentagon for k in range(NUM_SIDES): ## Draw one side, with a randomly chosen gap x = (SIDELENGTH-GAPLENGTH) * random.random() t.move(x) ## Move out of the way in order to break the plastic strand t.penup() t.right(math.pi/2) t.move(SIDELENGTH) t.dwell(50) t.left(math.pi) t.move(SIDELENGTH) t.right(math.pi/2) ## Skip over the gap and continue drawing the side
from extruder_turtle import ExtruderTurtle import math ## Parameters for vase and rim oscillations N = 100 RADIUS = 20 PERIODS = 3 AMPLITUDE = 6 LAYERS = 200 dtheta = 2 * math.pi / N dx = RADIUS * dtheta radius = RADIUS t = ExtruderTurtle() ## Set up the turtle t.name("nonplanar-vase.gcode") t.setup(x=100, y=100) t.set_density(0.05) t.rate(500) ## Draw a spiral base dr = 0.5 / 60 base_rad = 0 base_dx = 0 while base_rad < RADIUS: t.forward(base_dx) t.right(2 * math.pi / 60) base_rad += dr base_dx = base_rad * 2 * math.pi / 60
from extruder_turtle import ExtruderTurtle import math t = ExtruderTurtle() t.name("horizontal-brush.gcode") t.setup(x=200, y=100) t.rate(700) t.set_density(0.05) for l in range(100): t.forward(5) t.right(math.pi / 2) t.forward(20) t.right(math.pi / 2) t.forward(5) t.right(math.pi / 2) if l % 5 == 3: t.forward(0.5) for i in range(19): t.left(math.pi / 2) t.rate(3000) t.set_density(0.02) t.forward(50) t.lift(0.2 - l * 0.2) t.penup() t.forward(10) t.lift(l * 0.2 - 0.2) t.forward(-10) t.lift(10) t.right(math.pi)
from extruder_turtle import ExtruderTurtle import math ## Parameters for the spiral N = 40 ## Number of subdivisions of one round-trip RADIUS = 5 ## Outer radius of the spiral dtheta = 2*math.pi/N ## Change in heading after each step dx = RADIUS * dtheta ## Forward movement during each step dr = -0.5/N ## Change in radius with each step t = ExtruderTurtle() t.name("hair-pillar.gcode") t.setup(x=150, y=150) t.set_density(0.07) # 0.05 t.rate(500) radius = RADIUS while radius>0: t.forward(dx) t.right(dtheta) radius += dr dx = radius * dtheta for l in range(200): t.extrude(0.1) t.dwell(200) t.lift(0.1) # 0.1 t.penup() t.forward(80)
from extruder_turtle import ExtruderTurtle import math ## Parameters for the spiral N = 40 ## Number of subdivisions of one round-trip radius = 20 ## Outer radius of the spiral dtheta = 2 * math.pi / N ## Change in heading after each step dx = radius * dtheta ## Forward movement during each step dr = -0.5 / N ## Change in radius with each step t = ExtruderTurtle() t.name("palm-tree.gcode") t.setup(x=100, y=100) t.set_density(0.06) # 0.05 t.rate(500) while radius > 0: t.forward(dx) t.right(dtheta) radius += dr dx = radius * dtheta for l in range(50): t.extrude(0.1) t.dwell(100) t.lift(0.1) # 0.1, 0.05 for x in range(60): prog = x / 60 frond_length = prog**4 * 20
from extruder_turtle import ExtruderTurtle import math ## Parameters for the spiral N = 40 ## Number of subdivisions of one round-trip radius = 20 ## Outer radius of the spiral dtheta = 2 * math.pi / N ## Change in heading after each step dx = radius * dtheta ## Forward movement during each step dr = -0.5 / N ## Change in radius with each step t = ExtruderTurtle() t.name("alien-tree.gcode") t.setup(x=100, y=100) t.set_density(0.07) # 0.05 t.rate(500) while radius > 0: t.forward(dx) t.right(dtheta) radius += dr dx = radius * dtheta for l in range(50): t.extrude(0.1) t.dwell(100) t.lift(0.05) # 0.1 for x in range(60): for l in range(10): t.extrude(0.1)
from extruder_turtle import ExtruderTurtle import math HAIR_SPACE = 2 HAIR_ROWS = 10 LIFT_DIST = 10 EXTRUDE_AMT = 0.5 t = ExtruderTurtle() t.name("hair-patch.gcode") t.setup(x=100, y=100) t.rate(1000) t.set_density(0.05) ## Draw the base for l in range(3): length = (HAIR_ROWS + 1) * HAIR_SPACE while length > 0: t.left(math.pi / 2) t.forward(length) t.left(math.pi / 2) t.forward(length) length += -0.7 t.lift(0.2) while length < (HAIR_ROWS + 1) * HAIR_SPACE: length += 0.7 t.backward(length) t.right(math.pi / 2) t.backward(length) t.right(math.pi / 2)