Description
Requirements:
• Write a WebGL program that creates and visualizes a random triangle. Name your source code hw1.html
and hw1.js. The program should meet the following requirements:
– Set the title of the program to “hw1” (must appear on title bar).
– Set the background color to black.
– Create triangle vertices at 3 random locations. Create random coordinates so that each vertex may
possibly be positioned anywhere within canvas, but never outside.
– Create and assign 3 random colors for the 3 vertices. These 3 colors must be linearly interpolated within
the triangle.
– Use drawArrays function to visualize the triangle on canvas.
– Thus, every time you hit F5 (refresh) key, the canvas must display a new random triangle at a random
position, with random size and random color gradient (see Fig. 1 ∼ 2). The triangle vertices must never
go out of bounds.
Figure 1: Random triangle 1
1
Figure 2: Random triangle 2
What to submit:
• Submit all your source files (.html, .js) that are needed for compilation, including library files/folders. Missing library files/folders will lead to point deduction.
How to submit:
• Use Canvas Assignment Submission system to submit your source files.
• Make sure to zip all your files/folders into hw1.zip, then submit your hw1.zip as a single file.
Policy
• Do all the assignments on Chrome Development Tools using HTML, JavaScript, and GLSL ES.
• At the top of each source file, provide comments specifying the author, date, and a brief description of the file.
• Source code must contain enough comments here and there to make it easy enough to follow. Insufficient
comments could lead to point deduction.
• Incomplete program will get almost no credit (e.g., program does not run due to compile errors or program
terminates prematurely due to run-time errors).
• Thou shall not covet thy neighbor’s code. If identical (or nearly identical) submissions are found among
students, every student involved will get automatic zero for the assignment. The same goes for copying
existing code from online source.
• If a student makes multiple submissions, only the last submission will be considered valid.