norahramahi123
07.10.2019 •
Biology
Which process causes hillsides and mountains to gradually get smaller?
Solved
Show answers
More tips
- W Work and Career Which types of activities are not subject to mandatory licensing?...
- C Computers and Internet Thin Client: What It Is and Why You Need It?...
- F Food and Cooking The Most Delicious and Simple Fish in Batter Recipe...
- F Food and Cooking Red Caviar: How to Choose the Best?...
- C Computers and Internet Clearing Cache: How to Speed Up Your Browser...
- S Style and Beauty How are artificial nails removed?...
- S Style and Beauty Secrets of Tying a Pareo: 5 Ways...
- F Food and Cooking Everything You Need to Know About Pasta...
Answers on questions: Biology
- B Biology if you start at sea level, perhaps along the coast, and move up or rise in elevation into the atmosphere, how does the pressure you are experiencing change? How does...
- B Biology What is the trachea function don t google and paste please...
- B Biology This model shows a human embryo. What can you determine about its development from the model? It has a postanal tail. It’s a vertebrate It has pharyngeal arches. It has...
- B Biology Who doesn t RSVP to Auggie s party...
- B Biology Me and another person r on a zoom call Join Zoom Meeting Meeting ID: 931 489 2932 Passcode: ZFb1NK...
- B Biology For the trait of color in these beetles, where brown (B) is dominant to green (g), what is the genotype ratio of the possible offspring of two heterozygous beetles?...
- B Biology All cells, whether they are bacterial cells or human cells, share two basic steps of gene expression:...
- B Biology This process of protein synthesis occurs similarly in most organisms due to the fact that it is the same universal molecule that contains the instructions for it. A....
- B Biology For the trait of color in these beetles, where brown (B) is dominant to green (g), what is the phenotype ratio of the possible offspring of two heterozygous beetles?...
- B Biology Sir isaac newton has discovered many laws, besides the laws of motion. (a) what law of nature did newton discover? (b) how did he relate his discovery to the relationship...
Ответ:
/ 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);
}
}