smiley face-eption

first attempt at coding in turtletoy

Log in to post a comment.

Canvas.setpenopacity(1);

// Function to draw a smiley face
function drawSmileyFace(x, y) {
    const turtle = new Turtle();
    turtle.penup();
    turtle.goto(x, y);
    turtle.pendown();

    // Function to draw a circle
    function drawCircle(radius) {
        turtle.circle(radius);
    }

    // Function to draw eyes
    function drawEye(x, y) {
        turtle.penup();
        turtle.goto(x, y);
        turtle.pendown();
        turtle.circle(10);
    }

    // Function to draw a smile
    function drawSmile() {
        turtle.penup();
        turtle.goto(x + 20, y - 20);
        turtle.pendown();
        turtle.right(90);
        turtle.circle(20, 180);
    }

    // Draw the face
    drawCircle(25);
    drawEye(x - 10, y + 5); // Left eye
    drawEye(x + 10, y + 5); // Right eye
    //drawSmile(); // Smile
}
// Define smiley face dimensions
const faceWidth = 50;
const faceHeight = 50;

// Define canvas dimensions
const canvasWidth = Canvas.width;
const canvasHeight = Canvas.height;

// Repeat smiley faces across the canvas
for (let y = -canvasHeight / 2; y < canvasHeight / 2; y += faceHeight * 1.5) {
    for (let x = -canvasWidth / 2; x < canvasWidth / 2; x += faceWidth * 1.5) {
        if (Math.abs(x) + faceWidth <= canvasWidth / 2 && Math.abs(y) + faceHeight <= canvasHeight / 2) {
            drawSmileyFace(x, y);
        }
    }
}
 drawSmileyFace(0, 0);
  drawSmileyFace(0, -20);
   drawSmileyFace(0, 20);