Starting from:

$30

Computer Graphics-Lab Assignment 3 Solved

1. Write down a Python program to draw a rotating triangle. 

A.     Set the window title to your student ID and the window size to (480,480). 

B.     Draw a triangle using render() function below (DO NOT modify it!). 

def render(T): 

     glClear(GL_COLOR_BUFFER_BIT)     glLoadIdentity()     # draw cooridnate     glBegin(GL_LINES)     glColor3ub(255, 0, 0)     glVertex2fv(np.array([0.,0.]))     glVertex2fv(np.array([1.,0.]))     glColor3ub(0, 255, 0)     glVertex2fv(np.array([0.,0.]))     glVertex2fv(np.array([0.,1.])) 

    glEnd() 

    # draw triangle glBegin(GL_TRIANGLES) 

    glColor3ub(255, 255, 255) 

    glVertex2fv( (T @ np.array([.0,.5,1.]))[:-1] )     glVertex2fv( (T @ np.array([.0,.0,1.]))[:-1] )     glVertex2fv( (T @ np.array([.5,.0,1.]))[:-1] )     glEnd() 

 

C.     Expected result: Uploaded LabAssignment3-1.mp4 

Key 
Transformation 

Scale by 0.9 times in y direction 

Scale by 1.1 times in y direction 

Rotate by 10 degrees counterclockwise 

Rotate by 10 degrees clockwise 

Translate by 0.1 in x direction 
                i.       Do not mind the initial angle of the triangle. 

D.     The triangle should be t rad rotated when t seconds have elapsed since the program was executed. 

E.      You need to somehow combine a rotation matrix and a translation matrix to produce the expected result. 

F.      Files to submit: A Python source file (Name the file whatever you want (in English). Extension should be .py) 

 

2. Write down a Python program to draw a transformed triangle. 

A.     Set the window title to your student ID and the window size to (480,480). 

B.     Draw a triangle using render() function of prob 1 (DO NOT modify it!). 

C.     If you press or repeat a key, the triangle should be transformed as shown in the Table: 


Translate by -0.1 in x direction 

Reflection across the origin 

Reset the triangle with identity matrix 
D.     Transformations should be accumulated (composed with previous one) unless you press ‘1’. 

i.          Be sure: gComposedM = newM @ gComposedM 

ii.         You’ll need to make ‘gComposedM’ as a global variable. 

E. Files to submit: A Python source file (Name the file whatever you want (in English). 

Extension should be .py) 

 

More products