Beispiel #1
0
from workbench import Workbench
from e3ga import *
from math import exp, sqrt, pi

i = VectorE3(1, 0, 0)
j = VectorE3(0, 1, 0)
k = VectorE3(0, 0, 1)

f = 3 * i - 2 * j
g = 2 * j
h = i + j

scene = CartesianSpace()

probeR = ProbeBuilderE3().color("red").build()
scene.add(probeR.grade1)

probeG = ProbeBuilderE3().color("green").build()
scene.add(probeG.grade1)

probeB = ProbeBuilderE3().color("blue").build()
scene.add(probeB.grade1)

probeY = ProbeBuilderE3().color("yellow").build()
scene.add(probeY.grade1)

probeC = ProbeBuilderE3().color("cyan").build()
scene.add(probeC.grade1)

workbench = Workbench(scene.renderer, scene.camera)
Beispiel #2
0
This lesson demonstrates adding a keyboard handler.
We respond to the Escape key in order to end the animation prematurely.
'''
from browser import document, WindowAnimationRunner
from geometry import CartesianSpace, SphereBuilder
from math import cos, sin, pi
from workbench import Workbench3D

T = 5
omega = 2 * pi / T
R = 4

space = CartesianSpace()

sphere = SphereBuilder().color(0x0000FF).radius(0.2).build()
space.add(sphere)

workbench = Workbench3D(space.renderer.domElement, space.renderer,
                        space.camera)

timeOut = 10


def tick(t):
    sphere.position.set(R * cos(omega * t), R * sin(omega * t), 0)
    space.render()


def terminate(time):
    # The animation ends when the time is greater than the timeOut.
    # The animation may be ended prematurely by changing the timeOut value.
Beispiel #3
0
This lesson demonstrates adding a keyboard handler.
We respond to the Escape key in order to end the animation prematurely.
'''
from browser import document, WindowAnimationRunner
from geometry import CartesianSpace, SphereBuilder
from math import cos, sin, pi
from workbench import Workbench3D

T = 5
omega = 2 * pi / T
R = 4

space = CartesianSpace()

sphere = SphereBuilder().color(0x0000FF).radius(0.2).build()
space.add(sphere)

workbench = Workbench3D(space.renderer.domElement, space.renderer, space.camera)

timeOut = 10

def tick(t):
    sphere.position.set(R * cos(omega*t), R * sin(omega*t), 0)
    space.render()

def terminate(time):
    # The animation ends when the time is greater than the timeOut.
    # The animation may be ended prematurely by changing the timeOut value.
    done = time > timeOut
    return done
Beispiel #4
0
def magnitude(v):
    return sqrt(v.x * v.x + v.y * v.y)


def attitude(v):
    a = VectorE3(0, 0, 1)
    b = VectorE3(v.x, v.y, 0) / magnitude(v)
    numer = 1 + b * a
    denom = ScalarE3(sqrt(2 + (a % b)))
    R = numer / denom
    return R


arrowF = ArrowBuilder().scale(magnitude(f)).attitude(
    attitude(f)).color("red").build()
scene.add(arrowF)
arrowF.position.set(f.x / 2.0, f.y / 2.0, 0.0)

arrowH = ArrowBuilder().scale(magnitude(h)).attitude(
    attitude(h)).color("magenta").build()
scene.add(arrowH)
arrowH.position.set(h.x / 2, h.y / 2, 0)

workbench = Workbench(scene.renderer, scene.camera)


def tick(t):
    scene.render()


def terminate(t):
Beispiel #5
0
scene = CartesianSpace()

def magnitude(v):
    return sqrt(v.x * v.x + v.y * v.y)

def attitude(v):
    a = VectorE3(0, 0, 1)
    b = VectorE3(v.x, v.y, 0) / magnitude(v)
    numer = 1 + b * a
    denom = ScalarE3(sqrt(2 + (a % b)))
    R = numer / denom
    return R

arrowF = ArrowBuilder().scale( magnitude(f) ).attitude( attitude(f) ).color("red").build()
scene.add(arrowF)
arrowF.position.set(f.x / 2.0, f.y / 2.0, 0.0)

arrowH = ArrowBuilder().scale( magnitude(h) ).attitude( attitude(h) ).color("magenta").build()
scene.add(arrowH)
arrowH.position.set(h.x/2,h.y/2,0)

workbench = Workbench(scene.renderer, scene.camera)

def tick(t):
    scene.render()

def terminate(t):
    done = t > 16
    return done
Beispiel #6
0
from workbench import Workbench
from e3ga import *
from math import exp, sqrt, pi

i = VectorE3(1, 0, 0)
j = VectorE3(0, 1, 0)
k = VectorE3(0, 0, 1)

f = 3 * i - 2 * j
g = 2 * j
h = i + j

scene = CartesianSpace()

probeR = ProbeBuilderE3().color("red").build()
scene.add(probeR.grade1)

probeG = ProbeBuilderE3().color("green").build()
scene.add(probeG.grade1)

probeB = ProbeBuilderE3().color("blue").build()
scene.add(probeB.grade1)

probeY = ProbeBuilderE3().color("yellow").build()
scene.add(probeY.grade1)

probeC = ProbeBuilderE3().color("cyan").build()
scene.add(probeC.grade1)

workbench = Workbench(scene.renderer, scene.camera)
Beispiel #7
0
scene = CartesianSpace()

def magnitude(v):
    return sqrt(v.x * v.x + v.y * v.y)

def attitude(v):
    a = VectorE3(0.0, 0.0, 1.0)
    b = VectorE3(v.x, v.y, 0.0) / sqrt(v.quadrance())
    numer = 1 + b * a
    denom = sqrt(2 + (a % b))
    R = numer / denom
    return R

arrowF = ArrowBuilder().name("f").scale( magnitude(f) ).attitude( attitude(f) ).color(0xFF0000).build()#.axis(f.x, f.y, 0).build()
scene.add(arrowF)
arrowF.position.set(f.x/2,f.y/2,0)

arrowG = ArrowBuilder().name("g").scale( magnitude(g) ).attitude( attitude(g) ).color(0x0000FF).build()#.axis(f.x, f.y, 0).build()
scene.add(arrowG)
arrowG.position.set(g.x/2,g.y/2,0)

workbench = Workbench(scene.renderer, scene.camera)

def tick(t):
    scene.render()

def terminate(t):
    done = t > 4
    return done
space3D = CartesianSpace()
i = VectorE3(1.0, 0.0, 0.0)
j = VectorE3(0.0, 1.0, 0.0)
k = VectorE3(0.0, 0.0, 1.0)
I = i * j * k

workbench3D = Workbench3D(space3D.renderer.domElement, space3D.renderer,
                          space3D.camera)

particle = SphereBuilder().color("red").radius(0.1).build()
particle.charge = ScalarE3(1.0)
particle.mass = ScalarE3(1.0)
particle.position = VectorE3(0.0, 1.0, 0.0)
particle.velocity = VectorE3(0.0, -1.0, 0.0)
space3D.add(particle)

# Probe to show the velocity of the particle.
probeV = ProbeBuilderE3().color(particle.material.color.getHex()).build()
space3D.add(probeV.grade1)

# Probe to show the magnetic field at the particle position.
probeB = ProbeBuilderE3().color(0x0000FF).build()
space3D.add(probeB.grade1)
space3D.add(probeB.grade2)

# Probe to show the Lorentz force on the charged particle.
probeF = ProbeBuilderE3().color(0xFFFF00).build()
space3D.add(probeF.grade1)

dt = 0.02
Beispiel #9
0
'''
This lesson demonstrates adding a simple object to a scene.
'''
from browser import WindowAnimationRunner
from geometry import CartesianSpace, SphereBuilder
from workbench import Workbench3D

scene = CartesianSpace()

# The object is created using the builder pattern.
sphere = SphereBuilder().color(0x0000FF).build()
# Once created, the object must be added to the scene in order to be rendered.
scene.add(sphere)

workbench = Workbench3D(scene.renderer.domElement, scene.renderer,
                        scene.camera)


def tick(t):
    scene.render()


def terminate(t):
    done = t > 4
    return done


def setUp():
    workbench.setUp()

Beispiel #10
0
'''
This lesson demonstrates adding a simple object to a scene.
'''
from browser import WindowAnimationRunner
from geometry import CartesianSpace, SphereBuilder
from workbench import Workbench3D

scene = CartesianSpace()

# The object is created using the builder pattern.
sphere = SphereBuilder().color(0x0000FF).build()
# Once created, the object must be added to the scene in order to be rendered.
scene.add(sphere)

workbench = Workbench3D(scene.renderer.domElement, scene.renderer, scene.camera)

def tick(t):
    scene.render()

def terminate(t):
    done = t > 4
    return done

def setUp():
    workbench.setUp()

def tearDown(e):
    workbench.tearDown()
    if e:
        print e