Does the below program use recursion to create a sierpinski triangle? Souce code: package application; public class Triangle { publicstaticvoid main(String [] args) { TriangleFrame tf = new TriangleFrame(); } } package application; import java.awt.*; import javax.swing.*; public class SierpinskiGasket extends JPanel { public SierpinskiGasket() { } public void drawTriangle (Graphics g, int x, int y, int width, int height) { if (height == 1) { g.drawRect(x, y, width, height); } else { drawTriangle(g, x + (width / 4), y, width / 2, height / 2); drawTriangle(g, x, y + (height / 2), width / 2, height / 2); drawTriangle(g, x + (width / 2), y + (height / 2), width/ 2, height / 2); } } public void paintComponent (Graphics g) { super.paintComponent(g); drawTriangle(g, 0, 0, this.getWidth(), this.getHeight()); } }
Does the below program use recursion to create a sierpinski triangle?
Souce code:
package application;
public class Triangle {
publicstaticvoid main(String [] args) {
TriangleFrame tf = new TriangleFrame();
}
}
package application;
import java.awt.*;
import javax.swing.*;
public class SierpinskiGasket extends JPanel {
public SierpinskiGasket() {
}
public void drawTriangle (Graphics g, int x, int y, int width, int height) {
if (height == 1) {
g.drawRect(x, y, width, height);
}
else {
drawTriangle(g, x + (width / 4), y, width / 2, height / 2);
drawTriangle(g, x, y + (height / 2), width / 2, height / 2);
drawTriangle(g, x + (width / 2), y + (height / 2), width/ 2, height / 2);
}
}
public void paintComponent (Graphics g) {
super.paintComponent(g);
drawTriangle(g, 0, 0, this.getWidth(), this.getHeight());
}
}
![](/static/compass_v2/shared-icons/check-mark.png)
The Sierpinski triangle is a well-known fractal pattern that can be created by recursively subdividing an equilateral triangle into smaller equilateral triangles. It exhibits self-similar and intricate geometric properties.
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)