def step_impl(context): context.c2 = Color(0, 0.5, 0)
def step_impl(context): context.red = Color(1, 0, 0)
def step_impl(context): context.c1 = Color(1.5, 0, 0)
def step_impl(context): for x in range(context.c.width): for y in range(context.c.height): context.c.set_pixel(x, y, Color(1, 0.8, 0.6))
def step_impl(context): for x in range(context.c.width): for y in range(context.c.height): assert context.c.get_pixel(x, y) == Color(0, 0, 0)
def step_impl(context): context.c1 = Color(0.9, 0.6, 0.75)
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): context.c1 = Color(1, 0.2, 0.4)
def step_impl(context): context.c2 = Color(0.9, 1, 0.1)
def step_impl(context): context.c = Color(0.2, 0.3, 0.4)
def step_impl(context): assert context.c * 2 == Color(0.4, 0.6, 0.8)
def step_impl(context): assert context.c1 - context.c2 == Color(0.2, 0.5, 0.5)
def step_impl(context): assert context.c1 + context.c2 == Color(1.6, 0.7, 1.0)
def step_impl(context): context.c2 = Color(0.7, 0.1, 0.25)
def step_impl(context): context.c3 = Color(-0.5, 0, 1)
def step_impl(context): assert context.c1 * context.c2 == Color(0.9, 0.2, 0.04)
def __init__(self, width: int, height: int): self._canvas = [[Color() for j in range(width)] for i in range(height)]
def step_impl(context): context.c = Color(-0.5, 0.4, 1.7)