Ejemplo n.º 1
0
def mat_test(steps, fx, fy, mat_func):
    for d in range(steps):
        td.clear_plot(True)
        dx = fx(d, delta)
        dy = fy(d, delta)
        print(f"           by ({dx:2.4f}, {dy:2.4f})")
        m = mat_func(dx, dy)
        td.plot_points(xform_pt_list(m, myface_pt_list()), sizes, colors)
    input("\n<CR> to continue")
def funny_face(x, y):
    for r in range(0, -45, -5):
        td.clear_plot(True)
        rm = rotate_mat(r)
        t = trans_mat(x, y)
        cm = mat_mat(t, rm)
        td.plot_points(mat_pt_list(cm, myface_pt_list()), sizes, colors)
        
    for r in range(-45, 45, 5):
        td.clear_plot(True)
        rm = rotate_mat(r)
        t = trans_mat(x, y)
        cm = mat_mat(t, rm)
        td.plot_points(mat_pt_list(cm, myface_pt_list()), sizes, colors)
        
    for s in range(1, 11):
        td.clear_plot(True)
        scale = 1 + s/20
        sm = scale_mat(scale, scale)
        t = trans_mat(x, y)
        cm = mat_mat(t, sm)
        td.plot_points(mat_pt_list(cm, myface_pt_list()), sizes, colors)
        
    for s in range(1, 11):
        td.clear_plot(True)
        scale = 1.5 - s / 10
        sm = scale_mat(scale, scale)
        t = trans_mat(x, y)
        cm = mat_mat(t, sm)
        td.plot_points(mat_pt_list(cm, myface_pt_list()), sizes, colors)
    return m

def mat_pt_list(m, ptList):
    """ transform the entire ptList
    """
    return [mat_vec(m, v) for v in ptList]

"""
    Begin testing ...
"""

width = 800
height = 600
td.create_plot(width, height, True)
pts, sizes, colors = getMyFace()
td.plot_points(pts, sizes, colors)
input("A: Show the basic plot, <CR> to continue")

input("\nB: Mat_Mat Test: Scale first then rotate in 30 steps")
for i in range(0, 60, 2):
    td.clear_plot(True)
    r = rotate_mat(i)
    sx = 1 + i/2 * 0.01
    sy = 1 - 0.01 * i/2
    s = scale_mat(sx, sy)
    print(f"          scale: ({sx:3.2f}, {sy:3.2f})  then  rotate:{i:2}")
    cm = mat_mat(r, s)
    td.plot_points(mat_pt_list(cm, myface_pt_list()), sizes, colors)

input("\n<CR> to continue")
print("C: Mat_Mat Test: Rotate first then Scale in 30 steps")
def f(x, y):
    print(f"Left Mouse click: {x}, {y})")
    T = make_a_translation_matrix(x, y)
    new_pt_list = mat_vec_multiply(T, ptList)
    td.plot_points(new_pt_list, sizeList, colorList)
Ejemplo n.º 5
0
def lmb(x, y):
    print(f'Rotate first: Left mouse click at: {x:4.2f} and {y:4.2f}')
    td.clear_plot(True)
    tm = trans_mat(x, y)
    cm = mat_mat(tm, r)
    td.plot_points(mat_pt_list(cm, myface_pt_list()), sizes, colors)
Ejemplo n.º 6
0
def rmb(x, y):
    print(f'Translate first: Right mouse click at: {x:4.2f} and {y:4.2f}')
    td.clear_plot(True)
    tm = trans_mat(x, y)
    cm = mat_mat(r, tm)
    td.plot_points(mat_pt_list(cm, myface_pt_list()), sizes, colors)
"""

width = 800
height = 600
td.create_plot(width, height, True)


def xform_pt_list(m, ptlist):
    """ Transform a list of points
        ptlist: [  [x, y],  [x, y] ... ]
    """
    return [mat_vec(m, v) for v in ptlist]


pts, sizes, colors = getMyFace()
td.plot_points(pts, sizes, colors)
input("A: Show the basic plot, <CR> to continue")
# test translate matrix
steps = 30

print()
delta = 5
print(f"B: Translation Test: by ({delta}, {-delta/2}) in {steps} steps")
for d in range(steps):
    td.clear_plot(True)
    tx = d * delta
    ty = d * (-delta / 2)
    print(f"                 by ({tx:3.2f}, {ty:3.2f})")
    tm = trans_mat(tx, ty)
    td.plot_points(xform_pt_list(tm, myface_pt_list()), sizes, colors)
input("\n<CR> to continue")
Ejemplo n.º 8
0
##
## V2: defines this function for testing all three of the matrices
##
def mat_test(steps, fx, fy, mat_func):
    for d in range(steps):
        td.clear_plot(True)
        dx = fx(d, delta)
        dy = fy(d, delta)
        print(f"           by ({dx:2.4f}, {dy:2.4f})")
        m = mat_func(dx, dy)
        td.plot_points(xform_pt_list(m, myface_pt_list()), sizes, colors)
    input("\n<CR> to continue")


pts, sizes, colors = getMyFace()
td.plot_points(pts, sizes, colors)
input("A: Show the basic plot, <CR> to continue")
# test translate matrix
steps = 30

print()
delta = 5
print(f"B: Translation Test: by ({delta}, {-delta/2}) in {steps} steps")
mat_test(
    steps,  # steps
    lambda d, delta: d * delta,  # compute dx
    lambda d, delta: d * (-delta / 2),  # compute dy
    trans_mat  # which matrix function to test
)

sx = 0.01
import sys
sys.path.append('./Lib')  # this is where all the library files are

import math
import turtle_draw as td
import MyFace as mf
""" Matrix Utilities
"""


def dot_vector(v1, v2):
    return sum(a * b for a, b in zip(v1, v2))


""" Begin drawing
"""
print()
print("Simple face plot with axis")
w = 800
h = 600
td.create_plot(w, h, True)  # show the axis
ptList, sizeList, colorList = mf.getMyFace()
td.plot_points(ptList, sizeList, colorList)


def f(x, y):
    print("Left Mouse click: x, y)")


td.turtle_draw_mouse_click(f, 1)
"""
    Begin testing ...
"""

print("A: verify mat-mat function")
m1 = [[1, 2, 3], [2, 3, 4], [5, 6, 7]]
m2 = [[3, 4, 5], [1, 2, 3], [8, 9, 10]]
print("m1=", m1)
print("m2=", m2)
print("mat_mat(m1, m2):", mat_mat(m1, m2))

width = 800
height = 600
td.create_plot(width, height, True)

pts, sizes, colors = getMyFace()
input("\nB: Show the basic plot, <CR> to continue")
td.plot_points(pts, sizes, colors)

input("\nC: Transform by cm = T(200, -100) * R(45)")
td.clear_plot(True)
rm = rotate_mat(45)
tm = trans_mat(200, -100)
m = mat_mat(tm, rm)
td.plot_points(mat_pt_list(m, pts), sizes, colors)

input("\nD: Transform by cm = R(45) * T(200, -100)")
td.clear_plot(True)
m = mat_mat(rm, tm)
td.plot_points(mat_pt_list(m, pts), sizes, colors)
def draw_at(x, y):
    print(f'Left mouse click at: {x:4.2f} and {y:4.2f}')
    td.clear_plot()
    t = trans_mat(x, y)
    newpts = mat_pt_list(t, ptList)
    td.plot_points(newpts, sizeList, colorList)
def draw_pts(p):
    td.clear_plot(True)
    td.plot_points(p, sizes, colors)