Ejemplo n.º 1
1
def line(pos=(0,0), np=2, rotate=0.0, scale=1.0, xscale=1.0, yscale=1.0,
           thickness=None, start=(0,0), end=(0,1), path=False):
        v = vis.vector((end[0]-start[0]), (end[1]-start[1]))
        if thickness is None:
            thickness = 0.01*vis.mag(v)
        dv = thickness*vis.norm(vis.vector(0,0,1).cross(v))
        dx = dv.x
        dy = dv.y
        cp = [] # outer line
        cpi = [] # inner line
        vline = (vis.vector(end)-vis.vector(start)).norm()
        mline = vis.mag(vis.vector(end)-vis.vector(start))
        for i in range(np):
            x = start[0] + (vline*i)[0]/float(np-1)*mline
            y = start[1] + (vline*i)[1]/float(np-1)*mline
            cp.append( (x+pos[0],y+pos[1]) )
            cpi.append( (x+pos[0]+dx,y+pos[1]+dy) )
        if not path:
                cpi.reverse()
                for p in cpi:
                    cp.append(p)
                cp.append(cp[0])
        if rotate != 0.0: cp = rotatecp(cp, pos, rotate)
        if scale != 1.0: xscale = yscale = scale
        pp = Polygon(cp)
        if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
        if not path:
                return pp
        else:
                return [cp]
Ejemplo n.º 2
0
 def __init__(self, start=(0,0,0), end=(0,0,-1), np=2):
     if np < 2:
         raise AttributeError("The minimum value of np is 2 (one segment)")
     start = vector(start)
     end = vector(end)
     vline = (end-start)/(np-1)
     self.pos = []
     for i in range(np):
         self.pos.append(start + i*vline)
     self.up = (0,1,0)
Ejemplo n.º 3
0
 def __init__(self, start=(0, 0, 0), end=(0, 0, -1), np=2):
     if np < 2:
         raise AttributeError("The minimum value of np is 2 (one segment)")
     start = vector(start)
     end = vector(end)
     vline = (end - start) / (np - 1)
     self.pos = []
     for i in range(np):
         self.pos.append(start + i * vline)
     self.up = (0, 1, 0)
Ejemplo n.º 4
0
def convert(pos=(0,0,0), up=(0,1,0), points=None, closed=True):
        pos = vector(pos)
        up = norm(vector(up))
        up0 = vector(0,1,0)
        angle = acos(up.dot(up0))
        reorient = (angle > 0.0)
        axis = up0.cross(up)
        pts = []
        for pt in points:
            newpt = vector(pt[0],0,-pt[1])
            if reorient: newpt = newpt.rotate(angle=angle, axis=axis)
            pts.append(pos+newpt)
        if closed and (pts[-1] != pts[0]): pts.append(pts[0])
        return pts
Ejemplo n.º 5
0
def convert(pos=(0, 0, 0), up=(0, 1, 0), points=None, closed=True):
    pos = vector(pos)
    up = norm(vector(up))
    up0 = vector(0, 1, 0)
    angle = acos(up.dot(up0))
    reorient = (angle > 0.0)
    axis = up0.cross(up)
    pts = []
    for pt in points:
        newpt = vector(pt[0], 0, -pt[1])
        if reorient: newpt = newpt.rotate(angle=angle, axis=axis)
        pts.append(pos + newpt)
    if closed and (pts[-1] != pts[0]): pts.append(pts[0])
    return pts
Ejemplo n.º 6
0
def ship(s, v, a, dt, spaceship, predraw):
    dst = vector(0, 0, 0) - s  # computing spaceship - Sun distance vector
    gravity_acc = (u / (mag2(dst))) * norm(dst)  # computing gravity force

    v += (gravity_acc + a) * dt  # numerical integration of velocity
    s += v * dt  # numerical integration of position

    spaceship.pos = s  # assigning new position to the spaceship
    spaceship.trail.append(pos=s, retain=2000)  # appending spaceship trail with new position

    # recovers the spaceship to the initial position in case of crashing into the Sun or going out of range:

    if star_radius <= mag(s) or mag(s) <= sun_radius:
        spaceship.pos = s0
        spaceship.trail.pos = []    # clear the trail
        s, v, a = vector(s0.astuple()), vector(v0.astuple()), vector(a0.astuple())  # assign initial values
        predraw = False  # redraw the orbital prediction

    return s, v, a, predraw
Ejemplo n.º 7
0
def camera():  # initial camera movement
    global scene_old

    if scene_old==scene.forward:    # stop when user rotates -> scene.forward changes
        scene.forward = (scene.forward[0] + 6 / 3000., scene.forward[1] - 4 / 5000., scene.forward[2])
        scene_old=vector(scene.forward.astuple())

    # scene.scale = (scene.scale[0] + 6 * 2e-13, scene.scale[1] + 6 * 2e-13, scene.scale[2] + 6 * 2e-13)

    return 0
Ejemplo n.º 8
0
def camera():  # initial camera movement
    global scene_old

    if scene_old == scene.forward:  # stop when user rotates -> scene.forward changes
        scene.forward = (scene.forward[0] + 6 / 3000.,
                         scene.forward[1] - 4 / 5000., scene.forward[2])
        scene_old = vector(scene.forward.astuple())

    # scene.scale = (scene.scale[0] + 6 * 2e-13, scene.scale[1] + 6 * 2e-13, scene.scale[2] + 6 * 2e-13)

    return 0
Ejemplo n.º 9
0
def ship(s, v, a, dt, spaceship, predraw):
    dst = vector(0, 0, 0) - s  # computing spaceship - Sun distance vector
    gravity_acc = (u / (mag2(dst))) * norm(dst)  # computing gravity force

    v += (gravity_acc + a) * dt  # numerical integration of velocity
    s += v * dt  # numerical integration of position

    spaceship.pos = s  # assigning new position to the spaceship
    spaceship.trail.append(
        pos=s, retain=2000)  # appending spaceship trail with new position

    # recovers the spaceship to the initial position in case of crashing into the Sun or going out of range:

    if star_radius <= mag(s) or mag(s) <= sun_radius:
        spaceship.pos = s0
        spaceship.trail.pos = []  # clear the trail
        s, v, a = vector(s0.astuple()), vector(v0.astuple()), vector(
            a0.astuple())  # assign initial values
        predraw = False  # redraw the orbital prediction

    return s, v, a, predraw
Ejemplo n.º 10
0
def neuron3d(neuron_graph, color=vis.color.white):
    # vis.scene.stereo = 'redcyan'
    vis.scene.center = vis.vector(
        (neuron_graph.node[1]['x'], neuron_graph.node[1]['y'],
         neuron_graph.node[1]['z']))
    vis.scene.width = 1024
    vis.scene.height = 768
    for n0, n1 in neuron_graph.edges():
        pos0 = np.array(
            (neuron_graph.node[n0]['x'], neuron_graph.node[n0]['y'],
             neuron_graph.node[n0]['z']))
        pos1 = np.array(
            (neuron_graph.node[n1]['x'], neuron_graph.node[n1]['y'],
             neuron_graph.node[n1]['z']))
        comp = vis.cylinder(pos=pos0,
                            axis=pos1 - pos0,
                            radius=neuron_graph.node[n0]['r'],
                            color=color,
                            display=vis.scene)
Ejemplo n.º 11
0
def key_check(ship_mode, s, v, a, dt, sw_lbl, lbl_off, predraw, earthpos, t,
              ship):
    if scene.kb.keys:  # check if there are any keys pressed in the queue

        key = scene.kb.getkey()  # retrieve the pressed key

        # change simulation speed: (steps are small on purpose; user has to press and hold for smooth transition)
        if key == 'q' and 1 <= dt < 125:
            dt += 2
        elif key == 'q' and dt <= 0.95:
            dt += 0.05
        elif key == 'a' and dt > 1:
            dt -= 2
        elif key == 'a' and 0.2 < dt <= 1:
            dt -= 0.05

        elif key == 'esc':
            Exit()  # exit the program

        elif key == 'p':
            lbl.visible = True  # show pause label
            lbl.pos = scene.center  # center the label on the screen
            scene.kb.getkey()  # wait for key input
            lbl.visible = False  # hide pause label

        elif key == 'x':
            if scene.stereo == 'nostereo':
                scene.stereo = 'redcyan'  # turn on 3D rendering mode (red-cyan)
            elif scene.stereo == 'redcyan':
                scene.stereo = 'crosseyed'  # turn on 3D rendering mode (cross-eyed)
            else:
                scene.stereo = 'nostereo'  # turn off 3D rendering mode

        elif key == 'l':
            sw_lbl = not sw_lbl  # planet/spaceship label switch
            lbl_off = not lbl_off

        elif key == 's':
            #if ship_mode:
            #               music.fadeout(2500) # fade out music when quitting spaceship mode
            #            else:
            #                music.play(-1)   # turn on music when entering spaceship mode

            ship_mode = not ship_mode  # spaceship mode switch
            a = vector(0, 0, 0)  # reset acceleration
            sw_lbl = True  # turn on spaceship label

        # spaceship thrusters control:

        elif key == 'up':
            #a += vector(0, 0, am)  # old cartesian steering
            a += am * norm(v)  # accelerate into the direction of motion
        elif key == 'down':
            a -= am * norm(v)  # accelerate against the direction of motion
        elif key == 'left':
            a -= am * cross(norm(v), cross(
                norm(v), norm(s)))  # accelerate to the left of the velocity

        elif key == 'right':
            a += am * cross(norm(v), cross(
                norm(v), norm(s)))  # accelerate to the right of the velocity
        elif key == 'd':
            a += am * cross(norm(v),
                            norm(s))  # accelerate to the 'top' of the velocity
        elif key == 'c':
            a -= am * cross(
                norm(v), norm(s))  # accelerate to the 'bottom' of the velocity
        elif key == '0':
            a = vector(0, 0, 0)  # reset acceleration

        # pre-programmed spaceship positions/scenarios:

        elif key == '1':  # Earth-Sun Lagrange point 3 (L3 - 'counter-Earth')
            s = -earthpos
            v0 = (planets[2][1][:, (int(-t + 1)) % n] -
                  planets[2][1][:, (int(-t)) % n]) / (365.25 * 86400 / n)
            v = vector(v0[0], v0[1], v0[2])
            a = vector(0, 0, 0)
            predraw = False
            ship.trail.append(pos=s, retain=1)

        elif key == '2':  # polar orbit around the Sun
            s = vector(3e+07, -2e+06, 2e+08)
            v = vector(0, 24, 0)
            a = vector(0, 0, 0)
            predraw = False
            ship.trail.append(pos=s, retain=1)

        elif key == '3':  # orbit of the probe Helios 2  (fastest man-made object to date - 0.02% speed of light)
            s = vector(43e6, 0, 0)  # perihelion
            v = vector(0, 0, 70.22)
            a = vector(0, 0, 0)
            predraw = False
            ship.trail.append(pos=s, retain=1)

        elif key == '4':  # Halley's comet (derived using specific orbital energy, 162.3 deg inclination)
            s = vector(87813952, 0, 0)  # perihelion
            v = vector(0, 16.7, 52)
            a = vector(0, 0, 0)
            predraw = False
            ship.trail.append(pos=s, retain=1)

    return ship_mode, s, v, a, dt, sw_lbl, lbl_off, predraw, ship
Ejemplo n.º 12
0
def text(pos=(0,0), text="", font=None, height=1.0, align='left', spacing=0.03, rotate=0.0,
         scale=1.0, xscale=1.0, yscale=1.0, thickness=None, vertical_spacing=None,
         info=False):
    # If info == True, the caller wants the additional info such as upper-left, etc.
    # In this case we return an instance of the class text_info, with the Polygon as
    # an attribute, text_info.Polygon. The main client of this extra info is the text object.
    if thickness is not None:
        raise AttributeError("Thickness is not allowed in a text shape.")
    if scale != 1.0: xscale = yscale = scale
    lines = text.split('\n')
    while lines[-1] == '\n': # strip off trailing newlines
        lines = lines[:-1]
    if font is None:
        font = "serif"
    font = describe.openFont(findFont(font))
    
    try:
        fonth = glyphquery.charHeight(font)
    except:
        fonth = 1000
    if fonth == 0: fonth = 1000
    
    try:
        desc = glyphquery.charDescent(font) # charDescent may not be present
        fontheight = fonth+desc
        fontscale = 1./fontheight
        descent = fontscale*desc
    except:
        descent = -0.3*height # approximate value
        fontheight = 0.7*fonth
        fontscale = 1.3/fontheight
        
    if vertical_spacing is None:
        vertical_spacing = height*fontscale*glyphquery.lineHeight(font)

    excludef_list = [("ITCEdscr")]
    excludec_list = [("FRSCRIPT", "A"), ("jokerman", "O"),
                    ("vivaldii", "O"), ("vivaldii", "Q"),
                    ("vivaldii", "R")]
    
    ptext = [] 
    widths = []
    width = 0.0
    starts = []
    start = 0.0

    for line in range(len(lines)):
        ptext.append(Polygon())
        bb = 0
        
        for newchar in lines[line]:
            if newchar == " ":
                try:
                    if a:
                        bx = a.boundingBox()
                        bba = bx[1]-bx[0]
                        bba = min(bba, 700)
                        bb += bba
                except:
                    pass
                continue
            n = glyphquery.glyphName(font, newchar)

            if n == ".notdef":
                print("The character '"+newchar+"' is not supported in the font "+font)
                continue
            
            g = glyph.Glyph(n)
            c = g.calculateContours(font)
            contours = []

            for contour in c:
                contours.append(glyph.decomposeOutline(contour))
                if len(contours[-1]) == 0: contours.pop()

            for contour in contours:
                pp = 0
                for i in range(len(contour)-1):
                    if (contour[i][0] == contour[i+1][0]) and (contour[i][1] == contour[i+1][1]):
                        contour.pop(i)
                        pp += 1
                        if i+pp >= len(contour)-1: break

            def lenctr(contour):
                totlen = 0
                for j in range(len(contour)-1):
                    totlen += (vis.vector(contour[j])-vis.vector(contour[j+1])).mag
                return totlen

            lc = len(contours)
            
            if lc >= 4:
                mli = 0
                maxl = 0
                lengths = []
                for i in range(len(contours)):
                    totlen = lenctr(contours[i])
                    lengths.append((totlen,i))
                    if totlen > maxl:
                        mli = i
                        maxl = totlen

                lengths.sort()
                lengths.reverse()
                ocontours = []
                for ll in lengths:
                    ocontours.append(contours[ll[1]])
                contours = ocontours

                indxf = -1
                indxc = -1
                if (mli > 0 and newchar != "%"):
                    try: indxf = excludef_list.index(self.font)
                    except: pass
                    if indxf == -1:
                        try: indxc = excludec_list.index((self.font, newchar))
                        except: pass
                    if (indxf == -1 and indxc == -1):
                        maxc = contours.pop(mli)
                        contours.insert(0, maxc)
                               
            a = Polygon(contours[0])
            for i in range(1,len(contours)):
                b = Polygon(contours[i])
                if a.covers(b): a = a - b
                elif b.covers(a): a = b - a
                else: a = a + b

            a.shift(bb - a.boundingBox()[0] ,0)
           
            ptext[line] += a
            
            bx = ptext[line].boundingBox()
            bb = bx[1] - bx[0] + spacing*fontheight

        newwidth = fontscale*height*(ptext[line].boundingBox()[1]-ptext[line].boundingBox()[0])
        widths.append(newwidth)
        if newwidth > width: width = newwidth
        
        ptext[line].scale(xscale*fontscale*height, yscale*fontscale*height, 0, 0)
        
    for line in range(len(lines)):
        if align == 'left':
            ptext[line].shift(-width/2,-line*vertical_spacing)
        elif align == 'right':
            ptext[line].shift(width/2-widths[line],-line*vertical_spacing)
        else:
            ptext[line].shift(-widths[line]/2,-line*vertical_spacing)
        ptext[line].shift(pos[0], pos[1])
        if rotate != 0.0: ptext[line].rotate(rotate)
        if line == 0:
            shape = ptext[0]
            upper_left = vis.vector(ptext[line].boundingBox()[0],ptext[line].boundingBox()[3],0)
            upper_right = vis.vector(ptext[line].boundingBox()[1],ptext[line].boundingBox()[3],0)
            lower_left = vis.vector(ptext[line].boundingBox()[0],ptext[line].boundingBox()[2],0)
            lower_right = vis.vector(ptext[line].boundingBox()[1],ptext[line].boundingBox()[2],0)
        else:
            shape += ptext[line]
            xleft = ptext[line].boundingBox()[0]
            xright = ptext[line].boundingBox()[1]
            y = ptext[line].boundingBox()[2]
            if xleft < upper_left.x:
                upper_left.x = xleft
            if xright > upper_right.x:
                upper_right.x = xright
            lower_left = vis.vector(upper_left.x,ptext[line].boundingBox()[2],0)
            lower_right = vis.vector(upper_right.x,ptext[line].boundingBox()[2],0)

    dy = vis.vector(0,(upper_left.y-lower_left.y)/2-height,0)
    shape.shift(0,dy.y)
    if not info: return shape

    info = text_info()
    info.Polygon = shape
    info.upper_left = upper_left+dy
    info.upper_right = upper_right+dy
    info.lower_left = lower_left+dy
    info.lower_right = lower_right+dy
    if align == 'left':
        x = 0
    elif align == 'right':
        x = -width
    elif align == 'center':
        x = -0.5*width
    info.start = vis.vector(x,0,0)+dy
    info.starts = []
    for line in range(len(lines)):
        if align == 'left':
            x = 0
        elif align == 'right':
            x = -widths[line]
        elif align == 'center':
            x = -0.5*widths[line]
        info.starts.append(vis.vector(x,line*vertical_spacing,0)+dy)
    
    info.width = width
    info.widths = widths
    info.descent = descent
    info.vertical_spacing = vertical_spacing
    info.align = align
    info.height = height
    
    return info
Ejemplo n.º 13
0
from vis import rate, vector  # importing vPython module
# from pygame.mixer import music, init  # importing PyGame music module
from graphics import camera  # importing vPython with predefined settings
from key_control import key_check, mouse_check  # importing keyboard and mouse control module
from spaceship import ship  # importing variable orbit simulator
from uvf import position  # importing orbit predictor from variable orbit simulator
from info import lbl, lbl_ship, popup  # importing planet label generator
from update import planet_update, moon_update  # importing position-updating functions
from parameters import running, f, spaceship, times, sun, saturn_ring, uranus_ring, dt, planets, moons, n, \
    ship_mode, sw_lbl, lbl_off, s0, v0, a0, predraw, trailer, obj, t
# importing variables, lists, planets and moons

# init()  # initializing PyGame music mixer module
# music.load("danube.mp3")  # loading The Blue Danube Waltz by Johann Strauss

s, v, a = vector(s0.astuple()), vector(v0.astuple()), vector(a0.astuple())

while running:
    rate(f)  # ensures a steady rate of simulation on all computers

    # checking keyboard input:
    ship_mode, s, v, a, dt, sw_lbl, lbl_off, predraw, spaceship = key_check(
        ship_mode, s, v, a, dt, sw_lbl, lbl_off, predraw, planets[2][0].pos, t,
        spaceship)

    # spaceship coordinates update:
    s, v, a, predraw = ship(s, v, a, dt * 365.25 * 86400 / n, spaceship,
                            predraw)

    if ship_mode:
Ejemplo n.º 14
0
def key_check(ship_mode, s, v, a, dt, sw_lbl, lbl_off, predraw, earthpos, t, ship):
    if scene.kb.keys:  # check if there are any keys pressed in the queue

        key = scene.kb.getkey()  # retrieve the pressed key

        # change simulation speed: (steps are small on purpose; user has to press and hold for smooth transition)
        if key == 'q' and 1 <= dt < 125:
            dt += 2
        elif key == 'q' and dt <= 0.95:
            dt += 0.05
        elif key == 'a' and dt > 1:
            dt -= 2
        elif key == 'a' and 0.2 < dt <= 1:
            dt -= 0.05

        elif key == 'esc':
            Exit()  # exit the program

        elif key == 'p':
            lbl.visible = True  # show pause label
            lbl.pos = scene.center  # center the label on the screen
            scene.kb.getkey()  # wait for key input
            lbl.visible = False  # hide pause label

        elif key == 'x':
            if scene.stereo == 'nostereo':
                scene.stereo = 'redcyan'  # turn on 3D rendering mode (red-cyan)
            elif scene.stereo == 'redcyan':
                scene.stereo = 'crosseyed'  # turn on 3D rendering mode (cross-eyed)
            else:
                scene.stereo = 'nostereo'  # turn off 3D rendering mode

        elif key == 'l':
            sw_lbl = not sw_lbl  # planet/spaceship label switch
            lbl_off = not lbl_off

        elif key == 's':
            #if ship_mode:
 #               music.fadeout(2500) # fade out music when quitting spaceship mode
#            else:
#                music.play(-1)   # turn on music when entering spaceship mode

            ship_mode = not ship_mode  # spaceship mode switch
            a = vector(0, 0, 0)  # reset acceleration
            sw_lbl = True  # turn on spaceship label

        # spaceship thrusters control:

        elif key == 'up':
            #a += vector(0, 0, am)  # old cartesian steering
            a += am*norm(v)  # accelerate into the direction of motion
        elif key == 'down':
            a -= am*norm(v)  # accelerate against the direction of motion
        elif key == 'left':
            a -= am*cross(norm(v),cross(norm(v),norm(s)))   # accelerate to the left of the velocity

        elif key == 'right':
            a += am*cross(norm(v),cross(norm(v),norm(s)))  # accelerate to the right of the velocity
        elif key == 'd':
            a += am*cross(norm(v),norm(s))  # accelerate to the 'top' of the velocity
        elif key == 'c':
            a -= am*cross(norm(v),norm(s))   # accelerate to the 'bottom' of the velocity
        elif key == '0':
            a = vector(0, 0, 0)  # reset acceleration

        # pre-programmed spaceship positions/scenarios:

        elif key == '1':  # Earth-Sun Lagrange point 3 (L3 - 'counter-Earth')
            s = -earthpos
            v0 = (planets[2][1][:, (int(-t + 1)) % n] - planets[2][1][:, (int(-t)) % n]) / (365.25 * 86400 / n)
            v = vector(v0[0], v0[1], v0[2])
            a = vector(0, 0, 0)
            predraw = False
            ship.trail.append(pos=s, retain=1)

        elif key == '2':  # polar orbit around the Sun
            s = vector(3e+07, -2e+06, 2e+08)
            v = vector(0, 24, 0)
            a = vector(0, 0, 0)
            predraw = False
            ship.trail.append(pos=s, retain=1)

        elif key == '3':  # orbit of the probe Helios 2  (fastest man-made object to date - 0.02% speed of light)
            s = vector(43e6, 0, 0)  # perihelion
            v = vector(0, 0, 70.22)
            a = vector(0, 0, 0)
            predraw = False
            ship.trail.append(pos=s, retain=1)

        elif key == '4':  # Halley's comet (derived using specific orbital energy, 162.3 deg inclination)
            s = vector(87813952, 0, 0)  # perihelion
            v = vector(0, 16.7, 52)
            a = vector(0, 0, 0)
            predraw = False
            ship.trail.append(pos=s, retain=1)

    return ship_mode, s, v, a, dt, sw_lbl, lbl_off, predraw, ship
Ejemplo n.º 15
0
from vis import rate, vector  # importing vPython module
# from pygame.mixer import music, init  # importing PyGame music module
from graphics import camera  # importing vPython with predefined settings
from key_control import key_check, mouse_check  # importing keyboard and mouse control module
from spaceship import ship  # importing variable orbit simulator
from uvf import position  # importing orbit predictor from variable orbit simulator
from info import lbl, lbl_ship, popup  # importing planet label generator
from update import planet_update, moon_update  # importing position-updating functions
from parameters import running, f, spaceship, times, sun, saturn_ring, uranus_ring, dt, planets, moons, n, \
    ship_mode, sw_lbl, lbl_off, s0, v0, a0, predraw, trailer, obj, t
# importing variables, lists, planets and moons

# init()  # initializing PyGame music mixer module
# music.load("danube.mp3")  # loading The Blue Danube Waltz by Johann Strauss

s, v, a = vector(s0.astuple()), vector(v0.astuple()), vector(a0.astuple())

while running:
    rate(f)  # ensures a steady rate of simulation on all computers

    # checking keyboard input:
    ship_mode, s, v, a, dt, sw_lbl, lbl_off, predraw, spaceship = key_check(ship_mode, s, v, a, dt, sw_lbl, lbl_off,
                                                                            predraw, planets[2][0].pos, t, spaceship)

    # spaceship coordinates update:
    s, v, a, predraw = ship(s, v, a, dt * 365.25 * 86400 / n, spaceship, predraw)

    if ship_mode:

        obj = spaceship # set spaceship as the main object
Ejemplo n.º 16
0
# spaceship simulation parameters:
ship_mode = False  # switch for turning on spaceship control
predraw = False  # switch that ensures that the spaceship path will be drawn when it is activated
u = 132712440018.1  # Sun gravitational parameter
am = 1.5e-6  # acceleration increment in km/s^2
n_pred = 800 + 1  # number of data points in the orbit prediction (affects speed of the simulation)
t_pred = 200000  # temporal shift of data points in the orbit prediction (in seconds)
times = arange(1, n_pred) * t_pred  # array with input for orbit predictor

# constructing spaceship and orbit predictor:
spaceship = sphere(radius=1000000, trail=curve(color=color.white), material=death_star, color=(0.5, 0.5, 0.5))
trailer = box(length=1, height=1, width=1, trail=curve())

# initial attitude of the spaceship (in km):
s0 = vector(3e+07, -2e+06, 2e+08)
v0 = vector(-17, 0, 14)
a0 = vector(0, 0, 0)

# initializing unique (one-off) bodies:
sun = sphere(radius=695500 * 40, color=color.yellow, material=materials.emissive)  # radius in km
sun2 = sphere(radius=695500 * 40, material=sun_mat, opacity=0.7)  # applying Sun spots
stars = sphere(radius=30066790000, material=stars_mat)  # constructing a stellar sphere

obj = sun  # declaring Sun as the object in the center of the scene
sun_radius = sun.radius # constant required by external modules

for planet in planet_list:  # constructing planets list
    planets.append(planet_ini(planet, n, ScaleUp))

for moon in moon_list:  # constructing moons list (has to be initialized after the planets)
Ejemplo n.º 17
0
 def lenctr(contour):
     totlen = 0
     for j in range(len(contour)-1):
         totlen += (vis.vector(contour[j])-vis.vector(contour[j+1])).mag
     return totlen
Ejemplo n.º 18
0
from vis import scene, local_light, color, vector

# scene parameters and settings:

scene.x, scene.y = 250, 80  # centering the window (optimized for SXGA displays)
scene.width, scene.height = 800, 600
scene.title = "Solar System"
scene.lights = []
scene.ambient = 0.4  # turning off default lights and turning on some ambient light and the Sun
scene.forward = (2, -1, -2)
lamp = local_light(pos=(0, 0, 0), color=color.white)  # setting the scene
scene.autoscale = False
scene.scale = (0.000000001, 0.000000001, 0.000000001)
scene.fov = 0.8  # field of view

scene_old = vector(scene.forward.astuple())


def camera():  # initial camera movement
    global scene_old

    if scene_old == scene.forward:  # stop when user rotates -> scene.forward changes
        scene.forward = (scene.forward[0] + 6 / 3000.,
                         scene.forward[1] - 4 / 5000., scene.forward[2])
        scene_old = vector(scene.forward.astuple())

    # scene.scale = (scene.scale[0] + 6 * 2e-13, scene.scale[1] + 6 * 2e-13, scene.scale[2] + 6 * 2e-13)

    return 0
Ejemplo n.º 19
0
def roundc(cp, roundness=0.1, nseg=8, invert=False):

    vort = 0.0
    cp.pop()
    for i in range(len(cp)):
        i1 = (i+1)%len(cp)
        i2 = (i+2)%len(cp)
        v1 = vis.vector(cp[i1]) - vis.vector(cp[i])
        v2 = vis.vector(cp[(i2)%len(cp)]) - vis.vector(cp[i1])
        dv = vis.dot(v1,v2)
        vort += dv

    if vort > 0: cp.reverse()

    l = 999999
    
    for i in range(len(cp)):
        p1 = vis.vector(cp[i])
        p2 = vis.vector(cp[(i+1)%len(cp)])
        lm = vis.mag(p2-p1)
        if lm < l: l = lm

    r = l*roundness
    ncp = []
    lcp = len(cp)

    for i in range(lcp):
        i1 = (i+1)%lcp
        i2 = (i+2)%lcp
        
        w0 = vis.vector(cp[i])
        w1 = vis.vector(cp[i1])
        w2 = vis.vector(cp[i2])

        wrt = vis.cross((w1-w0),(w2-w0))

        v1 = w1-w0
        v2 = w1-w2
        rax = vis.norm(((vis.norm(v1)+vis.norm(v2))/2.0))
        angle = acos(vis.dot(vis.norm(v2),vis.norm(v1)))
        afl = 1.0
        if wrt[2] > 0: afl = -1.0
        angle2 = angle/2.0
        cc = r/sin(angle2)
        ccp = vis.vector(cp[i1]) - rax*cc
        tt = r/tan(angle2)
        t1 = vis.vector(cp[i1]) -vis.norm(v1)*tt
        t2 = vis.vector(cp[i1]) -vis.norm(v2)*tt

        ncp.append(tuple(t1)[0:2])
        nc = []
        a = 0
        dseg = afl*(pi-angle)/nseg
        if not invert:
            for i in range(nseg):
                nc.append(rotatep(t1, ccp, a))
                ncp.append(tuple(nc[-1])[0:2])
                a -= dseg
        else:
            dseg = afl*(angle)/nseg
            for i in range(nseg):
                nc.append(rotatep(t1, (cp[i1][0],cp[i1][1],0), a))
                ncp.append(tuple(nc[-1])[0:2])
                a += dseg
        ncp.append(tuple(t2)[0:2])
    ncp.append(ncp[0])
    return ncp
Ejemplo n.º 20
0
from vis import scene, local_light, color, vector


# scene parameters and settings:

scene.x, scene.y = 250, 80  # centering the window (optimized for SXGA displays)
scene.width, scene.height = 800, 600
scene.title = "Solar System"
scene.lights = []
scene.ambient = 0.4  # turning off default lights and turning on some ambient light and the Sun
scene.forward = (2, -1, -2)
lamp = local_light(pos=(0, 0, 0), color=color.white)  # setting the scene
scene.autoscale = False
scene.scale = (0.000000001, 0.000000001, 0.000000001)
scene.fov = 0.8  # field of view

scene_old = vector(scene.forward.astuple())


def camera():  # initial camera movement
    global scene_old

    if scene_old==scene.forward:    # stop when user rotates -> scene.forward changes
        scene.forward = (scene.forward[0] + 6 / 3000., scene.forward[1] - 4 / 5000., scene.forward[2])
        scene_old=vector(scene.forward.astuple())

    # scene.scale = (scene.scale[0] + 6 * 2e-13, scene.scale[1] + 6 * 2e-13, scene.scale[2] + 6 * 2e-13)

    return 0