MCPcopy Create free account
hub / github.com/ActiveState/code / frCurve

Function frCurve

recipes/Python/577783_Random_fractal_curve/recipe-577783.py:11–24  ·  view source on GitHub ↗
(xa, ya, xb, yb)

Source from the content-addressed store, hash-verified

9c = random.random()
10
11def frCurve(xa, ya, xb, yb):
12 dx = xb - xa
13 dy = yb - ya
14 d = math.hypot(dx, dy)
15 if d <= 1:
16 if xa >= 0 and xa < imgx and ya >=0 and ya < imgy:
17 image.putpixel((xa, ya), (0, 255, 0))
18 if xb >= 0 and xb < imgx and yb >=0 and yb < imgy:
19 image.putpixel((xb, yb), (0, 255, 0))
20 return
21 xm = xa + dx * c
22 ym = ya + dy * c + math.copysign(dx * c, random.random() - 0.5)
23 frCurve(xa, ya, xm, ym)
24 frCurve(xm, ym, xb, yb)
25
26# main
27frCurve(0, (imgy - 1) / 2, imgx - 1, (imgy - 1) / 2)

Callers 1

recipe-577783.pyFile · 0.85

Calls 3

hypotMethod · 0.45
putpixelMethod · 0.45
randomMethod · 0.45

Tested by

no test coverage detected