sketch-a-day/sketch_180121b/sketch_180121b.pyde

49 wiersze
1.4 KiB
Plaintext
Czysty Zwykły widok Historia

2018-01-21 01:37:23 +00:00
"""
s18020b - Alexandre B A Villares
https://abav.lugaralgum.com/sketch-a-day
Slider code by Peter Farell (older version tweeked by me)
https://github.com/hackingmath/python-sliders
2018-01-21 01:37:23 +00:00
"""
2018-01-21 23:54:47 +00:00
from __future__ import division
from slider import Slider
r1 = Slider(0,500,100)
r2 = Slider(0,500,200)
np = Slider(3,50,10)
2018-01-21 01:37:23 +00:00
def setup():
2018-01-22 00:29:53 +00:00
size(500, 500, P2D) # P2D necessary! I'm changing fill() inside Shape
2018-01-21 23:54:47 +00:00
colorMode(HSB)
2018-01-21 01:37:23 +00:00
background(0)
2018-01-21 23:54:47 +00:00
r1.position(20, 20)
r2.position(20, 60)
np.position(20, 100)
2018-01-21 01:37:23 +00:00
def draw():
background(0)
2018-01-22 00:24:50 +00:00
npoints, rad1, rad2 = np.val, r1.val, r2.val # I wanted to draw the star before the sliders
2018-01-21 23:54:47 +00:00
with pushMatrix():
translate(width / 2, height / 2)
angle = TWO_PI / npoints
h_angle = angle / 2.
beginShape()
#vertex(0, 0)
a = 0
while a < TWO_PI:
sx = cos(a) * rad2
sy = sin(a) * rad2
cor = map(a, 0, TWO_PI, 0, 255)
2018-01-22 00:29:53 +00:00
fill(cor, 255, 255) # only works on P2D & P3D renderers
2018-01-21 23:54:47 +00:00
vertex(sx, sy)
sx = cos(a + h_angle) * rad1
sy = sin(a + h_angle) * rad1
fill(cor, 255, 255)
vertex(sx, sy)
a += angle
endShape(CLOSE)
2018-01-22 00:29:53 +00:00
npoints, rad1, rad2 = np.value(), r1.value(), r2.value() # usual way to get values & draw the sliders
# if not frameCount % 10 and frameCount < 500: # used to make a GIF on Gimp
# saveFrame("###.tga")