add precision
This commit is contained in:
parent
97201be02f
commit
9d0f51bad4
12
waves.py
12
waves.py
@ -17,6 +17,8 @@ AMPLITUDE = 25
|
||||
MONOCHROME = True
|
||||
# background black? White otherwise:
|
||||
DARK_BG = True
|
||||
# precision of the calculation
|
||||
PRECISION = 10000
|
||||
|
||||
def main():
|
||||
|
||||
@ -26,7 +28,9 @@ def main():
|
||||
ctx.scale(WIDTH, HEIGHT) # Normalizing the canvas
|
||||
|
||||
wave_height = 1/WAVES
|
||||
lastpoints = [(x/1000, 0) for x in range(1000)]
|
||||
step_size = 1/PRECISION
|
||||
|
||||
lastpoints = [(x/PRECISION, 0) for x in range(PRECISION+1)]
|
||||
if DARK_BG:
|
||||
# make bg black
|
||||
ctx.rectangle(0, 0, 1, 1)
|
||||
@ -45,7 +49,8 @@ def main():
|
||||
while x < 1:
|
||||
y = math.sin(x*AMPLITUDE + (num * WAVE_OFFSET) ) * 0.1
|
||||
points.append((x, ( (y/4) + ((0.5+num)*wave_height))))
|
||||
x += 0.001
|
||||
x += step_size
|
||||
print(f'Draw {len(points)} points for curve {num}')
|
||||
if not MONOCHROME:
|
||||
ctx.set_source_rgb(r, g, b)
|
||||
else:
|
||||
@ -54,9 +59,10 @@ def main():
|
||||
ctx.move_to(*points[0])
|
||||
for p in points[1:]:
|
||||
ctx.line_to(*p)
|
||||
ctx.set_line_width(0.002)
|
||||
ctx.set_line_width(step_size) #0.002)
|
||||
ctx.stroke()
|
||||
# fill area above
|
||||
ctx.set_line_width(step_size)
|
||||
for pos in range(len(points)):
|
||||
ctx.move_to(*points[pos])
|
||||
ctx.line_to(*lastpoints[pos])
|
||||
|
Loading…
Reference in New Issue
Block a user