hackclub / blot

🤖 ✍️ blot, the plotting bot from hack club

Home Page:http://blot.hackclub.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

here is a function to draw N-Sided regular polygons

FOSSBOSS opened this issue · comments

I made this function to draw N-sided regular polygons:
For implementation in: https://github.com/hackclub/blot/blob/main/src/drawingToolkit/Turtle.js

function polygon(sideLength, sides) {
   // const t = new Turtle();
      if (sides <= 2) {
         return;     
    }
    const angle = 360 / sides;
    
    for (let i = 0; i < sides; i++) {
        t.forward(sideLength);
        t.right(angle);
    }
}

// Example usage: draw a triangle with side length 50
polygon(50, 3);

// Example usage: draw a hexagon with side length 40
polygon(40, 6);

Where I don't have the hardware to run this project, I probably wont fork it, but have a look, at this code anyway if you want to add drawing N-sided regular polygons to the project.

I don't think its neccesary to add this to the toolkit as if someone needed to make a polygon, they could just put this function into their code.