from visual import * import random import math import Numeric import povexport import string radian=57.295827908797774375395898255342 def walls(): # Build the walls of the installation room wallcolor=vector(0.1,0.1,0.1) box(pos=(-1,0,0), width=zsize, length=xsize+2, height=thickness,color=wallcolor) box(pos=(-1, ysize/2, zsize/2), width=thickness, length=xsize+2, height=ysize,color=wallcolor) box(pos=(-1, ysize/2, -zsize/2), width=thickness, length=xsize+2, height=ysize,color=wallcolor) box(pos=(xsize/2,ysize/2,0), width=zsize, length=thickness, height=ysize,color=wallcolor) def exportscene(prefix,sequence): pass ## povexport.export(filename="rendertest\\" + prefix + string.zfill(str(sequence),5) + ".pov", ## display=scene, ## #include_list=['colors.inc', 'stones.inc', 'woods.inc', 'metals.inc'] ## include_list=['colors.inc'] ## ) def randomcolor(brightness): # Return a random rgb color vector r = random.uniform(0,1) g = random.uniform(0,1-r) b = random.uniform(0,1-(r+g)) return vector(r,g,b) def pda(x,y,z,color=(0,0,0)): object = box(pos=(x,y,z),color=color,height=0.15,width=0.1, length=0.03) object.permcolor=color return object #print x,y,z def podio(x,y,z,color=(.6,.6,.6)): f=frame() #f.axis=(0,1,0) #f.pos=(x,y,z) podiumheight=1.0 toplength=.3 base = box(frame=f,pos=(x,y+podiumheight/2.0,z),color=color, height=podiumheight, width=0.3, length=0.1) top = box(frame=f,pos=(x-toplength/2.3,y+podiumheight+toplength/8,z), height=toplength, width=0.3, length=0.1,color=color) top.rotate(angle=pi/3.0, axis=(0,0,1)) return f def random_states(howmany): for xi in range(0, xpda+1): for yi in range(0, ypda+1): for zi in range(0, zpda+1): #print xi, yi, zi #rate(i) off(xi,yi,zi) for i in range(1,howmany): x=random.randrange(0,xpda+1) y=random.randrange(0,ypda+1) z=random.randrange(0,zpda+1) #pdas[x][y][z].color=colors[random.randrange(0,len(colors))] set_pda(x,y,z,random.randrange(0,2)) def state_pda(x,y,z): state = (pdas[x][y][z].color==pdas[x][y][z].permcolor) return state def set_pda(x,y,z,state): # print x,y,z if (state==1): pdas[x][y][z].color=pdas[x][y][z].permcolor else: pdas[x][y][z].color=vector(0,0,0) def on(x,y,z): pdas1[x][y][z]=1 def off(x,y,z): pdas1[x][y][z]=0 def total(): total=0 for xi in range(0, xpda+1): for yi in range(0, ypda+1): for zi in range(0, zpda+1): #print xi, yi, zi #rate(i) total+=state_pda(xi,yi,zi) return total def cycle(x,y,z): state = state_pda(x,y,z) total = 0 for xi in range(-1,2): for yi in range(-1,2): for zi in range(-1,2): xp=x+xi yp=y+yi zp=z+zi if xp > xpda or xp < 0 or yp > ypda or yp <0 or zp > zpda or zp < 0: value=0 else: value=state_pda(xp,yp,zp) total = total + value if total > 10 and state == 1: off(x,y,z) if total < 2 and state == 1: off(x,y,z) if total > 3 and total < 9 and state == 0: on(x,y,z) #print x,y,z,state,value def wobble(seconds,delta=.001,rotlimit=.1): t=0 for i in range(1,animrate*seconds): rate(animrate) t+=delta if (t<-rotlimit or t>rotlimit): delta = -delta if (scene.kb.keys): key = scene.kb.getkey() if key=='Q': print "Quitting." break scene.forward = rotate(scene.forward, angle=math.sin(t)*.01, axis=(0,1,0)) def dazzle(layer): print layer mode = 1 emotion = random.randrange(1,ypda+1) print emotion if mode ==1: for i in range(1,250): rate(200) y = random.randrange(0,ypda+1) z = random.randrange(0,zpda+1) if (y != magicy) | (z != magicz): value = (y0)) set_pda(layer,y,z,value) elif mode ==2: pass for i in range(0,6): rate(1) print i for y in range(0,ypda+1): for z in range(0,zpda+1): set_pda(layer,y,z,0) zoomin=1 bridge=1 cellular=1 attract=1 box(pos=(0,0,0),width=.01, lenght=.01, height=.01) for i in scene.objects: i.visible=0 #sphere(pos=(0,0,0),radius=1,color=color.blue) scene.autocenter=1 scene.center=vector(0,-1,0) scene.scale=[0.1, 0.1, 0.1] scene.lights=[vector(-1,-0.1,-0.1)] scene.ambient=0.9 scene.background=vector(.2,.2,.2) ##scene.width=800 ##scene.height=600 xsize = 8.0 ysize = 6.0 zsize = 4.8 thickness= 0.1 # Which is the active pda row? magicy = 1 magicz = 3 dt = .01 rotlimit = .1 delta = .001 sequence = 0 fudge = .30 xpda = 4 zpda = 3 ypda = 3 pdas = Numeric.array([0],PyObject) pdas = Numeric.resize(pdas,(xpda+1,ypda+1,zpda+1)) pdas1 = Numeric.array([0],Int) pdas1 = Numeric.resize(pdas,(xpda+1,ypda+1,zpda+1)) i =1 xstep = (xsize-fudge*2)/(xpda) zstep = (zsize-fudge*2)/(zpda) ystep = (ysize-fudge*2)/(ypda) print "Xstep", xstep print "Zstep", zstep for xi in range(0, xpda+1): for yi in range(0, ypda+1): for zi in range(0, zpda+1): #print xi, yi, zi #rate(i) i +=1 localcolor=(1-(xi/9.0),xi/13.0,.1) ## if (yi == magicy) & (zi == magicz): ## localcolor = vector(1,1,1) object=pda(x= -xsize/2+fudge+xstep*xi, y= fudge+ystep*yi, z= -zsize/2+fudge+zstep*zi, color=localcolor) object.xi=xi object.yi=yi object.zi=zi pdas[xi][yi][zi]=object set_pda(xi,yi,zi,1) #wobble(10) walls() ##podii=( ## ( 3.3,0.0, 0.6, -30), #1 ## ( 1.4,0.0,-1.4, 45), ## ( 0.1,0.0, 1.9, -60), ## (-3.0,0.0,-1.5, 150), ## (-2.1,0.0, 1.8,-120), ## (-4.1,0.0, 0.0, 170) ## ) ## ## ##for i in podii: ## print i ## ilpodio=podio(i[0],i[1],i[2]) ## ilpodio.rotate(angle=i[3]/radian,axis=(0,1,0),origin=(i[0],0,i[2])) podii=( ( 3.3,0.0, 0.6, -30), #1 ( 1.4,0.0,-1.4, 45), ( 0.1,0.0, 1.9, -60), (-3.0,0.0,-1.5, 150), (-2.1,0.0, 1.8,-120), (-4.1,0.0, 0.0, 170) ) podii = 6 interval = 360/podii angle = 15 xoffset = 1 for i in range(1,podii+1): x=((xsize/2.0)-fudge*2.5+xoffset)*cos(angle/radian)-xoffset z=((zsize/2.0)-fudge*2.5)*sin(angle/radian) print i,angle,x,z ilpodio=podio(x,0,z) ilpodio.rotate(angle=-angle/radian,axis=(0,1,0),origin=(x,0,z)) angle += interval ##for x in range(-5,6): ## for y in range(0,2): ## for z in range(-5,6): ## s=sphere(pos=(x,y,z),radius=0.02,color=(1,1,0)) ## if (x==0): ## s.color = (1,0,0) t=1 pick=0 # An unvalid value while(1): rate(30) for x in range(0,xpda+1): set_pda(x,magicy,magicz,1) t+=delta if (t>100): t=-100 #print t if (scene.kb.keys): key = scene.kb.getkey() if key=='Q': print "Quitting." break if key=="a": scene.forward+=vector(0,.1,0) elif key=="z": scene.forward+=vector(0,-.1,0) if key=="1": ncolor=(1,1,0) elif key=="2": ncolor=(0,0.8,0) elif key=="3": ncolor=(.2,.2,1) elif key=="4": ncolor=(1,.2,.2) print scene.center print scene.forward ## scene.forward = rotate(scene.forward, ## angle=math.sin(t/1000.0)*0.2, ## axis=(0,1,0) ## ) ## oldpick = pick pick=scene.mouse.pick if oldpick != pick and oldpick != 0 and hasattr(oldpick,"permcolor"): if scene.mouse.clicked: print pick.xi, pick.yi, pick.zi pick.color=ncolor event = scene.mouse.getclick() if (pick.yi==magicy) and (pick.zi==magicz): # This means we are in some of the controlling PDAs dazzle(pick.xi) # Clean up scene for i in scene.objects: i.visible=0