Links und Funktionen
Sprachumschaltung

Navigationspfad


Inhaltsbereich

auto2

auto.py — text/python-source, 6 KB (6532 bytes)

Dateiinhalt

from visual import *


# Szene-Einstellungen
scene.userzoom = True           # User darf zoomen?
scene.userspin = True           # User darf rotieren?
scene.forward = (-1,-1,-1)      # Kameraposition
scene.autoscale = True          # Autoskalierung aktiv?
scene.range = 300               # 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.white  # Hintergrundfarbe
scene.fov = 2                   # Kamerawinkeloeffnung: norm. 1
scene.fullscreen = False        # Vollbild? norm. False
scene.title = "Koordinaten"     # Fenstertitel
scene.width = 1400              # Fensterbreite: norm. 200
scene.height = 1400             # Fensterhoehe: norm 200
scene.x = 50                    # x-Koordinate d. Fensters: norm. 0
scene.y = 25                    # y-Koordinate d. Fensters: norm. 0


class Car2(frame):
    def __init__(self,pos=(0,0,0)):
        frame.__init__(self,pos=pos)
    
        self.reifen1 = ring(pos=(-40,5,-15), axis=(0,0,1), radius=5, thickness=2, color=color.black, frame=self)
        self.reifen2 = ring(pos=(0,5,-15), axis=(0,0,1), radius=5, thickness=2, color=color.black, frame=self)
        self.reifen3 = ring(pos=(-40,5,15), axis=(0,0,1), radius=5, thickness=2, color=color.black, frame=self)
        self.reifen4 = ring(pos=(0,5,15), axis=(0,0,1), radius=5, thickness=2, color=color.black, frame=self)
        self.reifen1i = cylinder(pos=(-40,5,-15),axis=(0,0,1),radius=3, color=color.black, frame=self)
        self.reifen2i = cylinder(pos=(0,5,-15),axis=(0,0,1),radius=3, color=color.black, frame=self)
        self.reifen3i = cylinder(pos=(-40,5,15),axis=(0,0,1),radius=3, color=color.black, frame=self)
        self.reifen4i = cylinder(pos=(0,5,15),axis=(0,0,1),radius=3, color=color.black, frame=self)
        self.boden = box(pos=(-20,5,0),length=60,height=1, width=26, color=(0,0.5,0), frame=self)
        self.frontg = box(pos=(-51,10,0),length=10,height=1, width=26,axis=(-0.3,1,0), color=(0,0.5,0), frame=self)
        self.frontw = box(pos=(-51.01,10,0),length=8,height=1, width=24,axis=(-0.3,1,0), color=color.white, frame=self)
        self.motorg = box(pos=(-40,16,0),length=25,height=1, width=26,axis=(1,0.1,0), color=(0,0.5,0), frame=self)
        self.motorw = box(pos=(-40,16.01,0),length=23,height=1, width=24,axis=(1,0.1,0), color=color.white, frame=self)
        self.scheibe = box(pos=(-24,21,0),length=10,height=1, width=26,axis=(0.8,1,0), color=color.black, frame=self)
        self.dachw = box(pos=(-6,25,0),length=30,height=1, width=26,axis=(1,0,0), color=color.white, frame=self)
        self.dachg = box(pos=(-6,25.01,0),length=28,height=1, width=24,axis=(1,0,0), color=(0,0.5,0), frame=self)
        self.heckug = box(pos=(10,10,0),length=10,height=1, width=26,axis=(0,1,0), color=(0,0.5,0), frame=self)
        self.heckuw = box(pos=(10.01,10,0),length=8,height=1, width=24,axis=(0,1,0), color=color.white, frame=self)
        self.hecko = box(pos=(8,20,0),length=10,height=1, width=26,axis=(-0.2,0.5,0), color=(0,0.5,0), frame=self)
        self.heckos = box(pos=(8.01,20,0),length=8,height=1, width=24,axis=(-0.2,0.5,0), color=color.black, frame=self)

        seiter = Polygon( [(10,5), (10,15), (6.5,25),(-10,25), (-10,17), (-28,17),(-52,15), (-50,5)] )
        straight = [(0,0,-12),(0,0,-13)]
        extrusion(pos=straight, shape=seiter, color=(0,0.5,0), frame=self)
        
        seitel = Polygon( [(10,5), (10,15), (6.5,25),(-10,25), (-10,17), (-28,17),(-52,15), (-50,5)] )
        straight = [(0,0,13),(0,0,12)]
        extrusion(pos=straight, shape=seitel, color=(0,0.5,0), frame=self)        
        
        fensterl = Polygon( [  (-10,25), (-10,17), (-28,17),(-21,25)] )
        straight = [(0,0,13),(0,0,12)]
        extrusion(pos=straight, shape=fensterl, color=color.black, frame=self)
        
        fensterr = Polygon( [  (-10,25), (-10,17), (-28,17),(-21,25)] )
        straight = [(0,0,-12),(0,0,-13)]
        extrusion(pos=straight, shape=fensterr, color=color.black, frame=self)
        
        self.vllicht = sphere(pos=(-52,10,-10),material = materials.emissive, frame=self, color=color.yellow, radius=2)
        self.vrlicht = sphere(pos=(-52,10,10),material = materials.emissive, frame=self, color=color.yellow, radius=2)
        
        self.hllicht = sphere(pos=(10,10,-10),material = materials.emissive, frame=self, color=color.red, radius=2)
        self.hrlicht = sphere(pos=(10,10,10),material = materials.emissive, frame=self, color=color.red, radius=2)

        self.kennzeichenv = box(pos=(-51,10,0),length=3,height=1, width=8,axis=(-0.3,1,0), color=color.black, frame=self)
        self.kennzeichenh = box(pos=(10,10,0),length=3,height=1, width=8,axis=(0,1,0), color=color.black, frame=self)

        blaulichts = cylinder(pos=(-15,25,10), radius=1, length=2, color=color.black, axis=(0,1,0), frame=self)
        blaulichtl = sphere(pos=(-15,27,10), radius=1,color=color.blue,material = materials.emissive, frame=self)

if __name__ == "__main__" :
    car2=Car2()
    rate(50)
    skk=""
    g=(0,0,0)
    gs=0.0
    while True:
        skk = scene.kb.getkey()
        if gs>=0.01:
                if skk=='w':
                    gs=gs+0.2
                elif skk=='s':
                    gs=gs-0.2
                if skk=='d':
                        car2.axis=car2.axis.rotate(angle=-pi/32,axis=(0,1,0))
                if skk=='a':
                        car2.axis=car2.axis.rotate(angle=pi/32,axis=(0,1,0))
                g=-gs*car2.axis  
                car2.pos=car2.pos+g
        else:
                if skk=='w':
                    gs=gs+0.2
                elif skk=='s':
                    gs=gs-0.2
                g=-gs*car2.axis
                car2.pos=car2.pos+g
    
         
        
            

                
                
    

if __name__ == "__main__" :
    car2=Auto()
    car2.setCenter=(40,5,15)
    v = (0,0,0)
    g=(0,0,0)
    gs=0
    a=0
    d=0  
    while True:
        rate(500)
        skk = scene.kb.getkey()
        if gs>=0.01:
                if skk=='w':
                    gs=gs+0.2
                elif skk=='s':
                    gs=gs-0.2
                if skk=='d':
                        car2.axis=car2.axis.rotate(angle=-pi/32,axis=(0,1,0))
                if skk=='a':
                        car2.axis=car2.axis.rotate(angle=pi/32,axis=(0,1,0))
                g=-gs*car2.axis  
                car2.pos=car2.pos+g

Funktionsleiste