CMPS 160 -- Lab Assignment 2
Due date:
Midnight, Friday, April 10, 2015
Objectives:
Create a triangle primitive and play with interaction with buttons.
Description
-
Organize your lab1 javascript code so that you now have a triangle function that draws
a single triangle wireframe given 3 vertices, using a predefined color.
-
You will use your new triangle drawing primitive in 2 ways:
(a) draw random triangles, and (b) create recursively subdivided triangles.
-
Random Triangles:
-
Create a button called "Random" so that each time it is pressed,
the display is cleared and 10 triangles are displayed.
-
Use the random number generator to generate coordinates for each of the
triangle vertex.
-
Subdivided Triangles:
-
Create another button called "Subdivide" so that each time it is pressed,
the triangle(s) are subdivided and displayed.
-
The first time this button is pressed, a single triangle is drawn.
The coordinates may either be hardwired or generated randomly.
-
Each successive presses of this button, will subdivide each of the current
set of triangles into 4 triangles using the following strategy.
To subdivide a triangle into 4, find the midpoint along each edge of the triangle.
Use these 3 new points as vertices for a new triangle.
The other three triangles will use one of the existing vertex, and 2 of the new vertices
as their vertices.
-
Button States:
-
If the display is currently showing subdivided triangles and the "Random" button is
pressed, it will simply throw away the subdivided triangles and generate 10 new random triangles.
-
If the display is currently showing random triangles and the "Subdivide" button is
pressed, it will throw away the last set of 10 random triangles, and display a single new triangle.
-
If the display is currently showing a single triangle or more subdivided triangles,
and the "Subdivide" button is pressed,
then new triangles are added to the set of subdivided triangles.
-
One way to do this is keep track of the last "state" of the button press.
That is, remember whether it was "Random" or "Subdivide".
This idea of a "state" is also used in the OpenGL / WebGL API.
Grading:
This lab assignment will form part of your CMPS 160L grade.
The other component of CMPS 160L grade is your attendance.
Comments (header block and inline comments for javascript) will account for 20% of grade.
Remaining 80% for functionality, split 50-50 between random and subdivided triangles.
The header block should contain at least the following information:
name, cruzid, date, and brief description of your program.
This will be true for all future assignments and programs.
Rubric:
5 comment block
5 separation of javascript from html
10 inline comments
40 random triangles and button events
40 subdivided triangles and button events
Who graded your assignment:
matthew : ahosick -- jbernay
jiayu: jchen160 -- tmlinejo
Submission:
Submission must be done using the "submit" command from CATS.
- submit cmps160-ap.s15 lab2 lab2.tar, or
- submit cmps160-ap.s15 lab2 lab2.zip
This command should work from unix.ic.ucsc.edu.
Create and submit a subdirectory called lab2.
It should contain
all the files necessary for this program run.
Tar or zip up lab2 before submitting.
Last modified
Sunday, 05-Apr-2015 18:25:24 PDT.