#!/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")
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.p = point(3,2,1)
def step_impl(context): assert context.p -context.v == point(-2,-4,-6)
def step_impl(context): context.p2 = point(5,6,7)