idk tf
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();
let num=4; // min=2 max=10 step=1 number of vertices
vertices=[]
j=0
while(j<num){
x=50*Math.sin(j*(6.283185/num))
y=50*Math.cos(j*(6.283185/num))
vertices.push([x,y])
j++
}
turtle.goto(0,0)
turtle.pendown()
// The walk function will be called until it returns false.
c=0
pre=[0]
function walk(i) {
n=Math.ceil(Math.random()*vertices.length)-1;
c1=pre[i]
c2=pre[i-1]
if(c1==c2){
while((c+1)%num==n||(c-1)%num==n){
n=Math.ceil(Math.random()*vertices.length)-1;
}
}
let r=0.618 //min=0 max=1 step=0.01
x=turtle.xcor()+(vertices[n][0]-turtle.xcor())*r
y=turtle.ycor()+(vertices[n][1]-turtle.ycor())*r
turtle.jump(x,y)
turtle.circle(0.04)
c=n
pre.push(c)
return i<90000
}