Code Monkey home page Code Monkey logo

spheromaniac's Introduction

Spheromaniac

To generate typical spirograph-like patterns (aka mathematical roulettes), you can trace the path of a circle rolling around inside a bigger circle. What if, instead, you rolled one sphere inside another sphere? That generates a three-dimensional pattern that I call a spherograph. This code generates spherographs.

spherograph

How does it work?

It's easy to draw a circle. Loop over the values from 0 to 2 * ฯ€ (there are infinitely many, so maybe use an interval). This produces an angle in raidans. Your x-coordinate is cosine of the angle and your y-coordinate is sine. Then draw a pixel at that location. Something like this in (pseudo-code):

for (angle = 0.0; angle < 2 * Math.PI; angle += 0.01)
{
    x = cos(angle);
    y = sin(angle);
    draw(x, y);
}

If you rotate the canvas while drawing the circle (and the centers of rotation are a little offset) then you'll get a basic spirograph. But how to rotate the canvas? The math isn't too hard, but it's trivial with a matrix math library (I used gl-matrix, which is very nice). But while we're rotating on the Z-plane, why not also rotate along X or Y? Then rotate for the camera and we're done.

spheromaniac's People

Contributors

marksilverman avatar

Stargazers

 avatar jjay avatar Sarmad Gardezi avatar  avatar Abod avatar  avatar Peter Parnes avatar Walker Hutchinson avatar Stephen Lains avatar  avatar Monica Powell avatar  avatar Yash Pandey avatar Arindam Das avatar danielsdesk avatar Ivan Viveros avatar Patrick Oliveira avatar

Watchers

James Cloos avatar  avatar Zaid Taha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.