Exemple #1
0
vp.arrow(pos=(0, 4, 0), axis=(0, 1, 0), color=vp.color.red)
BOXY = vp.box(size=(3, 3, 3),
              color=(0.5, 0.5, 0.5),
              material=vp.materials.rough)
B1 = vp.sphere(radius=0.3,
               pos=(R, 0, 0),
               color=vp.color.magenta,
               material=vp.materials.emissive)
B2 = vp.sphere(radius=0.3,
               pos=(0, 0, R),
               color=vp.color.yellow,
               material=vp.materials.emissive)
B3 = vp.arrow(radius=0.3,
              pos=(0, 0, R),
              color=vp.color.green,
              material=vp.materials.emissive)
L1 = vp.local_light(pos=B1.pos, color=B1.color)
L2 = vp.local_light(pos=B2.pos, color=B2.color)
L3 = vp.distant_light(direction=B3.pos, color=B3.color)

while True:
    vp.rate(100)
    L1.pos = B1.pos = R * vp.vector(vp.cos(A1), vp.sin(A1), B1.z)
    A1 += 0.02
    L2.pos = B2.pos = (R + 0.4) * vp.vector(B2.x, vp.sin(A2), vp.cos(A2))
    A2 += 0.055
    L3.direction = B3.pos = (R + 3) * vp.vector(vp.sin(A3), B3.y, vp.cos(A3))
    B3.axis = B3.pos * -0.3
    A3 += 0.033
from __future__ import print_function, division
import visual as vp

print(__doc__)

R = 3
A1 = A2 = A3 = 0.0

vp.arrow(pos=(0, 4, 0), axis=(0, 1, 0), color=vp.color.red)
BOXY = vp.box(size=(3, 3, 3), color=(0.5, 0.5, 0.5), material=vp.materials.rough)
B1 = vp.sphere(radius=0.3, pos=(R, 0, 0),
               color=vp.color.magenta, material=vp.materials.emissive)
B2 = vp.sphere(radius=0.3, pos=(0, 0, R),
               color=vp.color.yellow, material=vp.materials.emissive)
B3 = vp.arrow(radius=0.3, pos=(0, 0, R),
              color=vp.color.green, material=vp.materials.emissive)
L1 = vp.local_light(pos=B1.pos, color=B1.color)
L2 = vp.local_light(pos=B2.pos, color=B2.color)
L3 = vp.distant_light(direction=B3.pos, color=B3.color)

while True:
    vp.rate(100)
    L1.pos = B1.pos = R*vp.vector(vp.cos(A1), vp.sin(A1), B1.z)
    A1 += 0.02
    L2.pos = B2.pos = (R+0.4)*vp.vector(B2.x, vp.sin(A2), vp.cos(A2))
    A2 += 0.055
    L3.direction = B3.pos = (R+3)*vp.vector(vp.sin(A3), B3.y, vp.cos(A3))
    B3.axis = B3.pos * -0.3
    A3 += 0.033

Exemple #3
0
vp.scene.autocenter = True
vp.scene.width = 1024
vp.scene.height = 768

MOTOR_FRAME = vp.frame(axis=(0, 0, 1))  # Motor Frame
ROTOR_FRAME = vp.frame(frame=MOTOR_FRAME)  # Rotor Frame

# Create contactor
# First, draw the outer circle
G1 = vp.shapes.circle(radius=1.2)
NS = 24
# We will have 24 contactor surfaces, 2 per each rotor wiring
for i in range(NS):
    # Second, subtract rectangular pieces to get a slice for each contact surface
    t = vp.shapes.rectangle(pos=(1.2 * vp.cos(i * 2 * PI / NS),
                                 1.2 * vp.sin(i * 2 * PI / NS)),
                            width=2.1,
                            height=0.05,
                            rotate=i * 2 * PI / NS)
    G1 = G1 - t

G1 = G1 - vp.shapes.circle(radius=0.5)  # Last, subtract rotor shaft
C1 = 2.0
# Now, extrude to get "cylindrical" contactor surfaces
GE1 = vp.extrusion(pos=[(0, 0, 0), (0, 0, C1)],
                   shape=G1,
                   color=(1, 0.5, 0.3),
                   material=vp.materials.rough,
                   frame=ROTOR_FRAME)
Exemple #4
0
    x=vp.arange(-1, 1, RESTLENGTH),
    y=1,
    radius=0.02
)

BAND.p = BAND.pos * 0

vp.scene.range = 1.5
vp.scene.autoscale = 0

# Let the user position obstacles:
SPHERES = []
for i in range(NSPHERES):
    S = vp.sphere(pos=vp.scene.mouse.getclick().pos, #(i*0.6 - 0.7, 0.5 + i*0.1, 0),
                  radius=0.25,
                  color=(abs(vp.sin(i)), vp.cos(i)**2, (i%10)/10.0))
    SPHERES.append(S)

while True:
    vp.rate(1.0 / DT)

    if vp.scene.mouse.clicked:
        i = len(SPHERES)
        S = vp.sphere(pos=vp.scene.mouse.getclick().pos,
                      radius=0.25,
                      color=(abs(vp.sin(i)), vp.cos(i)**2, (i%10)/10.0))
        SPHERES.append(S)

    if FLOOR:
        BELOW = vp.less(BAND.pos[:, 1], -1)
        BAND.p[:, 1] = vp.where(BELOW, 0, BAND.p[:, 1])
Exemple #5
0
print(__doc__)
# David Scherer

vp.scene.range = 3
PI = vp.pi
A = vp.convex(color=(0.5, 0, 0))
B = vp.convex(color=(0, 0.5, 0))
C = vp.convex(color=(0, 0, 0.5))
D = vp.convex(color=(0.5, 0, 0.5))
E = vp.convex(color=(0.5, 0.5, 0))
F = vp.convex(color=(0, 0.5, 0.5))

# circle
T = vp.arange(0, 2 * PI, 0.1)
E.pos = vp.transpose((vp.sin(T), vp.cos(T) + 2, 0 * T))

# triangle
T = vp.arange(0, 2 * PI, 2 * PI / 3)
F.pos = vp.transpose((vp.sin(T) - 2, vp.cos(T) + 2, 0 * T))

# disk
for T in vp.arange(0, 2 * PI, 0.1):
    A.append(pos=(vp.cos(T), 0, vp.sin(T)))
    A.append(pos=(vp.cos(T), 0.2, vp.sin(T)))

# box
for i in range(8):
    P = vp.vector((i / 4) % 2 - 2.5, (i / 2) % 2 - 0.5, (i) % 2 - 0.5)
    B.append(pos=P)
Exemple #6
0
DT = 0.00005  # energy constancy check fails for dt > 0.0003
T = 0.

C11 = (0.25 * M1 + M2) * L1**2 + I1
C22 = 0.25 * M2 * L2**2 + I2

#### For energy check:
##gdisplay(x=800)
##gK = gcurve(color=color.yellow)
##gU = gcurve(color=color.cyan)
##gE = gcurve(color=color.red)

while True:
    vp.rate(1 / DT)
    # Calculate accelerations of the Lagrangian coordinates:
    C12 = C21 = 0.5 * M2 * L1 * L2 * vp.cos(THETA1 - THETA2)
    CDET = C11 * C22 - C12 * C21
    A0 = .5 * M2 * L1 * L2 * vp.sin(THETA1 - THETA2)
    A = -(.5 * M1 + M2) * G * L1 * vp.sin(THETA1) - A0 * THETA2DOT**2
    B = -.5 * M2 * G * L2 * vp.sin(THETA2) + A0 * THETA1DOT**2
    ATHETA1 = (C22 * A - C12 * B) / CDET
    ATHETA2 = (-C21 * A + C11 * B) / CDET
    # Update velocities of the Lagrangian coordinates:
    THETA1DOT += ATHETA1 * DT
    THETA2DOT += ATHETA2 * DT
    # Update Lagrangian coordinates:
    DTHETA1 = THETA1DOT * DT
    DTHETA2 = THETA2DOT * DT
    THETA1 += DTHETA1
    THETA2 += DTHETA2
vp.scene.autocenter = True
vp.scene.width = 1024
vp.scene.height = 768

MOTOR_FRAME = vp.frame(axis=(0, 0, 1))  # Motor Frame
ROTOR_FRAME = vp.frame(frame=MOTOR_FRAME)  # Rotor Frame

# Create contactor
# First, draw the outer circle
G1 = vp.shapes.circle(radius=1.2)
NS = 24
# We will have 24 contactor surfaces, 2 per each rotor wiring
for i in range(NS):
    # Second, subtract rectangular pieces to get a slice for each contact surface
    t = vp.shapes.rectangle(
        pos=(1.2 * vp.cos(i * 2 * PI / NS), 1.2 * vp.sin(i * 2 * PI / NS)),
        width=2.1,
        height=0.05,
        rotate=i * 2 * PI / NS,
    )
    G1 = G1 - t

G1 = G1 - vp.shapes.circle(radius=0.5)  # Last, subtract rotor shaft
C1 = 2.0
# Now, extrude to get "cylindrical" contactor surfaces
GE1 = vp.extrusion(
    pos=[(0, 0, 0), (0, 0, C1)], shape=G1, color=(1, 0.5, 0.3), material=vp.materials.rough, frame=ROTOR_FRAME
)

# Create contactor soldering tips, same as above
G2 = vp.shapes.circle(radius=1.4)
DT = 0.00005 # energy constancy check fails for dt > 0.0003
T = 0.

C11 = (0.25*M1+M2)*L1**2+I1
C22 = 0.25*M2*L2**2+I2

#### For energy check:
##gdisplay(x=800)
##gK = gcurve(color=color.yellow)
##gU = gcurve(color=color.cyan)
##gE = gcurve(color=color.red)

while True:
    vp.rate(1/DT)
    # Calculate accelerations of the Lagrangian coordinates:
    C12 = C21 = 0.5*M2*L1*L2* vp.cos(THETA1-THETA2)
    CDET = C11*C22-C12*C21
    A0 = .5*M2*L1*L2* vp.sin(THETA1-THETA2)
    A = -(.5*M1+M2)*G*L1* vp.sin(THETA1)-A0*THETA2DOT**2
    B = -.5*M2*G*L2* vp.sin(THETA2)+A0*THETA1DOT**2
    ATHETA1 = (C22*A-C12*B)/CDET
    ATHETA2 = (-C21*A+C11*B)/CDET
    # Update velocities of the Lagrangian coordinates:
    THETA1DOT += ATHETA1*DT
    THETA2DOT += ATHETA2*DT
    # Update Lagrangian coordinates:
    DTHETA1 = THETA1DOT*DT
    DTHETA2 = THETA2DOT*DT
    THETA1 += DTHETA1
    THETA2 += DTHETA2
Exemple #9
0
print(__doc__)
# David Scherer

vp.scene.range = 3
PI = vp.pi
A = vp.convex(color=(0.5, 0, 0))
B = vp.convex(color=(0, 0.5, 0))
C = vp.convex(color=(0, 0, 0.5))
D = vp.convex(color=(0.5, 0, 0.5))
E = vp.convex(color=(0.5, 0.5, 0))
F = vp.convex(color=(0, 0.5, 0.5))

# circle
T = vp.arange(0, 2*PI, 0.1)
E.pos = vp.transpose((vp.sin(T), vp.cos(T)+2, 0*T))

# triangle
T = vp.arange(0, 2*PI, 2*PI/3)
F.pos = vp.transpose((vp.sin(T)-2, vp.cos(T)+2, 0*T))

# disk
for T in vp.arange(0, 2*PI, 0.1):
    A.append(pos=(vp.cos(T), 0, vp.sin(T)))
    A.append(pos=(vp.cos(T), 0.2, vp.sin(T)))

# box
for i in range(8):
    P = vp.vector((i/4)%2 - 2.5, (i/2)%2 - 0.5, (i)%2 - 0.5)
    B.append(pos=P)
Exemple #10
0
# Create the stringy thing:
BAND = vp.curve(x=vp.arange(-1, 1, RESTLENGTH), y=1, radius=0.02)

BAND.p = BAND.pos * 0

vp.scene.range = 1.5
vp.scene.autoscale = 0

# Let the user position obstacles:
SPHERES = []
for i in range(NSPHERES):
    S = vp.sphere(
        pos=vp.scene.mouse.getclick().pos,  #(i*0.6 - 0.7, 0.5 + i*0.1, 0),
        radius=0.25,
        color=(abs(vp.sin(i)), vp.cos(i)**2, (i % 10) / 10.0))
    SPHERES.append(S)

while True:
    vp.rate(1.0 / DT)

    if vp.scene.mouse.clicked:
        i = len(SPHERES)
        S = vp.sphere(pos=vp.scene.mouse.getclick().pos,
                      radius=0.25,
                      color=(abs(vp.sin(i)), vp.cos(i)**2, (i % 10) / 10.0))
        SPHERES.append(S)

    if FLOOR:
        BELOW = vp.less(BAND.pos[:, 1], -1)
        BAND.p[:, 1] = vp.where(BELOW, 0, BAND.p[:, 1])
Exemple #11
0
    def trace3D(self):
        """Give a 3D representation of the traceroute.
        right button: rotate the scene
        middle button: zoom
        left button: move the scene
        left button on a ball: toggle IP displaying
        ctrl-left button on a ball: scan ports 21,22,23,25,80 and 443 and display the result"""
        trace = self.get_trace()
        import visual

        class IPsphere(visual.sphere):
            def __init__(self, ip, **kargs):
                visual.sphere.__init__(self, **kargs)
                self.ip=ip
                self.label=None
                self.setlabel(self.ip)
            def setlabel(self, txt,visible=None):
                if self.label is not None:
                    if visible is None:
                        visible = self.label.visible
                    self.label.visible = 0
                elif visible is None:
                    visible=0
                self.label=visual.label(text=txt, pos=self.pos, space=self.radius, xoffset=10, yoffset=20, visible=visible)
            def action(self):
                self.label.visible ^= 1

        visual.scene = visual.display()
        visual.scene.exit_on_close(0)
        start = visual.box()
        rings={}
        tr3d = {}
        for i in trace:
            tr = trace[i]
            tr3d[i] = []
            ttl = tr.keys()
            for t in range(1,max(ttl)+1):
                if t not in rings:
                    rings[t] = []
                if t in tr:
                    if tr[t] not in rings[t]:
                        rings[t].append(tr[t])
                    tr3d[i].append(rings[t].index(tr[t]))
                else:
                    rings[t].append(("unk",-1))
                    tr3d[i].append(len(rings[t])-1)
        for t in rings:
            r = rings[t]
            l = len(r)
            for i in range(l):
                if r[i][1] == -1:
                    col = (0.75,0.75,0.75)
                elif r[i][1]:
                    col = visual.color.green
                else:
                    col = visual.color.blue
                
                s = IPsphere(pos=((l-1)*visual.cos(2*i*visual.pi/l),(l-1)*visual.sin(2*i*visual.pi/l),2*t),
                             ip = r[i][0],
                             color = col)
                for trlst in tr3d.values():
                    if t <= len(trlst):
                        if trlst[t-1] == i:
                            trlst[t-1] = s
        forecol = colgen(0.625, 0.4375, 0.25, 0.125)
        for trlst in tr3d.values():
            col = forecol.next()
            start = (0,0,0)
            for ip in trlst:
                visual.cylinder(pos=start,axis=ip.pos-start,color=col,radius=0.2)
                start = ip.pos
        
        movcenter=None
        while 1:
            if visual.scene.kb.keys:
                k = visual.scene.kb.getkey()
                if k == "esc":
                    break
            if visual.scene.mouse.events:
                ev = visual.scene.mouse.getevent()
                if ev.press == "left":
                    o = ev.pick
                    if o:
                        if ev.ctrl:
                            if o.ip == "unk":
                                continue
                            savcolor = o.color
                            o.color = (1,0,0)
                            a,b=sendrecv.sr(IP(dst=o.ip)/TCP(dport=[21,22,23,25,80,443]),timeout=2)
                            o.color = savcolor
                            if len(a) == 0:
                                txt = "%s:\nno results" % o.ip
                            else:
                                txt = "%s:\n" % o.ip
                                for s,r in a:
                                    txt += r.sprintf("{TCP:%IP.src%:%TCP.sport% %TCP.flags%}{TCPerror:%IPerror.dst%:%TCPerror.dport% %IP.src% %ir,ICMP.type%}\n")
                            o.setlabel(txt, visible=1)
                        else:
                            if hasattr(o, "action"):
                                o.action()
                elif ev.drag == "left":
                    movcenter = ev.pos
                elif ev.drop == "left":
                    movcenter = None
            if movcenter:
                visual.scene.center -= visual.scene.mouse.pos-movcenter
                movcenter = visual.scene.mouse.pos