$25
1. Write down a Python program to:
A. Create a 1d array M with values ranging from 2 to 26 and print M.
B. Reshape M as a 5x5 matrix and print M.
C. Set the value of “inner” elements of the matrix M to 0 and print M.
D. Assign M2 to the M and print M.
E. Let’s call the first row of the matrix M a vector v. Calculate the magnitude of the vector v and print it.
i. Hint:
ii. Hint: Use np.sqrt()
F. Files to submit: A Python source file (Name the file whatever you want (in English). Extension should be .py)
Expected output:
2. Write down a Python program to draw a regular 12-sided polygon (dodecagon, 정12각형). A. Set the window title to your student ID and the window size to (480,480).
B. Use np.linspace() (or np.arrange()), np.cos(), np.sin() to compute the positions of vertices.
C. Do not hardcode the position of each vertex.
D. The 12 vertices should be specified counterclockwise starting from the vertex on the x-axis.
E. (Hint)
F. If the keys 1, 2, 3, … 9, 0 are entered, the primitive type should be changed.
i. Hint: Use a global variable to store the primitive type
Key
Primitive Type
1
GL_POINTS
2
GL_LINES
3
GL_LINE_STRIP
4
GL_LINE_LOOP
5
GL_TRIANGLES
6
GL_TRIANGLE_STRIP
7
GL_TRIANGLE_FAN
8
GL_QUADS
9
GL_QUAD_STRIP
10
GL_POLYGON