Run the code in RStudio Console, Plots: Export, Save as PDF…, choose File name, Save.
Run InkSpace with a blank new document, drag and drop the PDF, OK, Object - Ungroup (Shift+Ctrl+G), delete 3 unnecessary objects (white background, axes labels, frame with axes values).
File, Document properties (Shift+Ctrl+D), Custom size - Units: px, Display units: px, Scale: 1, Orientation: Landscape.
Move the picture to the right place, zoom it (with proportion locked), select it, Path - Object to Path (Shift+Ctrl+C).
Save as .SVG.
Extensions - Export, TurnKeyLaser Exporter… Choose File name .GCODE, Apply. If the plugin freezes and the .GCODE file is created, it is safe to kill the Inkscape. Otherwise, switch to desktop (Win+D), click on the Inkscape in the taskbar and a window with the OK button should appear, press OK, Close.
source("spiro.R")
drawClearPaper(m = 105)
for (I in c(1, 3, 5, 7)) {
drawSpiro(m = 105, n = 56, h = I, col = "blue")
}
drawClearPaper(m = 105)
drawSpiro(m = 105, n = 80, h = 1, col = "red")
drawSpiro(m = 105, n = 80, h = 6, col = "blue")
drawSpiro(m = 105, n = 80, h = 11, col = "red")
drawSpiro(m = 105, n = 80, h = 16, col = "green")
drawSpiro(m = 105, n = 80, h = 21, col = "green")
drawClearPaper(m = 105)
for (I in 1:16) {
drawSpiro(m = 105, n = 63, h = I+3, phase = I-1)
}
drawClearPaper(m = 105)
for (I in 1:4) {
drawSpiro(m = 105, n = 63, h = I, phase = I-1, col = "red")
}
for (I in 5:8) {
drawSpiro(m = 105, n = 63, h = I, phase = I-1, col = "green")
}
for (I in 9:12) {
drawSpiro(m = 105, n = 63, h = I, phase = I-1, col = "blue")
}
drawClearPaper(m = 96)
for (I in 1:9) {
drawSpiro(m = 96, n = 56, h = I, phase = I-1, col = "blue")
}
drawClearPaper(m = 105)
for (I in c(1, 4, 7)) {
drawSpiro(m = 105, n = 45, h = I, col = "blue")
}
for (I in c(10, 13, 16)) {
drawSpiro(m = 105, n = 45, h = I, col = "green")
}
drawClearPaper(m = 105)
for (I in 1:11) {
drawSpiro(m = 105, n = 84, h = I, phase = 2*(I-1), col = "blue")
}
for (I in 12:22) {
drawSpiro(m = 105, n = 84, h = I, phase = 2*(I-12), col = "green")
}
drawClearPaper(m = 105)
for (I in c(1, 2, 3)) {
drawSpiro(m = 105, n = 30, h = I, col = "blue")
}
for (I in c(6, 7, 8)) {
drawSpiro(m = 105, n = 45, h = I, col = "red")
}
for (I in c(11, 12, 13)) {
drawSpiro(m = 105, n = 60, h = I, col = "green")
}
for (I in c(16, 17, 18)) {
drawSpiro(m = 105, n = 75, h = I, col = "black")
}
drawClearPaper(m = 96)
for (I in 0:3) {
drawSpiro(m = 96, n = 80, h = 1, phase = I, col = "blue")
}
for (I in 0:3) {
drawSpiro(m = 96, n = 80, h = 1, phase = I+4, col = "green")
}
for (I in 0:3) {
drawSpiro(m = 96, n = 80, h = 1, phase = I+8, col = "red")
}
for (I in 0:2) {
drawSpiro(m = 96, n = 80, h = 20, phase = I, col = "blue")
}
for (I in 0:2) {
drawSpiro(m = 96, n = 80, h = 20, phase = I+3, col = "green")
}
for (I in 0:2) {
drawSpiro(m = 96, n = 80, h = 20, phase = I+6, col = "red")
}
drawClearPaper(m = 105)
for (I in c(1, 3, 5)) {
drawSpiro(m = 105, n = 63, h = I, col = "red")
}
for (I in c(7, 9, 11)) {
drawSpiro(m = 105, n = 63, h = I, col = "green")
}
for (I in c(13, 15, 17)) {
drawSpiro(m = 105, n = 63, h = I, col = "blue")
}
drawClearPaper(m = 105)
for (I in c(1, 3, 5)) {
drawSpiro(m = 105, n = 30, h = I, col = "blue")
}
for (I in c(1, 3, 5)) {
drawSpiro(m = 105, n = 45, h = I, col = "green")
}
for (I in c(1, 3, 5)) {
drawSpiro(m = 105, n = 60, h = I, col = "red")
}
drawClearPaper(m = 96)
for (I in c(1, 3, 5)) {
drawSpiro(m = 96, n = 64, h = I, col = "black")
}
for (I in c(7, 9, 11)) {
drawSpiro(m = 96, n = 64, h = I, col = "red")
}
for (I in c(13, 15, 17)) {
drawSpiro(m = 96, n = 64, h = I, col = "blue")
}
for (I in c(19, 21, 23, 25)) {
drawSpiro(m = 96, n = 64, h = I, col = "green")
}
drawClearPaper(m = 105)
drawSpiro(m = 105, n = 52, col = "green", pStart = 0, pEnd = 1/3)
drawSpiro(m = 105, n = 52, col = "blue", pStart = 1/3, pEnd = 2/3)
drawSpiro(m = 105, n = 52, col = "red", pStart = 2/3, pEnd = 1)
drawClearPaper(m = 96)
for (I in 1:5) {
drawSpiro(m = 96, n = 24, h = I, col = "blue")
drawSpiro(m = 96, n = 24, h = I, phase = 96/12, col = "green")
drawSpiro(m = 96, n = 24, h = I, phase = 2*96/12, col = "red")
}
for (I in 15:19) {
drawSpiro(m = 96, n = 80, h = I, col = "green")
drawSpiro(m = 96, n = 80, h = I, phase = 96/12, col = "red")
}
drawClearPaper(m = 96)
for (I in 1:9) {
drawSpiro(m = 96, n = 84, h = I, phase = I-1, col = "red")
}
for (I in 2:10) {
drawSpiro(m = 96, n = 84, h = I, phase = I-2, col = "red")
}
drawClearPaper(m = 105)
drawSpiro(m = 105, n = 60, h = 3, col = "red")
drawSpiro(m = 105, n = 60, h = 3, phase = 1, col = "red")
drawSpiro(m = 105, n = 60, h = 3, phase = -1, col = "red")
drawSpiro(m = 105, n = 60, h = 3, phase = 105/14, col = "blue")
drawSpiro(m = 105, n = 60, h = 3, phase = 105/14+1.5, col = "blue")
drawSpiro(m = 105, n = 60, h = 3, phase = 105/14-1.5, col = "blue")
drawClearPaper(m = 96)
for (I in 1:5) {
drawSpiro(m = 96, n = 24, h = I, col = "black")
}
drawSpiro(m = 96, n = 72, h = 9, col = "red")
drawSpiro(m = 96, n = 72, h = 9, phase = 1, col = "red")
drawSpiro(m = 96, n = 72, h = 9, phase = 2, col = "red")
drawSpiro(m = 96, n = 72, h = 9, phase = -1, col = "red")
drawSpiro(m = 96, n = 72, h = 9, phase = -2, col = "red")
drawSpiro(m = 96, n = 72, h = 18, phase = 12, col = "red")
drawSpiro(m = 96, n = 72, h = 19, phase = 12, col = "red")
drawSpiro(m = 96, n = 72, h = 20, phase = 12, col = "black")
drawSpiro(m = 96, n = 72, h = 21, phase = 12, col = "black")
drawClearPaper(m = 105)
drawSpiro(m = 105, n = 24, h = 5, col = "red")
drawSpiro(m = 105, n = 80, h = 13, col = "red")
drawSpiro(m = 105, n = 80, h = 14, col = "red")
drawSpiro(m = 105, n = 80, h = 15, col = "red")
drawClearPaper(m = 105)
for (I in 1:26) {
drawSpiro(m = 105, n = 84, h = I, phase = (I-1)*2, col = "blue")
}
drawClearPaper(m = 105)
drawSpiro(m = 105, n = 75, h = 1, col = "red")
drawSpiro(m = 105, n = 75, h = 2, phase = 1, col = "red")
drawSpiro(m = 105, n = 75, h = 2, phase = -1, col = "red")
drawSpiro(m = 105, n = 75, h = 3, phase = 2, col = "blue")
drawSpiro(m = 105, n = 75, h = 3, phase = -2, col = "blue")
drawSpiro(m = 105, n = 75, h = 4, phase = 3, col = "blue")
drawSpiro(m = 105, n = 75, h = 4, phase = -3, col = "blue")
drawSpiro(m = 105, n = 75, h = 5, phase = 4, col = "blue")
drawSpiro(m = 105, n = 75, h = 5, phase = -4, col = "blue")
drawSpiro(m = 105, n = 75, h = 6, phase = 5, col = "red")
drawSpiro(m = 105, n = 75, h = 6, phase = -5, col = "red")
drawSpiro(m = 105, n = 75, h = 7, phase = 6, col = "red")
drawSpiro(m = 105, n = 75, h = 7, phase = -6, col = "red")
drawSpiro(m = 105, n = 75, h = 8, phase = 7, col = "red")
drawSpiro(m = 105, n = 75, h = 8, phase = -7, col = "red")
drawClearPaper(m = 96)
drawSpiro(m = 96, n = 60, h = 3, phase = 1, col = "red")
drawSpiro(m = 96, n = 60, h = 3, phase = -1, col = "red")
drawSpiro(m = 96, n = 60, h = 5, phase = 2, col = "red")
drawSpiro(m = 96, n = 60, h = 5, phase = -2, col = "red")
drawSpiro(m = 96, n = 60, h = 2, phase = 0.5, col = "red")
drawSpiro(m = 96, n = 60, h = 2, phase = -0.5, col = "red")
drawSpiro(m = 96, n = 60, h = 4, phase = 1.5, col = "red")
drawSpiro(m = 96, n = 60, h = 4, phase = -1.5, col = "red")
drawSpiro(m = 96, n = 60, h = 6, phase = 2.5, col = "red")
drawSpiro(m = 96, n = 60, h = 6, phase = -2.5, col = "red")
drawSpiro(m = 96, n = 60, h = 1, col = "blue")
drawSpiro(m = 96, n = 60, h = 7, phase = 3, col = "blue")
drawSpiro(m = 96, n = 60, h = 7, phase = -3, col = "blue")
drawClearPaper(m = 105)
drawSpiro(m = 105, n = 24, h = 5, col = "black")
drawSpiro(m = 105, n = 36, h = 11, col = "red")
drawSpiro(m = 105, n = 48, h = 17, col = "blue")
drawSpiro(m = 105, n = 60, h = 23, col = "green")
drawSpiro(m = 105, n = 60, h = 23, phase=105/2, col = "green")
drawSpiro(m = 105, n = 72, h = 29, col = "black")
drawSpiro(m = 105, n = 84, h = 35, col = "red")
drawSpiro(m = 105, n = 84, h = 35, phase=105/2, col = "red")
drawClearPaper(m = 96)
drawSpiro(m = 96, n = 40, h = 5, col = "red")
drawSpiro(m = 96, n = 56, h = 9, col = "red")
drawSpiro(m = 96, n = 80, h = 15, col = "red")
drawSpiro(m = 96, n = 80, h = 15, phase = 96/12, col = "red")
drawSpiro(m = 96, n = 72, h = 13, col = "red")
drawSpiro(m = 96, n = 72, h = 13, phase = 96/12, col = "red")
drawSpiro(m = 96, n = 72, h = 13, phase = 2*96/12, col = "red")
drawSpiro(m = 96, n = 24, h = 1, col = "red")
drawSpiro(m = 96, n = 24, h = 1, phase = 96/12, col = "red")
drawSpiro(m = 96, n = 24, h = 1, phase = 2*96/12, col = "red")
drawSpiro(m = 96, n = 32, h = 3, col = "red")
drawSpiro(m = 96, n = 32, h = 3, phase = 96/12, col = "red")
drawSpiro(m = 96, n = 32, h = 3, phase = 2*96/12, col = "red")
drawSpiro(m = 96, n = 32, h = 3, phase = 3*96/12, col = "red")
drawSpiro(m = 96, n = 64, h = 11, col = "red")
drawSpiro(m = 96, n = 64, h = 11, phase = 96/12, col = "red")
drawSpiro(m = 96, n = 64, h = 11, phase = 2*96/12, col = "red")
drawSpiro(m = 96, n = 64, h = 11, phase = 3*96/12, col = "red")
drawSpiro(m = 96, n = 48, h = 7, col = "red")
drawSpiro(m = 96, n = 48, h = 7, phase = 96/12, col = "red")
drawSpiro(m = 96, n = 48, h = 7, phase = 2*96/12, col = "red")
drawSpiro(m = 96, n = 48, h = 7, phase = 3*96/12, col = "red")
drawSpiro(m = 96, n = 48, h = 7, phase = 4*96/12, col = "red")
drawSpiro(m = 96, n = 48, h = 7, phase = 5*96/12, col = "red")
drawClearPaper(m = 96)
drawSpiro(m = 96, n = 40, h = 1, col = "black")
drawSpiro(m = 96, n = 56, h = 1, col = "black")
drawSpiro(m = 96, n = 24, h = 1, col = "black")
drawSpiro(m = 96, n = 24, h = 1, phase = 96/12, col = "black")
drawSpiro(m = 96, n = 24, h = 1, phase = 2*96/12, col = "black")
drawSpiro(m = 96, n = 32, h = 1, col = "black")
drawSpiro(m = 96, n = 32, h = 1, phase = 96/12, col = "black")
drawSpiro(m = 96, n = 32, h = 1, phase = 2*96/12, col = "black")
drawSpiro(m = 96, n = 32, h = 1, phase = 3*96/12, col = "black")
drawSpiro(m = 96, n = 48, h = 1, col = "black")
drawSpiro(m = 96, n = 48, h = 1, phase = 96/12, col = "black")
drawSpiro(m = 96, n = 48, h = 1, phase = 2*96/12, col = "black")
drawSpiro(m = 96, n = 48, h = 1, phase = 3*96/12, col = "black")
drawSpiro(m = 96, n = 48, h = 1, phase = 4*96/12, col = "black")
drawSpiro(m = 96, n = 48, h = 1, phase = 5*96/12, col = "black")
drawClearPaper(m = 96)
drawSpiro(m = 96, n = 45, h = 1, col = "red")
drawSpiro(m = 96, n = 45, h = 10, col = "blue")
drawSpiro(m = 96, n = 45, h = 16, col = "green")
drawSpiro(m = 96, n = 63, h = 3, col = "green")
drawSpiro(m = 96, n = 63, h = 5, col = "red")
drawClearPaper(m = 275)
for (I in 1:9) {
drawSpiro(m = -144, n = 72, h = 1, phase = I-1, col = "blue")
}
for (I in 1:9) {
drawSpiro(m = -144, n = 72, h = 1, phase = I-1 + 1.5*144/12, col = "red")
}
for (I in 1:9) {
drawSpiro(m = -144, n = 72, h = 1, phase = I-1 + 3*144/12, col = "green")
}
for (I in 1:9) {
drawSpiro(m = -144, n = 72, h = 1, phase = I-1 + 4.5*144/12, col = "black")
}
drawSpiro(m = 96, n = 52, h = 1, col = "green")
drawSpiro(m = -84, n = 40, h = 13, col = "blue")
Source file spiro.R
# Math: https://en.wikipedia.org/wiki/Spirograph
drawClearPaper <- function(m = 96) {
R <- m/(2*pi)
plot(x=c(-R, R), y=c(-R, R), type = "n", asp = 1)
}
#' drawSpiro
#'
#' @param m ring size (number of teeth) - negative for outer wheel motion
#' @param n wheel size (number of teeth) - always positive
#' @param h (hole number, starting at 1)
#' @param phase (wheel phase - number of teeth (starting at 0), according to ring size)
#' @param pStart start of the part of the shape to draw (0-1)
#' @param pEnd end of the part of the shape to draw (0-1)
#' @param npoints resolution - number of points per one wheel turn
#' @param col color
drawSpiro <- function(m = 96, n = 32, h = 1, phase = 0, pStart = 0, pEnd = 1, npoints = 1000, col = "black") {
v <- numbers_LCM(m, n) / n # number of peaks of the resulting shape
turns <- numbers_LCM(m, n) / m # number of turns
R <- m/(2*pi) # ring radius
r <- n/(2*pi) # wheel radius
# d <- 0.85-(h-1)*0.025 # distance of hole from the center of the wheel ... my first approximation
# ro <- r*d
# ro <- r - (1 - (0.84761904-(h-1)*0.0247619)) * 80/(2*pi) # better approximation
# ro <- r - (1 - (0.84761904-(h-1)*0.024)) * 80/(2*pi) # another approximation
ro <- r - (1 - (0.872-(h-1)*0.025)) * 80/(2*pi) # the best approximation in the respect to the original
ph <- -phase / m * 2*pi
t <- seq(pStart*turns*2*pi, pEnd*turns*2*pi, length.out = turns*npoints)
# translate axes so the beginning is at the top of the image
y <- (R-r)*cos(t) + ro*cos((R-r)/r*t)
x <- (R-r)*sin(t) - ro*sin((R-r)/r*t)
x <- -x
# phase rotation
s <- sin(ph)
c <- cos(ph)
xNew <- x*c - y*s
yNew <- x*s + y*c
lines(xNew, yNew, col = col)
}
# functions GCD a LCM from "numbers" package # library(numbers)
numbers_GCD <- function (n, m)
{
stopifnot(is.numeric(n), is.numeric(m))
if (length(n) != 1 || floor(n) != ceiling(n) || length(m) !=
1 || floor(m) != ceiling(m))
stop("Arguments 'n', 'm' must be integer scalars.")
if (n == 0 && m == 0)
return(0)
n <- abs(n)
m <- abs(m)
if (m > n) {
t <- n
n <- m
m <- t
}
while (m > 0) {
t <- n
n <- m
m <- t%%m
}
return(n)
}
numbers_LCM <- function (n, m)
{
stopifnot(is.numeric(n), is.numeric(m))
if (length(n) != 1 || floor(n) != ceiling(n) || length(m) !=
1 || floor(m) != ceiling(m))
stop("Arguments 'n', 'm' must be integer scalars.")
if (n == 0 && m == 0)
return(0)
return(n/numbers_GCD(n, m) * m)
}