Close

Drawing Spirals

A project log for Gcode Playground

Writing my own Gcode generator for pen plotter

mike-szczysMike Szczys 05/01/2020 at 22:520 Comments

I'm working on some code to generate spiral patterns. So far I'm using Turtle in Python to simulate the pen plotter (you may remember this from the Apple ][)

from turtle import *

stylus = Turtle()
#stylus.setpos(100,100)        
        
def drawSpiral(turtleObj,limit, steps):

    #0=right, 1=down, 2=left, 3=up
    
    increment = 0
    counter = 1

    while turtleObj.position()[0] < limit and turtleObj.position()[1] < limit:
        #if odd
        if counter%2 != 0:
            
            #increase by 10
            if increment < 0:
                increment -= steps
            else:
                increment += steps
            #change X
            turtleObj.setpos(turtleObj.position()[0]+increment,turtleObj.position()[1])
        #if even
        else:
            #flip polarity
            increment = increment * -1
            #change Y
            turtleObj.setpos(turtleObj.position()[0],turtleObj.position()[1]+increment)
        counter += 1

 Which when run using drawSpiral(stylus,191,10) gives us the nice demo below. This isn't spitting out g-code, but it shouldn't be hard to add that in when ready.

Discussions