1. Sierpinski
A Sierpinski triangle is a recursive structure of triangleswithin triangles. The order of the Sierpinskitriangle refers to how many levels of nested triangles to draw.There is one outer triangle that points upward. Then we can draw adownward facing triangle within it. This then creates three newupward facing triangles (above, left, and right of the downwardone), in which we can repeat this process. For example:
Write a program that takes the order as a command-line argument(e.g., java Sierpinski 2) and draws the correspondingSierpinski triangle. You can use Sierpinski.java as astarting point. Your program should use recursion. Due to integerrounding, your images might look slightly different than thoseabove.
To draw a triangle, you may want to usethe g.drawPolygon(xs, ys, n) method,where xs is a list of x-coordinates, ys a listof y-coordinates, and n the number of vertices.
Please complete in java and provide a screenshot of theoutput.
1. Sierpinski A Sierpinski triangle is a recursive structure of triangles within triangles. The order of the Sierpinski
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am