1 |
|
from math import sin,cos,sqrt,pi |
2 |
|
|
3 |
ripple_scale = .25 |
ripple_scale = .25 |
4 |
|
|
5 |
args = ["radius", "2", str(ripple_scale), "0.25", |
args = ["radius", "2", str(ripple_scale), "0.25", |
12 |
["invert", "1"]) |
["invert", "1"]) |
13 |
|
|
14 |
|
|
15 |
|
# alpha(y) = e / y * f >= e |
16 |
|
# y <= f |
17 |
|
|
18 |
|
|
19 |
|
def lerp(a, b, f): |
20 |
|
return [ (1-f) * a[i] + f * b[i] for i in range(0, len(a)) ] |
21 |
|
|
22 |
|
def getirr(texid, angle, pos): |
23 |
|
|
24 |
# alpha(y) = e / y * f >= e |
texmat = js([ |
25 |
# y <= f |
cos(angle), sin(angle), 0, 0, |
26 |
|
-sin(angle), cos(angle), 0, 0, |
27 |
|
0, 0, 1, 0, |
28 |
|
sin(angle)*pos, cos(angle)*pos, 0, 1, |
29 |
|
]) |
30 |
|
|
31 |
|
col0l = [ (1.0,0.5,0.5), (0.5,0.5,1.0), (0.5,1.0,0.5), (1.0,0.5,0.5) ] |
32 |
|
col1l = [ (.75,0.5,0.5), (0.5,0.5,.75), (0.5,.75,0.5), (.75,0.5,0.5) ] |
33 |
|
|
34 |
|
a = angle * 6 / (2 * pi) |
35 |
|
while a < 0: a+=3 |
36 |
|
i = int(a) % 3 |
37 |
|
f = a - int(a) |
38 |
|
|
39 |
|
col0 = js(lerp(col0l[i], col0l[i+1], f)) |
40 |
|
col1 = js(lerp(col1l[i], col1l[i+1], f)) |
41 |
|
|
42 |
|
#print col0, col1 |
43 |
|
|
|
def getirr(texid): |
|
44 |
e = 0.5 |
e = 0.5 |
45 |
return getDList(""" |
return getDList(""" |
46 |
PushAttrib ENABLE_BIT |
PushAttrib ENABLE_BIT |
107 |
#TexEnv TEXTURE_ENV OPERAND1_ALPHA_ARB SRC_ALPHA |
#TexEnv TEXTURE_ENV OPERAND1_ALPHA_ARB SRC_ALPHA |
108 |
|
|
109 |
MatrixMode TEXTURE |
MatrixMode TEXTURE |
110 |
LoadMatrix 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 |
LoadMatrix %(texmat)s |
111 |
MatrixMode MODELVIEW |
MatrixMode MODELVIEW |
112 |
|
|
113 |
Begin QUAD_STRIP |
Begin QUAD_STRIP |
114 |
|
|
115 |
TexCoord 0 0 0 1 |
TexCoord 0 0 0 1 |
116 |
Color 1 .5 .5 |
Color %(col0)s |
117 |
Vertex 0 %(e)s 0 1 |
Vertex 0 %(e)s 0 1 |
118 |
|
|
119 |
TexCoord 0 0 0 %(e)s |
TexCoord 0 0 0 %(e)s |
120 |
Color .75 .5 .5 |
Color %(col1)s |
121 |
Vertex 0 %(e)s 0 %(e)s |
Vertex 0 %(e)s 0 %(e)s |
122 |
|
|
123 |
TexCoord 1 0 0 1 |
TexCoord 1 0 0 1 |
124 |
Color 1 .5 .5 |
Color %(col0)s |
125 |
Vertex 1 %(e)s 0 1 |
Vertex 1 %(e)s 0 1 |
126 |
|
|
127 |
TexCoord %(e)s 0 0 %(e)s |
TexCoord %(e)s 0 0 %(e)s |
128 |
Color .75 .5 .5 |
Color %(col1)s |
129 |
Vertex %(e)s %(e)s 0 %(e)s |
Vertex %(e)s %(e)s 0 %(e)s |
130 |
|
|
131 |
End |
End |
187 |
""" % vars()) |
""" % vars()) |
188 |
|
|
189 |
|
|
|
irr = getirr(tex.getTexId()) |
|
|
irrinv = getirr(texinv.getTexId()) |
|
|
|
|
190 |
|
|
191 |
|
|
192 |
|
|
199 |
def __init__(self): |
def __init__(self): |
200 |
self.scale = 128 |
self.scale = 128 |
201 |
self.dist = 1 |
self.dist = 1 |
202 |
|
self.angle = 0 |
203 |
|
self.pos = 0 |
204 |
|
|
205 |
def scene(self, vs): |
def scene(self, vs): |
206 |
putnoc(vs, background((0.7,0.7,1.0))) |
putnoc(vs, background((0.7,0.7,1.0))) |
210 |
vs.matcher.add(cs1, "1") |
vs.matcher.add(cs1, "1") |
211 |
vs.matcher.add(cs2, "2") |
vs.matcher.add(cs2, "2") |
212 |
|
|
213 |
|
irr = getirr(tex.getTexId(), self.angle, self.pos) |
214 |
|
irrinv = getirr(texinv.getTexId(), self.angle, self.pos) |
215 |
|
|
216 |
vs.map.put(irr, cs1) |
vs.map.put(irr, cs1) |
217 |
vs.map.put(irrinv, cs2) |
vs.map.put(irrinv, cs2) |
218 |
|
|
219 |
def key(self, k): |
def key(self, k): |
220 |
if k == "+": self.scale *= 1.4142135623731; print round(self.scale) |
if k == "+": self.scale *= 1.4142135623731; print round(self.scale) |
221 |
if k == "-": self.scale /= 1.4142135623731; print round(self.scale) |
if k == "-": self.scale /= 1.4142135623731; print round(self.scale) |
222 |
if k == "Up": self.dist *= 1.1 |
if k == "Prior": self.dist *= 1.1 |
223 |
if k == "Down": self.dist /= 1.1 |
if k == "Next": self.dist /= 1.1 |
224 |
|
if k == "Up": self.pos -= 1./128 |
225 |
|
if k == "Down": self.pos += 1./128 |
226 |
|
if k == "Left": self.angle -= pi/180 |
227 |
|
if k == "Right": self.angle += pi/180 |
228 |
|
print "angle",round(self.angle / pi * 180) |
229 |
|
|
230 |
currentScene = IrreguScene() |
currentScene = IrreguScene() |