1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
aleksklad [387]
2 years ago
8

The Polish mathematician Wacław Sierpiński described the pattern in 1915, but it has appeared in Italian art since the 13th cent

ury. Though the Sierpinski triangle looks complex, it can be generated with a short recursive function. Your main task is to write a recursive function Sierpinski() that plots a Sierpinski triangle of order n to standard drawing. Think recursively: Sierpinski() should draw one filled equilateral triangle (pointed downwards) and then call itself recursively three times (with an appropriate stopping condition). It should draw 1 filled triangle for n = 1; 4 filled triangles for n = 2; and 13 filled triangles for n = 3; and so forth.
API specification:
When writing your program, exercise modular design by organizing it into four functions, as specified in the following API:

public class Sierpinski {

// Height of an equilateral triangle whose sides are of the specified length.
public static double height(double length)

// Draws a filled equilateral triangle whose bottom vertex is (x, y)
// of the specified side length.
public static void filledTriangle(double x, double y, double length)

// Draws a Sierpinski triangle of order n, such that the largest filled
// triangle has bottom vertex (x, y) and sides of the specified length.
public static void Sierpinski(int n, double x, double y, double length)

// Takes an integer command-line argument n;
// draws the outline of an equilateral triangle (pointed upwards) of length 1;
// whose bottom-left vertex is (0, 0) and bottom-right vertex is (1, 0); and
// draws a Sierpinski triangle of order n that fits snugly inside the outline.
public static void main(String[] args)
}

Restrictions: You may not change either the scale or size of the drawing window.
Observe the following rules:

DO NOT use System.exit().
DO NOT add the project or package statements.
DO NOT change the class name.
DO NOT change the headers of ANY of the given methods.
DO NOT add any new class fields.
ONLY display the result as specified by the example for each problem.
DO NOT print other messages, follow the examples for each problem.
USE StdIn, StdOut, and StdDraw libraries.
Computers and Technology
1 answer:
soldi70 [24.7K]2 years ago
7 0

Answer:

/ Sierpinski.java

public class Sierpinski {

     // method to find the height of an equilateral triangle with side length =

     // length

     public static double height(double length) {

           // formula= length*sqrt(3)/2

           double h = (length * Math.sqrt(3)) / 2.0;

           return h;

     }

     // method to draw a filled triangle (pointed downwards) with bottom vertex

     // x,y

     public static void filledTriangle(double x, double y, double length) {

           // finding height

           double h = height(length);

           // filling triangle as a polygon

           // passing x, x-length/2, x+length/2 as x coordinates

           // and y, y+h, y+h as y coordinates

           StdDraw.filledPolygon(new double[] { x, x - (length / 2.0),

                       x + (length / 2.0) }, new double[] { y, y + h, y + h });

     }

     // method to draw an n level sierpinski triangle

     public static void sierpinski(int n, double x, double y, double length) {

           // checking if n is above 0 (base condition)

           if (n > 0) {

                 // drawing a filled triangle with x, y as bottom coordinate, length

                 // as side length

                 filledTriangle(x, y, length);

                 // drawing the triangle(s) on the top

                 sierpinski(n - 1, x, y + height(length), length / 2);

                 // drawing the triangle(s) on the left side

                 sierpinski(n - 1, x - (length / 2.0), y, length / 2);

                 // drawing the triangle(s) on the right side

                 sierpinski(n - 1, x + (length / 2.0), y, length / 2);

           }

     }

     public static void main(String[] args) {

           // parsing first command line argument as integer, if you dont provide

           // the value while running the program, this program will cause

           // exception.

           int n = Integer.parseInt(args[0]);

           // length of the outline triangle

           double length = 1;

           // finding height

           double h = height(length);

           // drawing a triangle (pointed upwards) to represent the outline.

           StdDraw.polygon(new double[] { 0, length / 2, length }, new double[] {

                       0, h, 0 });

           // drawing n level sierpinski triangle(s) with length / 2, 0 as x,y

           // coordinates and length / 2 as initial side length

           sierpinski(n, length / 2, 0, length / 2);

     }

}

You might be interested in
I WILL GIVE BRAINLIEST TO WHO ANSWERS FIRST AND CORRECTLY.
svlad2 [7]

Answer:

The answer is false

Explanation:

Please give me brainliest so I can post my artwork

6 0
3 years ago
Ali has created a small program in Python, but he wants to store his data in a multi-dimensional array. He would like to use adv
Dafna11 [192]

NumPy is the key scientific Python computing package. This makes things simpler to display large numbers of data in advanced maths and other operating types. These operations are typically extra efficient and less code-based than that of the built-in sequences in Python are possible, and the further discussion can be defined as follows:

  • It offers a multidimensional array object, as do variations such as masks and matrixes that can be used for different mathematical activities.
  • It is an external library of basic levels in Python used for complex mathematical procedures.
  • It has integrated functions that <em><u>convert various algorithms into arrays</u></em>.

So, the answer is "NumPy".

Learn more:

brainly.com/question/24817911

6 0
1 year ago
What does it mean when your phone says not registered on network?.
Tasya [4]

Answer:

There could be an issue with your SIM card, or the problem could be on your carrier's end. Possible causes of the 'not registered on network' error include:

Your phone's firmware or operating system is out of date.

The SIM card is disconnected or damaged.

Your carrier is not selected in your phone's settings.

Your carrier is experiencing an outage.

Explanation:

5 0
2 years ago
How does theatre compare with movies or television? What makes it similar to movies and television? What makes it different?
givi [52]

Answer:

you cant mess up in theatre but you can redo scences in movies, thay both have acting in them

Explanation:

im a theatre person

3 0
3 years ago
Data driven processes: Select one: a. are heavily based on intuition b. rely heavily on the experience of the process owners c.
krek1111 [17]

Answer:

c. are based on statistical data, measurement and metrics

Explanation:

Data driven process are process that are not based on intuition but rather are based on data. This data serves as evidence to back a decision that is to be taken. It therefore means that, whatever decision that will be taken, such a decision will be based on the data presented.

6 0
2 years ago
Other questions:
  • Categories of general purpose application software and examples each​
    13·1 answer
  • While you are working with a document using a program such as wordpad, the document is stored in ___________?
    15·2 answers
  • A website's ____ page provides basic information about the individual or organization and includes a navigation bar with links t
    13·1 answer
  • I WILL GIVE BRAINLIEST TO WHO ANSWERS FIRST AND CORRECTLY.
    6·2 answers
  • Which member of the Jackson family was the spokesperson for the Psychic Friends Network.​
    7·1 answer
  • For a business that is properly using a social media information system, the system can
    13·1 answer
  • Do anyone else receive random points from Brainly… because I swear I had like 2K+ something and I check and Im at ACE… and with
    10·1 answer
  • Which of these is not the correct method for moving text in a document in Word 2016?
    5·1 answer
  • Bank Account Postings While reviewing your checking account balance online, you notice that debit card purchases have not posted
    5·1 answer
  • To set up scenarios,then set up a list, then set up the reference cell. to set up the cells that display the output results from
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!