Exemplo n.º 1
0
#!/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")
Exemplo n.º 2
0
def step_impl(context):
    assert all([x == color(0, 0, 0) for x in context.c.data])
Exemplo n.º 3
0
def step_impl(context):
    context.red = color(1, 0, 0)
Exemplo n.º 4
0
def step_impl(context):
  assert context.c1 * context.c2 == color(0.9, 0.2, 0.04)
Exemplo n.º 5
0

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")
Exemplo n.º 6
0
def step_impl(context):
  context.c1 = color(1, 0.2, 0.4)
Exemplo n.º 7
0
def step_impl(context):
  context.c2 = color(0.9, 1, 0.1)
Exemplo n.º 8
0
def step_impl(context):
  context.c = color(0.2, 0.3, 0.4)
Exemplo n.º 9
0
def step_impl(context):
  assert context.c * 2 == color(0.4, 0.6, 0.8)
Exemplo n.º 10
0
def step_impl(context):
  assert context.c1 - context.c2 == color(0.2, 0.5, 0.5)
Exemplo n.º 11
0
def step_impl(context):
  assert  context.c1 + context.c2 == color(1.6, 0.7, 1.0)
Exemplo n.º 12
0
def step_impl(context):
  context.c2 = color(0.7, 0.1, 0.25)
Exemplo n.º 13
0
def step_impl(context):
  context.c1 = color(0.9, 0.6, 0.75)
Exemplo n.º 14
0
def step_impl(context):
  context.c = color(-0.5, 0.4, 1.7)