random walks from a circle
Log in to post a comment.
// Forked from "hairy square" by SimonKirby
// https://turtletoy.net/turtle/914281c07f
// 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();
turtle.radians();
function turtle_start() {
let angle = Math.random()*2*Math.PI;
if (Math.random()<0.2) {
turtle.jump(Math.sin(angle)*50, Math.cos(angle)*50);
turtle.seth(Math.random()*2*Math.PI);
} else {
turtle.jump(Math.sin(angle)*35, Math.cos(angle)*35);
turtle.seth(Math.random()*2*Math.PI)
}
}
function circle(s) {
turtle.penup();
turtle.forward(s);
turtle.pendown();
let x = turtle.x();
let y = turtle.y();
turtle.jump(x,y+s);
for (let angle=0; angle<2*Math.PI+0.1; angle+=0.1) {
turtle.goto(x+Math.sin(angle)*s, y+Math.cos(angle)*s);
}
}
turtle_start();
let age = 0;
// The walk function will be called until it returns false.
function walk(i) {
if (Math.random()<age/50 && Math.sqrt(turtle.x()**2+turtle.y()**2)<50) {
turtle.penup();
} else {
turtle.pendown();
}
age++;
turtle.forward(1);
turtle.lt((Math.random()-0.5));
//turtle.seth((turtle.h()*10+Math.PI/2)/11);
let x = turtle.x();
let y = turtle.y();
if (age>40 || (Math.sqrt(x**2+y**2)<50 && Math.sqrt(x**2+y**2)>35)) {
if (Math.sqrt(x**2+y**2)>60) {
circle(1);
}
turtle_start();
age=0;
}
return i < 20000;
}