Skip to content

Instantly share code, notes, and snippets.

@akirayou
Last active February 4, 2020 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akirayou/71d7e06c66567499285686f75306fd3d to your computer and use it in GitHub Desktop.
Save akirayou/71d7e06c66567499285686f75306fd3d to your computer and use it in GitHub Desktop.
draw loop
# -*- coding: utf-8 -*-
import math
import cmath
outfile=open("out.gcode","w")
feedrate=0.03 #depends on youre printer
temperature=250
speed=3000
espeed=speed*feedrate
#start point
nowe=0
step=0.6
base=10
r=10
direc=1+0j
now=100+100j -(base/2-r/2)-(base/2+r/2)*1j
maxLen=190-r
header="""
M107
M104 S"""+str(temperature)+""" ; set temperature
G21; set mm units
G90; set absolute coordinates
G92 E0; reset extruder distance
G28 X0 Y0;home x and y axis
G28 Z0; home Z axis
G92 E0; reset extrusion distance
M109 S"""+str(temperature)+""" ; wait for temperature to be reached
G21 ; set units to millimeters
G90 ; use absolute coordinates
M82 ; use absolute distances for extrusion
G1 X"""+str(now.real)+""" Y"""+str(now.imag)+""" F12000.000
G1 E0.00000 F"""+str(espeed)+"""
G1 F"""+str(speed)+"""
G2 F"""+str(speed)+"""
G3 F"""+str(speed)+"""
"""
def g1(to,ext=True):
global now,nowe
l=abs(now-to)
if(ext):
nowe+=feedrate*l
print("###### LEN ",l)
print("G1","X"+str(to.real),"Y"+str(to.imag),"E"+str(nowe),file=outfile )
else:
print("G1","X"+str(to.real),"Y"+str(to.imag) ,file=outfile)
now=to
def gr(to,center,iscw=False,ext=True):
global now,nowe,outfile
code="G2" if iscw else "G3"
arg=cmath.phase( (to-now)-center)-cmath.phase(-center)
if(not iscw):arg*=-1
#if(arg<0):arg += math.pi*2
l=abs(arg)*abs(center)
if(ext):
nowe+=feedrate*l
print("############## trun ",arg*180/math.pi,"degree","len",l)
print(code,"X"+str(to.real),"Y"+str(to.imag),"I"+str(center.real),"J"+str(center.imag),"E"+str(nowe),file=outfile )
else:
print(code,"X"+str(to.real),"Y"+str(to.imag),"I"+str(center.real),"J"+str(center.imag),file=outfile)
now=to
print(header,file=outfile)
d=base
print("G1 E0.1",file=outfile)
nowe=0.1
while(d<maxLen):
to=now+(d-r)*direc
g1(to)
to+=r*direc
direc*=0+1j #rotation
to+=r*direc
gr(to,r*direc)
d+=step
print("G1 Z10",file=outfile)
outfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment