Log in to post a comment.

// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(1);

// Global code will be evaluated once.
const turtle = new Turtle();
turtle.pendown();

// cardiod_modulo_n_455_500
// How to calculate points on a circle
// Based on code from http://www.mathopenref.com/coordcirclealgorithm...
/* 
There are 2 * PI Radians in a circle
If we have a circle of radius 20 with its center at the origin, the circle can be described by the pair of equations
x = 20 cos(t) 
y = 20 sin(t)
also pased on https://www.youtube.com/watch?v=qhbuKbxJsk8&amp... 
Times Tables, Mandelbrot and the Heart of Mathematics
by Burkard Polster and Giuseppe Geracitano
see: http://codepen.io/hippiefuturist/full/NAvqgk/

Artwork on Redbubble at: https://www.redbubble.com/shop/ap/24619400
Code on Github at: https://github.com/rupertrussell/cardiod_modulo_n_455_500

*/
const radius=95; // //min=10 max=200 step=1
const n = 115; //min=10 max=500 step=1
const fineN = 0; //min=-5 max=5 step=0.01 
const m = 232; //min=10 max=455 step=1
const fineM = 0; //min=-10 max=10 step=1 
const xoffset = 0 // //min=-100 max=100 step=1
const yoffset = 0// //min=-100 max=100 step=1
const outerCircle = 0; //min=0 max=1 step=1 (Yes, No)


cardioid(n + fineN, radius, xoffset, yoffset); // number of points on circle, radius of circle
// draw the cardiod lines
for (var i = 0; i < n + fineN; i = i+1) {
    connectPoints(n + fineN, radius, i, i * m + fineM);
}
// draw the outline circle
if(outerCircle ==0){
    turtle.jump(0,0 - radius);
    turtle.circle(radius, extent = undefined, steps = undefined)
}

function cardioid( n,  r, offset) {
// draws n points on a circle
const step = 2 * Math.PI/n; 

// draw n points on circle
for (var theta=0; theta < 2 * Math.PI; theta += step) {
var x = xoffset + r * Math.cos(theta);
var y = yoffset - r * Math.sin(theta);
// stroke(255, 0, 0);
// point(x, y);
}
}

function connectPoints(n,  r,  firstPoint, secondPoint) {
// Connect two points on a circle
var step = 2 * Math.PI/n; 

// draw n points on circle
const x1 = xoffset + r * Math.cos(firstPoint * step);
const y1 = yoffset - r * Math.sin(firstPoint * step);
const x2 = xoffset + r * Math.cos(secondPoint * step);
const y2 = yoffset -r * Math.sin(secondPoint * step);
// strokeWeight(15 * scale);
// stroke(0, 0, 0);
turtle.jump(x1, y1);
turtle.goto(x2, y2);
}