Brownian tree: Difference between revisions
Content added Content deleted
(→{{header|Processing}}: It is not very Processing-like to have a long wait and draw a single frame of draw()... so now you see the tree growing (slowly).) |
(→{{header|Processing}}: adding Processing Python mode) |
||
Line 2,955: | Line 2,955: | ||
if (frameCount > width * height) noLoop(); |
if (frameCount > width * height) noLoop(); |
||
}</lang> |
}</lang> |
||
==={{header|Processing Python mode}}=== |
|||
{{trans|Processing}} |
|||
<lang python>SIDESTICK = False |
|||
def setup() : |
|||
global is_taken |
|||
size(512, 512) |
|||
background(0) |
|||
is_taken = [[False] * height for _ in range(width)] |
|||
is_taken[width/2][height/2] = True |
|||
def draw() : |
|||
x = floor(random(width)) |
|||
y = floor(random(height)) |
|||
if is_taken[x][y]: |
|||
return |
|||
while True: |
|||
xp = x + floor(random(-1, 2)) |
|||
yp = y + floor(random(-1, 2)) |
|||
is_contained = 0 <= xp < width and 0 <= yp < height |
|||
if is_contained and not is_taken[xp][yp]: |
|||
x = xp |
|||
y = yp |
|||
continue |
|||
else: |
|||
if SIDESTICK or (is_contained and is_taken[xp][yp]): |
|||
is_taken[x][y] = True |
|||
set(x, y, color(255)) |
|||
break |
|||
if frameCount > width * height: |
|||
noLoop()</lang> |
|||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |