Question

In: Computer Science

Write a three.js/HTML programming to generate a Sierpenski Triangle using recursion (generate until 10 depth of...

Write a three.js/HTML programming to generate a Sierpenski Triangle using recursion (generate until 10 depth of recursion)

Need the index code with it too so I am able to run it

Example of triangle below:

Solutions

Expert Solution

The Sierpiński triangle (sometimes spelled Sierpinski), is also called the Sierpiński gasket or Sierpiński sieve, is a fractal attractive fixed set with the overall shape of an equilateral triangle,subdivided recursively into smaller equilateral triangles. Originally constructed as a curve, this is one of the basic examples of self similar sets—that is, it is a mathematically generated pattern that is reproducible at any magnification or reduction. It is named after the Polish mathematician Wacław Sierpiński, but appeared as a decorative pattern many centuries before the work of Sierpiński.

code for Sierpiński triangle

import turtle

def drawTriangle(points,color,myTurtle):

    myTurtle.fillcolor(color)

    myTurtle.up()

    myTurtle.goto(points[0][0],points[0][1])

    myTurtle.down()

    myTurtle.begin_fill()

    myTurtle.goto(points[1][0],points[1][1])

    myTurtle.goto(points[2][0],points[2][1])

    myTurtle.goto(points[0][0],points[0][1])

    myTurtle.end_fill()

def getMid(p1,p2):

    return ( (p1[0]+p2[0]) / 2, (p1[1] + p2[1]) / 2)

def sierpinski(points,degree,myTurtle):

    colormap = ['blue','red','green','white','yellow',

                'violet','orange']

    drawTriangle(points,colormap[degree],myTurtle)

    if degree > 0:

        sierpinski([points[0],

                        getMid(points[0], points[1]),

                        getMid(points[0], points[2])],

                   degree-1, myTurtle)

        sierpinski([points[1],

                        getMid(points[0], points[1]),

                        getMid(points[1], points[2])],

                   degree-1, myTurtle)

        sierpinski([points[2],

                        getMid(points[2], points[1]),

                        getMid(points[0], points[2])],

                   degree-1, myTurtle)

def main():

   myTurtle = turtle.Turtle()

   myWin = turtle.Screen()

   myPoints = [[-100,-50],[0,100],[100,-50]]

   sierpinski(myPoints,3,myTurtle)

   myWin.exitonclick()

main()


Related Solutions

Write a three.js/HTML programming to generate a Sierpenski Triangle using recursion (generate until 10 depth of...
Write a three.js/HTML programming to generate a Sierpenski Triangle using recursion (generate until 10 depth of recursion) Need the index code with it too so I am able to run it
In this programming assignment, you will write C code that performs recursion. For the purpose of...
In this programming assignment, you will write C code that performs recursion. For the purpose of this assignment, you will keep all functions in a single source file main.c. Your main job is to write a recursive function that generates and prints all possible password combinations using characters in an array. In your main() function you will first parse the command line arguments. You can assume that the arguments will always be provided in the correct format. Remember that the...
Write a program that performs a merge-sort algorithm without using a recursion. c++ programming language(Only #inlclude...
Write a program that performs a merge-sort algorithm without using a recursion. c++ programming language(Only #inlclude <iostream>)
Write a program in python that implements quicksort, first using recursion and then without recursion.
Write a program in python that implements quicksort, first using recursion and then without recursion.
Can you please solve this using recursion/ dynamic programming? Any programming language is fine. Wallace the...
Can you please solve this using recursion/ dynamic programming? Any programming language is fine. Wallace the Weightlifting Walrus is training for a contest where it will have to lift 1000 kg. Wallace has some weight plates lying around, possibly of different weights, and its goal is to add some of the plates to a bar so that it can train with a weight as close as possible to 1000 kg. In case there exist two such numbers which are equally...
a) Using the programming tool of your choice generate 10 random numbers from a flat distribution...
a) Using the programming tool of your choice generate 10 random numbers from a flat distribution between -0.5 and 0.5, and find the mean of these 10 numbers. Consider this mean to be the ‘result’ of this procedure. b) Repeat this 10 times and calculate the mean and variance of your 10 results. Is the distance of the mean from 0 about what you would expect? Why? c) Now repeat it 100 times and calculate the mean and variance. Is...
For this assignment, you will write a tic-tac-toe application in HTML and JavaScript, using an HTML...
For this assignment, you will write a tic-tac-toe application in HTML and JavaScript, using an HTML <canvas> tag. The game will be played "hot seat" where players take turns using the same device. Requirements: The canvas should be 600px tall and wide, with the gameplay area occupying most of the canvas. The X's and O's may be drawn using polygons or large-font text The grid should be drawn using polygons, specifically long, thin rectangles Before & between games, the canvas...
Purpose For this programming project, you will create an application that draws fractal-like shapes using recursion....
Purpose For this programming project, you will create an application that draws fractal-like shapes using recursion. The class that creates the graphics window for the display of the shapes is given to you (see below). What you have to do is create a set of classes for the three shapes that are displayed in the graphics window. Two of the shapes must be a Sierpinski triangle and an H-shape. The third shape is your choice, though it must be a...
Generate the first ten rows of Pascal triangle using MATLAB. Post code in the response
Generate the first ten rows of Pascal triangle using MATLAB. Post code in the response
Write the class RecursiveProbs, with the methods listed below. Write all the methods using recursion, not...
Write the class RecursiveProbs, with the methods listed below. Write all the methods using recursion, not loops. You may use JDK String methods like substring() and length(), but do not use the JDK methods to avoid coding the algorithms assigned. For example, don't use String.reverse(). public boolean recursiveContains(char c, String s) returns true if the String contains the char, otherwise returns false. Here is the code for this method, which you should use as an example to see how to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT