#!/usr/bin/env python import sys import os import math sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from pyTracer.canvas import canvas from pyTracer.util import color, Tuple, vector, point from pyTracer.transforms import * c = canvas(400, 400) # c.x_offset = 200 # center it # c.y_offset = 200 # center it p = point(1, 0, 0) r = rotation_z(math.pi / 6) s = scaling(100, 10, 10) t = translation(200, 200) p = t * s * p for i in range(12): c.pset(p, color(1, 0, 0)) p = r * p c.save("clock.ppm")
def step_impl(context): assert all([x == color(0, 0, 0) for x in context.c.data])
def step_impl(context): context.red = color(1, 0, 0)
def step_impl(context): assert context.c1 * context.c2 == color(0.9, 0.2, 0.04)
class env: def __init__(self, gravity, wind): self.gravity = gravity self.wind = wind class proj: def __init__(self, position, velocity): self.position = position self.velocity = velocity def tick(e, p): position = p.position + p.velocity velocity = p.velocity + e.gravity + e.wind return proj(position, velocity) c = canvas(900, 500) p = proj(point(0, 1, 0), vector(1, 1.8, 0).normalize() * 11.25) e = env(vector(0, -0.1, 0), vector(-0.01, 0, 0)) for i in range(0, 200): p = tick(e, p) print(p.position, p.velocity) c.set(int(p.position.x), c.height - int(p.position.y), color(1, 0, 0)) c.save("test.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.c1 = color(0.9, 0.6, 0.75)
def step_impl(context): context.c = color(-0.5, 0.4, 1.7)