Anonymous user
Fractal tree: Difference between revisions
no edit summary
SqrtNegInf (talk | contribs) m (→{{header|F_Sharp|F#}}: Fix link: Perl 6 --> Raku) |
No edit summary |
||
Line 2,106:
EndIf
Repeat: Until WaitWindowEvent(
[[Image:PB_FractalTree.png]]
=={{header|Python}}==
=== Java mode ===
<lang java>void setup() {
size(600, 600);
background(0);
stroke(255);
drawTree(300, 550, -90, 9);
}
void drawTree(float x1, float y1, float angle, int depth) {
if (depth > 0) {
float x2 = x1 + cos(radians(angle)) * depth * 10.0;
float y2 = y1 + sin(radians(angle)) * depth * 10.0;
line(x1, y1, x2, y2);
drawTree(x2, y2, angle - 20, depth - 1);
drawTree(x2, y2, angle + 20, depth - 1);
}
}</lang>
=== Python mode ===
<lang python>def setup():
size(600, 600)
background(0)
stroke(255)
drawTree(300, 550, -90, 9)
def drawTree(x1, y1, angle, depth):
if depth > 0:
x2 = x1 + cos(radians(angle)) * depth * 10.0
y2 = y1 + sin(radians(angle)) * depth * 10.0
line(x1, y1, x2, y2)
drawTree(x2, y2, angle - 20, depth - 1)
drawTree(x2, y2, angle + 20, depth - 1)</lang>
=={{header|Python}}==
Line 2,120 ⟶ 2,154:
def drawTree(x1, y1, angle, depth):
if depth > 0:
x2 = x1 + int(math.cos(math.radians(angle)) * depth * 10.0)
y2 = y1 + int(math.sin(math.radians(angle)) * depth * 10.0)
|