Skip to content

Latest commit

 

History

History
93 lines (79 loc) · 5.92 KB

polar-shapes.md

File metadata and controls

93 lines (79 loc) · 5.92 KB

Polar Shapes - WIP

The shape code can be found in the shapes.js file. The ShapeUI class (shape_ui.js) adds the dropdown and add a new Shape in the selectShape(shapeName, shapeValues) function. A switch statement to select the specific shape choosen by the user. The selectShape() function is called in the addLsystem() function is the Turtle class (turtle.js).

If you would like to learn more about polar coordinates and rendering polaring shapes, I highly recommend reading Daniel Shiffman's The Nature of Code book or watching some of Daniel Shiffman's tutorial videos. You can find an p5.js sketch here for experimenting with the shape parameters.

Polar Coordinates - The Nature of Code

Coding Challenge #23: 2D Supershapes

Coding Challenge #134: Heart Curve

Code

Here is the code to instantiate the Shape class:

selectedShape = new Shape(
    0,
    0,
    length * shapeScale,
    a,
    b,
    m,
    n1,
    n2,
    n3,
    n,
    shapeAngle
);

While most of the shapes are closed, several shapes are "open" by nature. There are therefore two different functions in the Shapes class to render the shape -- a show() and an openShow(). I have also added messaging about the shape curves which appears when the shape is selected if it is a function of the shape parameters (a, b, m, n1, n2, n3, n). For example, if the supershape is selected, this message appears:

The supershape curve is a f(a, b, m, n, n1, n2, n3).

🌄 Shape Images

Archimedes spiral

Archimedes spiral
Astroid

Astroid
Bicorn

Bicorn
Cassini oval

Cassini oval
Ceva

Ceva
Cornu spiral

Cornu Spiral
Cross

Maltese Cross
Deltoid

Deltoid
Eight curve

Eight curve
Gear curve

Gear curve
Heart curve

Heart curve
Kiss curve

Kiss curve
Quadrifolium

Quadrifolium
Polygon

Quadrilateral
Superellipse

Superellipse
Supershape

Supershape
Tear

Tear