Exemplo n.º 1
0
def step_impl(context):
    context.v = Vector(4, -4, 3)
Exemplo n.º 2
0
def step_impl(context):
    assert cross(context.a, context.b) == Vector(-1, 2, -1)
Exemplo n.º 3
0
def step_impl(context):
    assert cross(context.b, context.a) == Vector(1, -2, 1)
Exemplo n.º 4
0
def step_impl(context):
    context.a = Vector(1, 2, 3)
Exemplo n.º 5
0
def step_impl(context):
    context.b = Vector(2, 3, 4)
Exemplo n.º 6
0
def step_impl(context):
    context.v2 = Vector(5, 6, 7)
Exemplo n.º 7
0
def step_impl(context):
    assert context.v.normal == Vector(0.26726, 0.53452, 0.80178)
Exemplo n.º 8
0
def step_impl(context):
    context.v = Vector(-1, -2, -3)
Exemplo n.º 9
0
def step_impl(context):
    context.v = Vector(4, 0, 0)
Exemplo n.º 10
0
def step_impl(context):
    assert context.zero - context.v == Vector(-1, 2, -3)
Exemplo n.º 11
0
def step_impl(context):
    context.v = Vector(0, 1, 0)
Exemplo n.º 12
0
def step_impl(context):
    context.v = Vector(1, -2, 3)
Exemplo n.º 13
0
def step_impl(context):
    context.zero = Vector(0, 0, 0)
Exemplo n.º 14
0
def step_impl(context):
    assert context.v1 - context.v2 == Vector(-2, -4, -6)
Exemplo n.º 15
0
    gravity: Vector
    wind: Vector

    def __init__(self, gravity: Vector, wind: Vector):
        self.gravity = gravity
        self.wind = wind


def tick(proj: Projectile, env: Environment):
    position = proj.position + proj.velocity
    velocity = proj.velocity + env.gravity + env.wind
    return Projectile(position, velocity)


start = Point(0, 1, 0)
velocity = Vector(1, 1.8, 0).normal * 11.25
p = Projectile(start, velocity)

gravity = Vector(0, -0.1, 0)
wind = Vector(-0.01, 0, 0)

e = Environment(gravity, wind)

c = Canvas(900, 550)
color = Color(1.0, 0, 0)

while p.position.y >= 0:
    c.set_pixel(int(p.position.x), 500 - int(p.position.y), color)
    p = tick(p, e)

print(c.ppm)
Exemplo n.º 16
0
def step_impl(context):
    print(context.v.normal)
    assert context.v.normal == Vector(1, 0, 0)
Exemplo n.º 17
0
class Projectile:
    position: Point
    velocity: Vector

    def __init__(self, position: Point, velocity: Vector):
        self.position = position
        self.velocity = velocity


class Environment:
    gravity: Vector
    wind: Vector

    def __init__(self, gravity: Vector, wind: Vector):
        self.gravity = gravity
        self.wind = wind


def tick(proj: Projectile, env: Environment):
    position = proj.position + proj.velocity
    velocity = proj.velocity + env.gravity + env.wind
    return Projectile(position, velocity)


p = Projectile(Point(0, 1, 0), Vector(1, 1, 0).normal)
e = Environment(Vector(0, -0.1, 0), Vector(-0.01, 0, 0))

while p.position.y >= 0:
    print(p.position)
    p = tick(p, e)
Exemplo n.º 18
0
def step_impl(context):
    context.v1 = Vector(3, 2, 1)