def step_impl(context): context.v = Vector(4, -4, 3)
def step_impl(context): assert cross(context.a, context.b) == Vector(-1, 2, -1)
def step_impl(context): assert cross(context.b, context.a) == Vector(1, -2, 1)
def step_impl(context): context.a = Vector(1, 2, 3)
def step_impl(context): context.b = Vector(2, 3, 4)
def step_impl(context): context.v2 = Vector(5, 6, 7)
def step_impl(context): assert context.v.normal == Vector(0.26726, 0.53452, 0.80178)
def step_impl(context): context.v = Vector(-1, -2, -3)
def step_impl(context): context.v = Vector(4, 0, 0)
def step_impl(context): assert context.zero - context.v == Vector(-1, 2, -3)
def step_impl(context): context.v = Vector(0, 1, 0)
def step_impl(context): context.v = Vector(1, -2, 3)
def step_impl(context): context.zero = Vector(0, 0, 0)
def step_impl(context): assert context.v1 - context.v2 == Vector(-2, -4, -6)
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)
def step_impl(context): print(context.v.normal) assert context.v.normal == Vector(1, 0, 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)
def step_impl(context): context.v1 = Vector(3, 2, 1)