
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
svg-turtle
Advanced tools
a turtle graphics library with SVG output
svg-turtle is a small JavaScript library (written in TypeScript) to create turtle graphics with SVG output. While it may well be used to create "ordinary" graphics, it is primarily intended to create projects for cutting plotters.
(this project is currently under active development, please stay tuned - it is planned to be finished by end of July)
NPM users: please consider the Github README for the latest description of this package (as updating the docs would otherwise always require a new NPM package version)
Just a small note: if you like this module and plan to use it, consider "starring" this repository (you will find the "Star" button on the top right of this page), so that I know which of my repositories to take most care of.
svg-turtle may be used as an ECMAScript module (ESM), a CommonJS or AMD module or from a global variable.
You may either install the package into your build environment using NPM with the command
npm install svg-turtle
or load the plain script file directly
<script src="https://unpkg.com/svg-turtle"></script>
How to access the package depends on the type of module you prefer
import { Graphic } from 'svg-turtle'const SVGTurtle = require('svg-turtle')require(['svg-turtle'], (SVGTurtle) => {...})Alternatively, you may access the global variable SVGTurtle directly.
For Svelte it is recommended to import the package within a module context:
<script context="module">
import Graphic from 'svg-turtle'
</script>
<script>
let SVG = new Graphic().moveTo(10,10).draw(10).curveRight(90,10).draw(10).asSVG()
</script>
If you prefer ESMs, just import the library and use it:
<script>
import { Graphic } from 'svg-turtle'
window.onload = function () {
let SVG = new Graphic().moveTo(10,10).draw(10).curveRight(90,10).draw(10).asSVG()
...
}
</script>
Let's assume that you already "required" or "imported" (or simply loaded) the module according to your local environment. In that case, you may use it as follows:
<script>
const { Graphic } = SVGTurtle
window.onload = function () {
let SVG = new Graphic().moveTo(10,10).draw(10).curveRight(90,10).draw(10).asSVG()
...
}
</script>
A simple example is available on the Svelte REPL - feel free to play with it!
More examples can be found below.
As shown in the code examples above, every graphic is represented by an instance of class Graphic - each of which may contain multiple "paths".
A typical workflow looks as follows:
Graphic,type TUR_Location = numbertype TUR_Dimension = numbertype TUR_Angle = numbertype TUR_Color = stringtype TUR_Lineature = 'solid'|'dotted'|'dashed'type TUR_Join = 'bevel'|'miter'|'round'type TUR_Cap = 'butt'|'round'|'square'type TUR_PathOptionSet = {x?:TUR_Location, y?:TUR_Location, Direction?:TUR_Angle,Width?:TUR_Dimension, Color?:TUR_Color,Lineature?:TUR_Lineature, Join?:TUR_Join, Cap?:TUR_Cap}type TUR_Position = { x:TUR_Location, y:TUR_Location }type TUR_Alignment = { x:TUR_Location, y:TUR_Location, Direction:TUR_Angle }Class Graphic has a single parameterless constructor. After instantiation (or, later, after a reset), its settings contain the following defaults:
x,y: 0,0 (at coordinate origin)Direction: 0 (in direction of the x-axis)Width: 1Color: #000000Lineature: solidJoin: roundCap: roundMany methods return the instance they were applied to in the end - this may be used to immediately concatenate multiple method invocations (sometimes called a fluent API)
reset ():GraphicbeginPath (PathOptionSet?:TUR_PathOptionSet):GraphicPathOptionSetturn (Anglee:TUR_Angle):GraphicAngle (specified in degrees). Positive angles rotate clockwise, negative ones counterclockwise. This method may be invoked outside an active pathturnTo (Angle:TUR_Angle):GraphicAngle (specified in degrees). Positive angles describe a clockwise, negative ones a counterclockwise rotation. This method may be invoked outside an active pathturnLeft (Angle:TUR_Angle):GraphicAngle (specified in degrees), equivalent to turn(-Angle). This method may be invoked outside an active pathturnRight (Angle:TUR_Angle):Graphicturn(Angle). It may be invoked outside an active pathmove (Distance:TUR_Location):GraphicDistance units without drawing. Positive values for Distance move forward, negative ones move backward. This method may be invoked outside an active pathmoveTo (x:TUR_Location, y:TUR_Location):Graphicdraw (Distance:TUR_Location):GraphicDistance units drawing a straight line. Positive distances move forward, negative ones backward. If invoked outside an active path, a new path with the current turtle position, orientation and line style is starteddrawTo (x:TUR_Location, y:TUR_Location):GraphiccurveLeft (Angle:TUR_Angle, rx:TUR_Dimension, ry?:TUR_Dimension):GraphicAngle with radius rx (in the current turtle direction) and ry (perpendicular to the current turtle direction). If ry is omitted, it defaults to rx. Positive angles move the turtle forward, negative angles backward. Finally, the turtle is positioned at the end of the arc and oriented tangentially to the arc. If invoked outside an active path, a new path with the current turtle position, orientation and line style is startedcurveRight (Angle:TUR_Angle, rx:TUR_Dimension, ry?:TUR_Dimension):GraphicAngle with radius rx (in the current turtle direction) and ry (perpendicular to the current turtle direction). If ry is omitted, it defaults to rx. Positive angles move the turtle forward, negative angles backward. Finally, the turtle is positioned at the end of the arc and oriented tangentially to the arc. If invoked outside an active path, a new path with the current turtle position, orientation and line style is startedendPath ():GraphicclosePath ():GraphiccurrentPosition ():TUR_PositionpositionAt (Position:TUR_Position):GraphicmoveTo insofar as you have to specify a TUR_Position rather than two separate coordinatescurrentAlignment ():TUR_AlignmentalignAt (Alignment:TUR_Alignment):GraphicLimits ():{ xMin:number, yMin:number, xMax:number, yMax:number}Graphic instance containspublic asSVG (Unit?:'px'|'mm'|'cm'|'in',xMin?:number,yMin?:number, xMax?:number,yMax?:number):stringGraphic instance and all its paths, using the given xMin, xMax, yMin and yMax values as viewport limits - any missing limit is estimated from the paths the Graphic instance contains. If the target system (e.g., a web browser) supports it, the resulting SVG will rendered using the given Unit (which defaults to px)public asSVGwith72dpi (Unit?:'px'|'mm'|'cm'|'in',xMin?:number,yMin?:number, xMax?:number,yMax?:number):stringGraphic instance and all its paths, using the given xMin, xMax, yMin and yMax values as viewport limits - any missing limit is estimated from the paths the Graphic instance contains. In contrast to asSVG, this method scales the output such that all coordinates and dimensions are multiples of 1/72 inch (depending on the given unit which defaults to mm)The "Cricut Design Space" does not respect any units given in an SVG's width and height attributes but expects the numeric coordinates to be multiples of 1/72 of an inch. It is therefore recommended to export any turtle graphics using the asSVGwith72dpi method which scales the output as required by the application (based on the provided unit).
Typically, within "Cricut Design Space", you will first
Now, you should
If need be, you may also
Before plotting, you should not forget to
Your project is now ready to be sent to your plotter.
All of them can be found on the Svelte REPL - ready to play with!
![]() | ![]() | ![]() |
| Hexagon | Star | Koch Curve |
You may easily build this package yourself.
Just install NPM according to the instructions for your platform and follow these steps:
npm install in order to install the complete build environmentnpm run build to create a new buildYou may also look into the author's build-configuration-study for a general description of his build environment.
FAQs
a turtle graphics library with SVG output
We found that svg-turtle demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.