Esempio n. 1
0
def step_impl(context):
    context.v = Vector(4, -4, 3)
Esempio n. 2
0
def step_impl(context):
    assert cross(context.a, context.b) == Vector(-1, 2, -1)
Esempio n. 3
0
def step_impl(context):
    assert cross(context.b, context.a) == Vector(1, -2, 1)
Esempio n. 4
0
def step_impl(context):
    context.a = Vector(1, 2, 3)
Esempio n. 5
0
def step_impl(context):
    context.b = Vector(2, 3, 4)
Esempio n. 6
0
def step_impl(context):
    context.v2 = Vector(5, 6, 7)
Esempio n. 7
0
def step_impl(context):
    assert context.v.normal == Vector(0.26726, 0.53452, 0.80178)
Esempio n. 8
0
def step_impl(context):
    context.v = Vector(-1, -2, -3)
Esempio n. 9
0
def step_impl(context):
    context.v = Vector(4, 0, 0)
Esempio n. 10
0
def step_impl(context):
    assert context.zero - context.v == Vector(-1, 2, -3)
Esempio n. 11
0
def step_impl(context):
    context.v = Vector(0, 1, 0)
Esempio n. 12
0
def step_impl(context):
    context.v = Vector(1, -2, 3)
Esempio n. 13
0
def step_impl(context):
    context.zero = Vector(0, 0, 0)
Esempio n. 14
0
def step_impl(context):
    assert context.v1 - context.v2 == Vector(-2, -4, -6)
Esempio 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)
Esempio n. 16
0
def step_impl(context):
    print(context.v.normal)
    assert context.v.normal == Vector(1, 0, 0)
Esempio 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)
Esempio n. 18
0
def step_impl(context):
    context.v1 = Vector(3, 2, 1)