Commit 7529b611 authored by Raoul's avatar Raoul Committed by Daniel Willmann

Updates to dodecahedra code

parent 2bef2437
......@@ -2,11 +2,9 @@
# Raoul, Hackover 2014, GPL v2
import client
import time
import random
from numpy import sin, cos, pi, array, sqrt, clip, linspace, dot
from numpy import sin, cos, pi, array, clip, linspace, dot
from numpy.linalg import norm
from numpy import random
from copy import deepcopy
CENX = client.WIDTH / 2.0
CENY = client.HEIGHT / 2.0
......@@ -17,7 +15,7 @@ xmin = sigma * B - 2
ymin = tau * B
xmax = client.WIDTH - sigma * B
ymax = client.HEIGHT - tau * B - 2
NT = 10
NT = 12
def cube(a=10):
vert = [(-a, -a, -a),
......@@ -83,6 +81,7 @@ def dode(a=15):
#
return a*array(vert)
edge_map_dode = [(3, 14),
(2, 14),
(6, 12),
......@@ -116,25 +115,24 @@ edge_map_dode = [(3, 14),
def rotatex(vertl, phi = pi/3):
Rx = array([[1, 0, 0],
[0, cos(phi), sin(phi)],
Rx = array([[1, 0, 0],
[0, cos(phi), sin(phi)],
[0, -sin(phi), cos(phi)]])
vertl_t = dot(Rx, vertl.T).T
return vertl_t
return dot(Rx, vertl.T).T
def rotatey(vertl, phi = pi/3):
Ry = array([[cos(phi), 0, sin(phi)],
[0, 1, 0],
Ry = array([[ cos(phi), 0, sin(phi)],
[ 0, 1, 0],
[-sin(phi), 0, cos(phi)]])
vertl_t = dot(Ry, vertl.T).T
return vertl_t
return dot(Ry, vertl.T).T
def rotatez(vertl, phi = pi/3):
Rz = array([[cos(phi), sin(phi), 0],
Rz = array([[ cos(phi), sin(phi), 0],
[-sin(phi), cos(phi), 0],
[0, 0, 1]])
vertl_t = dot(Rz, vertl.T).T
return vertl_t
[ 0, 0, 1]])
return dot(Rz, vertl.T).T
def propagate(x, v):
......@@ -172,28 +170,24 @@ def line(u, v):
t = linspace(0, 1, NT)
lx = u[0] + xd*t
ly = u[1] + yd*t
lx = lx.round()
ly = ly.round()
return lx, ly
return lx.round(), ly.round()
def show(vl, el, col=255):
def show(vl, el):
pixels = []
pixelso = []
for i, e in enumerate(el):
u = e[0]
v = e[1]
lx, ly = line(vl[u], vl[v])
pixelsold = []
for e in el:
lx, ly = line(vl[e[0]], vl[e[1]])
for lxi, lyi in zip(lx, ly):
pixels.append( (lxi, lyi, col) )
pixelso.append( (lxi, lyi, 0) )
pixels.append( (lxi, lyi, 255) )
pixelsold.append( (lxi, lyi, 0) )
return pixels, pixelso
return pixels, pixelsold
def clear():
pixels = [0] * client.HEIGHT * client.WIDTH
client.blit(0,0,client.WIDTH,client.HEIGHT,pixels)
client.blit(0, 0, client.WIDTH, client.HEIGHT, pixels)
if __name__=="__main__":
......@@ -205,7 +199,9 @@ if __name__=="__main__":
c1 = dode(16)
c2 = dode(16)
m = edge_map_dode
m += [(mi[0] + 20, mi[1]+20) for mi in m]
offset = len(c1)
m += [(mi[0]+offset, mi[1]+offset) for mi in m]
c1 = rotatez(c1, pi/4.0)
c1 = rotatex(c1, pi/3.0)
......@@ -217,10 +213,9 @@ if __name__=="__main__":
r2y = -pi/30
r2z = -pi/50
pixo = []
clear()
ti = 0
pixold = []
clear()
while(True):
c1 = rotatey(c1, r1y)
c1 = rotatez(c1, r1z)
......@@ -230,27 +225,27 @@ if __name__=="__main__":
propagate(x1, v1)
propagate(x2, v2)
n = x1-x2
if(norm(n)) < 54:
n = x1 - x2
if norm(n) < 54:
v1, v2 = reflect(v1, v2, n/norm(n))
ry = clip(2*random.uniform(), -1.25, 1.25)
rz = clip(2*random.uniform(), -1.25, 1.25)
r1y = clip(r1y*ry, -0.18, 0.18)
r1z = clip(r1z*rz, -0.18, 0.18)
r2y = clip(r2y*ry, -0.18, 0.18)
r2z = clip(r2z*rz, -0.18, 0.18)
ry = clip(2*random.uniform(), -1.5, 1.5)
rz = clip(2*random.uniform(), -1.5, 1.5)
r1y = clip(r1y*ry, -0.28, 0.28)
r1z = clip(r1z*rz, -0.28, 0.28)
r2y = clip(r2y*ry, -0.28, 0.28)
r2z = clip(r2z*rz, -0.28, 0.28)
cc1 = project(move(c1, x1))
cc2 = project(move(c2, x2))
pix, pixoo = show(cc1+cc2, m)
client.set_pixels(pixo + pix)
pixo = pixoo
pix, pixoldn = show(cc1+cc2, m)
client.set_pixels(pixold+pix)
pixold = pixoldn
ti += 1
if ti > 2000:
pixo = []
ti = 0
pixold = []
x1 = array([CENX-100, CENY, 0])
v1 = array([1.5, 0.75, 0])
x2 = array([CENX+100, CENY, 0])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment