Raumschiffbewegung mit Hintergrund
raumschiff-bewegung.py — text/python-source, 4 KB (4779 bytes)
Dateiinhalt
# Einbinden des 3D-Moduls from visual import * import time # Szene-Einstellungen scene.userzoom = True # User darf zoomen? scene.userspin = True # User darf rotieren? scene.forward = (0,0,-1) # Kameraposition scene.autoscale = False # Autoskalierung aktiv? scene.range = 12 # Kameraabstand von scene.center scene.center = (0,0,0) # Kamerablickpunkt: norm. (0,0,0) scene.up = (0,1,0) # Rotationsachse Kamera: norm. (0,1,0) scene.background = color.black # Hintergrundfarbe scene.fov = 1 # Kamerawinkeloeffnung: norm. 1 scene.fullscreen = True # Vollbild? norm. False scene.title = "Raumschiff" # Fenstertitel scene.width = 1200 # Fensterbreite: norm. 200 scene.height = 1000 # Fensterhoehe: norm 200 scene.x = 50 # x-Koordinate d. Fensters: norm. 0 scene.y = 25 # y-Koordinate d. Fensters: norm. 0 scene.cursor.visible=False # Mauszeiger unsichtbar # Koordinatenachsen in Form von Pfeilen #xAchse = arrow(axis=(10,0,0), shaftwidth=0.05, color=color.red) #yAchse = arrow(axis=(0,10,0), shaftwidth=0.05, color=(0,0,1)) #zAchse = arrow(axis=(0,0,10), shaftwidth=0.05, color=color.green) # Beschriftungen #xLabel = label(pos=(10,0,0), text="x-Achse") #yLabel = label(pos=(0,10,0), text="y-Achse") #zLabel = label(pos=(0,0,10), text="z-Achse") #Raumschiff erzeugen raumschiff=frame() nase=cone(pos=(0,0,0), axis=(0.5,0,0), radius=(0.1), material=materials.blazed, frame=raumschiff) rumpf=box(pos=(-0.35,-0.01,0), size=(0.79,0.2,0.4), material=materials.chrome, color=(0.4,0.4,0.4), frame=raumschiff) cockpit=ellipsoid(pos=(-0.15,0.07,0), size=(0.4,0.2,0.2), color=(0.5,0.8,0), material=materials.chrome, opacity=(1), frame=raumschiff) fluegel1=pyramid(pos=(-0.74,-0.01,0), size=(0.8,1.8,0.005), material=materials.chrome, opacity=(1), color=(0.4,0.4,0.4), frame=raumschiff) fluegel1.rotate(angle=0.65*pi,axis=(1,0,0), origin=(fluegel1.pos)) fluegel2=pyramid(pos=(-0.74,-0.01,0), size=(0.8,1.8,0.005), material=materials.chrome, opacity=(1), color=(0.4,0.4,0.4), frame=raumschiff) fluegel2.rotate(angle=1.35*pi,axis=(1,0,0), origin=(fluegel2.pos)) turbine1=frame(frame=raumschiff) turbinenfront1=cone(pos=(-0.4,-0.015,0.2), length=(0.15), radius=(0.07), material=materials.blazed, frame=turbine1) turbinenrohr1=cylinder(pos=(-0.75,-0.015,0.2), length=(0.35), radius=(0.07), material=materials.blazed, frame=turbine1) turbinenrohrende1=cylinder(pos=(-0.751,-0.015,0.2), length=(0.001),radius=(0.06),material=materials.plastic, color=(0.4,0.4,0.4), frame=turbine1) turbinenstrahl1=cone(pos=(-0.78,-0.015,0.2), length=(0.1), radius=(0.08), opacity=(0.6), color=(0.3,0.3,1), material=materials.emissive, frame=turbine1) turbine2=frame(frame=raumschiff) turbinenfront2=cone(pos=(-0.4,-0.015,-0.2), length=(0.15), radius=(0.07), material=materials.blazed, frame=turbine2) turbinenrohr2=cylinder(pos=(-0.75,-0.015,-0.2), length=(0.35), radius=(0.07), material=materials.blazed, frame=turbine2) turbinenrohrende2=cylinder(pos=(-0.751,-0.015,-0.2), length=(0.001),radius=(0.06),material=materials.plastic, color=(0.4,0.4,0.4), frame=turbine2) turbinenstrahl2=cone(pos=(-0.78,-0.015,-0.2), length=(0.1), radius=(0.08), opacity=(0.6), color=(0.3,0.3,1), material=materials.emissive, frame=turbine2) #raumschiff richtig drehen raumschiff.rotate(angle=pi/2, axis=(0,1,0), origin=(rumpf.pos)) raumschiff.pos=(0,0,12) ### #Lasergeschoss erzeugen laser=cylinder(radius=(0.055), length=(0.35), color=(0.2,1,0.2), material=materials.emissive, opacity=0.7) laser.rotate(angle=pi/2, axis=(0,1,0), origin=laser.pos) ### #Hintergrund erzeugen feuerkugel=sphere(pos=(-10,-10,-100), radius=(30), color=(0.75,0.21,0), material=materials.emissive) feuerringe=frame() feuerring=ring(pos=(-10,-10,-100), radius=(35), color=(1,0,0), thickness=(2), material=materials.BlueMarble, frame=feuerringe) feuerring2=ring(pos=(-10,-10,-100), radius=(37), color=(1,0,0), thickness=(2), material=materials.BlueMarble, frame=feuerringe) planet=sphere(pos=(15,15,-80), radius=(12), color=(0,1,0), material=materials.earth) ### #Raumschiffbewegung mit Maus while True: #Bewegung des Hintergrund planet.rotate(angle=-pi/450, axis=(0.3,1,0), origin=planet.pos) feuerringe.rotate(angle=pi/800, axis=(1,0,0), origin=feuerring.pos) feuerringe.rotate(angle=pi/750, axis=(0,1,0), origin=feuerring.pos) feuerringe.rotate(angle=pi/850, axis=(0,0,1), origin=feuerring.pos) ### mauspos = scene.mouse.project(normal=(0,0,1), point=(0,0,13)) raumschiffx=(mauspos.x-raumschiff.x)*0.02 raumschiffy=(mauspos.y-raumschiff.y)*0.02 raumschiff.pos=(raumschiff.x+raumschiffx,raumschiff.y+raumschiffy,12) time.sleep(0.001) ###