Stars 001

Stars 001
I am thinking of plotting a starfield based on actual coordinates and size relative to brightness

Log in to post a comment.

// You can find the Turtle API reference here: https://turtletoy.net/syntax
// MIT Licence

Canvas.setpenopacity(1);

let maxScale=5; //min=1 max=10 step=1
let stars= 100; //min=1 max=200 step=1
const turtle = new Turtle();

function walk(i) {
    // random position
    let randomX = getRandomInt(200);
    let randomY = getRandomInt(200); 
    randomX = randomX -100;
    randomY = randomY -100;
    scale =  getRandomInt(maxScale + 1); 
    turtle.penup();
    turtle.goto(randomX, randomY);

    // N S  arm
    turtle.penup();
    turtle.goto(randomX, randomY);
    turtle.pendown();
    turtle.setheading(90);
    turtle.penup();
    turtle.forward(scale);
    let position3 = turtle.position();
    turtle.pendown();
    turtle.right(180);
    turtle.forward(scale * 2);
    let position0 = turtle.position();
    
    // NW SE arm
    turtle.penup();
    turtle.goto(randomX, randomY);
    turtle.pendown();
    turtle.setheading(30);
    turtle.penup();
    turtle.forward(scale);  
    turtle.pendown();
    let position2 = turtle.position();
    turtle.right(180);
    turtle.forward(scale * 2);
    let position5 = turtle.position();
        
    // SW NE arm
    turtle.penup();
    turtle.goto(randomX, randomY);
    turtle.setheading(-30); 
    turtle.penup();
    turtle.forward(scale);
    turtle.pendown();
    let position1 = turtle.position();
    turtle.right(180);
    turtle.forward(scale * 2);
    let position4 = turtle.position();

    // draw star of david
    turtle.jump(position0);
    turtle.pendown();
    turtle.goto(position2)
    turtle.goto(position4)
    turtle.goto(position0)

    turtle.jump(position5);
    turtle.pendown();
    turtle.goto(position1)
    turtle.goto(position3)
    turtle.goto(position5)

    return i < stars-1;
}
function getRandomInt(max) {
  return Math.floor(Math.random() * max);
}

console.log(getRandomInt(3));
// Expected output: 0, 1 or 2