hund.py.py
hund.py.py — text/python-source, 11 KB (12004 bytes)
Dateiinhalt
from visual import * from time import * import Image from math import * name="himmel" width = 2048 height = 1024 im = Image.open(name+".tga") materials.saveTGA(name, im) pano = materials.texture(data=im, mapping="spherical", interpolate=False) name2 = "fell" im2 = Image.open(name2+".tga") materials.saveTGA(name2, im2) fell = materials.texture(data=im2, mapping="rectangular", interpolate=False) name3 = "gras" im3 = Image.open(name3+".tga") materials.saveTGA(name3, im3) gras = materials.texture(data=im3, mapping="rectangular", interpolate=False) rasen= box(pos=(0,-3,0), length=1500, width=1500, height=3, material=gras) name4="ziel" im4= Image.open(name4+".tga") materials.saveTGA(name4, im4) ziel=materials.texture(data=im4, mapping="sign", interpolate=False) name5="wald" im5= Image.open(name5+".tga") materials.saveTGA(name5, im5) wald= materials.texture(data=im5, mapping="rectangular", interpolate=False) scene.lights = [distant_light(direction=( 10, 10, 10), color=color.gray(0.5)),\ distant_light(direction=(-10, 10, 10), color=color.gray(0.5)),\ distant_light(direction=( 10,-10, 10), color=color.gray(0.5)),\ distant_light(direction=( 10, 10,-10), color=color.gray(0.5)),\ distant_light(direction=(-10,-10, 10), color=color.gray(0.5)),\ distant_light(direction=( 10,-10,-10), color=color.gray(0.5)),\ distant_light(direction=(-10, 10,-10), color=color.gray(0.5)),\ distant_light(direction=(-10,-10,-10), color=color.gray(0.5))] scene.userzoom = False scene.autoscale = False scene.fov = pi/2 scene.range = 45 scene.background=(0,0,0.6) ellipsoid(pos=(0,14,0), width=1000, length=1000, height=100, material=pano) class Hund(object): def __init__(self): self.hund=frame() self.schwanz = helix(frame=self.hund,\ pos=(19,8,0),\ radius=1,\ length=8,\ thickness=0.3,\ axis=(1,0.5,0), color=(0.3,0.2,0.1)) self.hinterteil = sphere(frame=self.hund,\ pos=(17,5,0),\ radius=5.02, material=fell) bauch = cylinder(frame=self.hund,\ pos=(0,5,0),\ radius=5,\ length=18, material=fell) bein1 = sphere(frame=self.hund,\ pos=(1,-1,3),\ radius=2.5, material=fell) bein2 = sphere(frame=self.hund,\ pos=(1,-1,-3),\ radius=2.5, material=fell) bein3 = sphere(frame=self.hund,\ pos=(17,-1,-3),\ radius=2.5, material=fell) bein4 = sphere(frame=self.hund,\ pos=(17,-1,3),\ radius=2.5, material=fell) vorderteil = sphere(frame=self.hund,\ pos=(1,5,0),\ radius=5.02, material=fell) hals = cylinder(frame=self.hund,\ pos=(-4,9,0),\ axis=(1,-1.2,0),\ length=5,\ radius=3, material=fell) kopf = ellipsoid(frame=self.hund,\ pos=(-7.5,10.5,0),\ length=12,\ height=7,\ width=8, material=fell) nase = sphere(frame=self.hund,\ pos=(-13.1,10.5,0),\ radius=0.4,\ color=color.red) augapfell = sphere(frame=self.hund,\ pos=(-10.5,12.5,2),\ radius=0.6,\ color=color.yellow) augapfelr = sphere(frame=self.hund,\ pos=(-10.5,12.5,-2),\ radius=0.6,\ color=color.yellow) augel = sphere(frame=self.hund,\ pos=(-10.65,12.7,-2.1),\ radius=0.4,\ color=(0,0,0)) auger = sphere(frame=self.hund,\ pos=(-10.65,12.7,2.1),\ radius=0.4,\ color=(0,0,0)) ohrl = ellipsoid(frame=self.hund,\ pos=(-6,11,3.8),\ length=5,\ height=0.1,\ width=3.5,\ axis=(0.3,-1.5,1), material=fell) ohrr = ellipsoid(frame=self.hund,\ pos=(-6,11,-3.8),\ length=5,\ height=0.1,\ width=3.5,\ axis=(-0.3,1.5,1), material=fell) hut = cylinder(frame=self.hund,\ pos=(-5,13,0),\ axis=(0.3,1,0),\ radius=3,\ length=6,\ color=(0,0,0)) hutkrempe = cylinder(frame=self.hund,\ pos=(-5,13,0),\ axis=(0.3,1,0),\ radius=5,\ length=0.2,\ color=(0,0,0)) def aktion(self): k=ellipsoid(pos=(self.hund.pos.x+22,self.hund.pos.y+5, self.hund.pos.z), axis=(0,1,0), color=(0.3,0.2,0.1), length=3) for i in range(90): k.pos.y = k.pos.y - 0.04 sleep(0.006) for i in xrange(5): self.schwanz.length= self.schwanz.length - 0.1 sleep(0.006) k.pos.y = k.pos.y - 0.04 for i in xrange(5): self.schwanz.length = self.schwanz.length +0.1 sleep(0.006) def aktion2(self): k2=ellipsoid(pos=(self.hund.pos.x+22,self.hund.pos.y+5, self.hund.pos.z), axis=(0,1,0), color=(0.3,0.2,0.1), length=3) for i in range(90): k2.pos.y = k2.pos.y - 0.033 sleep(0.006) for i in xrange(5): self.schwanz.length= self.schwanz.length - 0.1 sleep(0.006) k2.pos.y = k2.pos.y - 0.033 for i in xrange(5): self.schwanz.length = self.schwanz.length +0.1 sleep(0.006) stamm=cylinder(radius=3.5, pos=(230, -3, -20), axis=(0,6.5,0), length=30,color=(0.5,0.25,0.1)) laub=sphere(radius=10, pos=(230,27,-20), color=(0.1,0.5,0.1)) stamm2=cylinder(radius=3.5, pos=(100, -3, 20), axis=(0,6.5,0), length=30,color=(0.5,0.25,0.1)) laub2=sphere(radius=10, pos=(100,27,20), color=(0.1,0.5,0.1)) stamm3=cylinder(radius=3.5, pos=(-100, -3, -30), axis=(0,6.5,0), length=30,color=(0.5,0.25,0.1)) laub3=sphere(radius=10, pos=(-100,27,-30), color=(0.1,0.5,0.1)) stange=cylinder(length=25,radius=1, pos=(200, 0, -15), axis=(0,9,0), color=(0.3,0.3,0.3)) lampe=sphere(radius=4,pos=(200,28,-15),opacity=0.7, color=color.yellow) ring=ring(radius=1,thickness=1,axis=(0,1,0),pos=(200,10,-15),color=(0.3,0.3,0.3)) basis=cone(radius=4, pos=(200,-1,-15), axis=(0,3,0), color=(0.3,0.3,0.3)) stange2=cylinder(length=25,radius=1, pos=(-80, 0, 15), axis=(0,9,0), color=(0.3,0.3,0.3)) lampe2=sphere(radius=4,pos=(-80,28,15),opacity=0.7, color=color.yellow) basis2=cone(radius=4, pos=(-80,-1,15), axis=(0,3,0), color=(0.3,0.3,0.3)) z1 = cylinder(pos=(-140,0,-25), length=25, radius=0.8, axis=(0,1,0), color=color.blue) z2 = cylinder(pos=(-140,0,25), length=25, radius=0.8, axis=(0,1,0), color=color.blue) z3 = box(pos=(-140, 25, 0), length=1, width=50, height=8, material=ziel) w= box(pos=(0, 20,-60), length=800, width=1, height=40, material=wald) w2= box(pos=(0, 20,60), length=800, width=1, height=40, material=wald) a=box(pos=(-118,-1.5,0), length=0.25, width=2, height=0.5, color=color.red) b=box(pos=(100,-1.5,0), length=0.5, width=2, height=0.5, color=color.red) c=box(pos=(-70,-1.5,0), length=1, width=2, height=0.5, color=color.red) d=box(pos=(0,-1.5,0), length=2, width=2, height=0.5, color=color.red) e=box(pos=(40,-1.5,0), length=3, width=2, height=0.5, color=color.red) f=box(pos=(100,-1.5,0), length=4, width=2, height=0.5, color=color.red) g=box(pos=(130,-1.5,0), length=5, width=2, height=0.5, color=color.red) i=box(pos=(150,-1.5,0), length=6, width=2, height=0.5, color=color.red) j=box(pos=(200,-1.5,0), length=7, width=2, height=0.5, color=color.red) l=box(pos=(230,-1.5,0), length=8, width=2, height=0.5, color=color.red) punktzahl=0 h = Hund() h.hund.pos=(250,0,0) anzeige = label(pos=(250,10,10), text="Punktzahl", \ box=False, line=False, height=10) scene.center = h.hund.pos scene.forward =vector(-h.hund.axis.x, -0.5,h.hund.axis.z) while True: rate(50) if scene.kb.keys: p = scene.kb.getkey() if p =="w": scene.center.x = scene.center.x+scene.forward.x h.hund.pos.x = h.hund.pos.x +scene.forward.x anzeige.pos.x = anzeige.pos.x + scene.forward.x if p =="s": scene.center.x = scene.center.x-scene.forward.x h.hund.pos.x = h.hund.pos.x-scene.forward.x anzeige.pos.x = anzeige.pos.x - scene.forward.x if p ==" ": h.aktion() h.aktion2() if (h.hund.pos.x +22) - l.pos.x <= 4: if (h.hund.pos.x +22) -l.pos.x >= -4: punktzahl = punktzahl + 10 anzeige.text="Punkte: "+str(punktzahl) else: pass if (h.hund.pos.x +22) - j.pos.x <= 3.5: if (h.hund.pos.x +22) -j.pos.x >= -3.5: punktzahl = punktzahl + 12 anzeige.text="Punkte: "+str(punktzahl) else: pass if (h.hund.pos.x +22) - i.pos.x <= 3: if (h.hund.pos.x +22) -i.pos.x >= -3: punktzahl = punktzahl + 14 anzeige.text="Punkte: "+str(punktzahl) else: pass if (h.hund.pos.x +22) - g.pos.x <= 2.5: if (h.hund.pos.x +22) -g.pos.x >= -2.5: punktzahl = punktzahl + 16 anzeige.text="Punkte: "+str(punktzahl) else: pass if (h.hund.pos.x +22) - f.pos.x <= 2: if (h.hund.pos.x +22) -f.pos.x >= -2: punktzahl = punktzahl + 18 anzeige.text="Punkte: "+str(punktzahl) else: pass if (h.hund.pos.x +22) - e.pos.x <= 1.5: if (h.hund.pos.x +22) -e.pos.x >= -1.5: punktzahl = punktzahl + 20 anzeige.text="Punkte: "+str(punktzahl) else: pass if (h.hund.pos.x +22) - d.pos.x <= 1: if (h.hund.pos.x +22) -d.pos.x >= -1: punktzahl = punktzahl + 25 anzeige.text="Punkte: "+str(punktzahl) else: pass if (h.hund.pos.x +22) - c.pos.x <= 0.5: if (h.hund.pos.x +22) -c.pos.x >= -0.5: punktzahl = punktzahl + 30 anzeige.text="Punkte: "+str(punktzahl) else: pass if (h.hund.pos.x +22) - b.pos.x <= 0.25: if (h.hund.pos.x +22) -b.pos.x >= -0.25: punktzahl = punktzahl + 40 anzeige.text="Punkte: "+str(punktzahl) else: pass if (h.hund.pos.x +22) - a.pos.x <= 0.125: if (h.hund.pos.x +22) -a.pos.x >= -0.125: punktzahl = punktzahl + 50 anzeige.text="Punkte: "+str(punktzahl) else: pass