Пример #1
0
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

## First few layers "bulding up" the oscillations
for l in range(20):
    prop = l / 20
    total_prop = l / LAYERS
    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)
    t.left(math.pi / 2)
    radius_delta = RADIUS * math.sin(1.5 * math.pi *
                                     (total_prop + 1 / 3)) / (LAYERS / 2)
    t.forward(radius_delta)
    radius += radius_delta
    dx = radius * dtheta
    t.right(math.pi / 2)

## The rest of the layers, with full oscillations
for l in range(LAYERS - 20):
    total_prop = (l + 20) / LAYERS
    for k in range(N):
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
        t.extrude(0.5)
        t.lift(2)
        t.extrude(-0.1)
        t.forward_lift(1, 4 - horiz_prop * 0.3)
        t.lift(-6)
    t.right(6 * math.pi / 7)