Giter Site home page Giter Site logo

sierpinskitriangle's Introduction

Sierpinski Triangle

The Sierpinski Triangle is a fractal. According to Wikipedia it was named after "mathematician Waclaw Sierpinski who described it in 1915. However, similar patterns appear already in the 13th-century Cosmati mosaics in the cathedral of Anagni, Italy." You can create the Sierpinski Triangle (and very similar fractals) with surprisingly little code. The following picture and instructions are also from Wikipedia.

Alt text

Start with any triangle, though the usual Sierpinski triangle uses an equilateral triangle. Shrink the triangle to ½ height and ½ width, make three copies, and position the three shrunken triangles so that each triangle touches the two other triangles at a corner (image 2). Note the emergence of the central hole - because the three shrunken triangles can between them cover only 3/4 of the area of the original. (Holes are an important feature of Sierpinski's triangle.) Repeat step 2 with each of the smaller triangles (image 3 and so on).

Suggested steps to complete this assignment:

  1. Fork and clone down this repository (Optional: Create your own repository from scratch. Look at the bottom of this page for instructions)

  2. Write the sierpinski function:

    • If len is greater than 20 (or some variable)
      • recursively call the sierpinksi function to draw a triangle with the left corner at (x,y) and a base and height equal to len/2.
      • Again, call the sierpinksi function a second time to draw another triangle a distance of len/2 to the right of the first triangle.
      • Now, call the sierpinksi function a third time to draw a triangle a distance of len/4 to the right and len/2 up from the first triangle. This triangle should "sit on top" of the first two.
    • else
      • Draw a triangle with the left corner at (x,y) and a base and height equal to len.
  3. Once you have the sierpinksi function completed, call it once in draw() to start the process. You can change the number and size of the triangles by changing the limit in the if from 20 to some variable and adjusting the value of the variable. One way to make the program interactive is to use mouseDragged to change the limit.

  4. Feel free to create your own inidividual variation of the Sierpinski triangle. Your recursive triangle doesn't have to look like any other. The mathematically adventurous might want to check out the sierpinski triangle page to end most sierpinski triangle pages ™.

  5. You could also create a Sierpinski carpet as an alternative to the Sierpinski Triangle.

Optional: Create your own repository from scratch

It's not hard to create your own repostiory.

  1. Create a folder called SierpinskiTriangle in your apjava folder.
  2. Copy processing.js from a previous assignment and move it to the SierpinskiTriangle folder (Or, better practice, download the latest development version)
  3. Use Sublime to create the following 3 files, all of which are stored in the SierpinskiTriangle folder. Choose New File and then Save As and give the file the correct name
    • SierpinskiTriangle.pde
    • index.html (can be copied from a previous assignment, you will just need to change the canvas id tag in the body to match the name SierpinskiTriangle)
    • styles.css (can be copied from a previous assignment)
  4. Now, go to GitHub and create a new empty SierpinskiTriangle repository. GitHub will provide the commands that you use to link your local SierpinskiTriangle folder to the GitHub repository
  5. To display your program on the web, you will want to create a new gh-pages branch. Then, go to the GitHub settings and make gh-pages the default branch

Samples of Student Work

Dante

sierpinskitriangle's People

Contributors

simart avatar lmaragon avatar

Watchers

James Cloos 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.