-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy path02-color.py
32 lines (23 loc) · 1.17 KB
/
02-color.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from nodeboxgl.graphics import *
from nodeboxgl.graphics.geometry import smoothstep
img = Image("creature.png")
def draw(canvas):
canvas.clear()
translate(250, 250)
scale(0.5)
t = canvas.frame % 100 * 0.01 # A number between 0.0 and 1.0.
t = smoothstep(0.0, 1.0, t) # Slow down ("ease") when nearing 0.0 or 1.0.
rotate(t * 360)
m = 1.0 - 2 * abs(0.5-t) # A number that goes from 0.0 to 1.0 and then back to 0.0.
scale(0.5+m)
# The image command has an optional "color" and an optional "alpha" parameter.
# The alpha sets the overall opacity of the image (alpha=0.25 means 75% transparent).
# The color adjusts the fill color of the image. By default it is (1,1,1,1),
# which means that the image pixels are mixed with white and remain unaffected.
# In this case, we lower the green component,
# so the creature gets more pink when it flies.
image(img, x=0, y=-img.height, color=color(1, 1-m, 1, 1), alpha=1.0)
# You can pass a Color object (i.e. returned from color()),
# or simply a (R,G,B)-tuple, which is faster because no Color needs to be constructed.
canvas.size = 500, 500
canvas.run(draw)