Draws randomly sized zeros and ones at random positions of the canvas
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.penup();
// The walk function will be called until it returns false.
function walk(i) {
if (i % 2 == 0) {
goto_random();
draw_0();
}
else {
goto_random();
draw_1();
}
return i<1000;
}
function goto_random() {
turtle.goto((Math.random() - 0.5) * 195, (Math.random() - 0.5) * 195);
}
function goto_random_outer() {
x = NaN;
y = NaN;
while(true) {
x = (Math.random() - 0.5) * 195;
y = (Math.random() - 0.5) * 195;
if (!((x >=-50 && x <= 50) && (y >=-50 && y<=50))) {
break;
}
}
turtle.goto(x, y);
}
function goto_random_inner() {
turtle.goto((Math.random() - 0.5) * 100, (Math.random() - 0.5) * 100);
}
function draw_0() {
size = (Math.random() + 0.1) * 5;
size=3;
turtle.setheading(0);
turtle.pendown();
turtle.circle(size, extent=90);
turtle.forward(size);
turtle.circle(size, extent=180);
turtle.forward(size);
turtle.circle(size, extent=90);
turtle.penup();
}
function draw_1() {
size = (Math.random()+0.1) * 4;
turtle.pendown();
turtle.left(50);
turtle.forward(size*2.5);
turtle.right(140);
turtle.forward(size*5);
turtle.left(90);
turtle.penup()
}