from visual import * from visual.text import * from numpy import * from numpy.linalg import * #Set background white color scene.background = (1,1,1) width = height = 10 #draw grids for i in list(range(-width, width)): curve(pos = [[i, -height],[i, height]], color = (0.8,0.8,0.8)) for j in list(range(-height, height)): curve(pos = [[-width, j],[width, j]],color = (0.8,0.8,0.8)) curve(pos = [[0, -height],[0, height]], radius = 0.1, color = (0,0,0)) curve(pos = [[-width, 0],[width, 0]], radius = 0.1, color = (0,0,0)) # Define a man man = array([[1,1,1], [0,0,1],[2,0,1],[1,1,1],[1,4,1],[1.5,4,1],[1.5,5,1],[0.5,5,1],[0.5,4,1],[1,4,1],[1,3,1],[0,2,1],[1,3,1],[2,2,1],[3,3,1]]) #1. Define a function drawman(man, c) which draw the man with c color def drawman(man, c): #2. Define a function T(man, tx, ty) which translate the man with [x,y] direction (Using dot(A,B) to multiple two matrices) def T(man, tx,ty): #3 Define a function S(man, sx, sy) which scale the man with [x,y] def S(man, sx, sy): #4 Define a function R(man,theta) which rotate the man counterwisely theta degree def R(man, theta): #5 Function call # 5.1 Draw the man with color black # 5.2 Translate the man by [2, 1],[-2,1], and draw them with color red # 5.3 Scale the man by [-1, 1], and draw it with color green # 5.4 Rotate the man by pi degree, and draw it with color blue