Programming Assign
Programming Assign
1. Using the PNGWriter class, write a program to create a PNG image (called image.png)
with dimensions 300 pixels by 300 pixels and containing a red primary diagonal line (top
left to bottom right) and a green secondary diagonal line (bottom left to top right), then
fill the lowest bounded quadrant in blue. 10 Marks
2. Given a 3-dimensional space which is defined by an 800 x 600 viewport and whose
coordinate axes have their origins at the center of the viewport, write the OpenGL (or
using any language you understand) program statements which will produce the
following effects:
Define a 3-dimensional equilateral triangle (a triangle pyramid) whose y-axis in
local space is located through the center of the triangle pyramid. The base of the
3D triangle may be aligned to the x-axis.
Transpose three (3) object instances of the 3-dimensional triangle (defined in part
(i) above) to global space, along the same z-plane, so that the left object is tilted
30 degrees left of the y-axis, the center object is aligned vertically with the y-axis
and the right object is tilted 30 degrees right of the y-axis as illustrated in the
figure below:
Hint: You may use a separate function to define the object in local space and call
that function in your display/render function to position the objects in world
space.
3. Using the concept of a Current Transformation Matrix (push/pop matrices), write the
OpenGL or using whichever language code to define the object as illustrated below. You
may assume that the object is composed of two squares and a circle of unit dimensions in
2D space.
4. Using the PNGWriter class, write a program which takes an existing image called
image.png and creates a second image called flipped.png as shown below, where
flipped.png is the result of flipping image.png both horizontally and vertically.
5. A quadratic B´ezier curve is defined by three points, P1, P2, P3, and a parameter, t:
Describe an algorithm that draws the quadratic B´ezier curve, using straight lines only, to
within a tolerance τ. You may use the algorithm from part (a) and you may assume that
you already have an algorithm for drawing a straight line
6. How are curves like the B´ezier curve and the B-spline curve useful? 2 Marks. Give an
application where a curve can be used as a reference. Write a program to carry out
subdivision of triangular or quadrilateral meshes. When the subdivision is working
correctly, add the averaging step to form a smoother surface.
7. You can generate a simple maze starting with a rectangular array of cells. Each cell has
four sides. You remove sides (except from the perimeter of all the cells) until all the cells
are connected. Then you create an entrance and an exit by removing two sides from the
perimeter. A simple example is shown in Figure below. Write a program using WebGL
or OPENGL or JAVA or any other programming language of your choice and
understanding that takes as input the two integers N and M and then draws an N × M
maze.
8. Implement the suggestion about displaying a rotating cube in the program. Add a button
that, when the cube is loaded, can update the locations of the cube vertices by computing
them with a new value of t, the amount to rotate. To make the animation look smooth, try
changing t by .05 radians per button click.
9. Write a program that displays an image consisting of parallel stripes, sitting above
another image that’s pure gray. Make the gray level adjustable (by slider, buttons,
keystrokes, or any other means you like). Stand far enough away that the stripes are
indistinguishable from one another, and adjust (or have a friend adjust) the gray level of
the solid rectangle until you say it matches the apparent gray of the stripes. Now move
toward the display screen until you can detect the stripes individually; measure your
distance from the display, and compute the angle subtended at your eye by a pair of
parallel stripes. You should make sure that you’re not fooling yourself by having the
display (after the press/click of a button) show either vertical or horizontal stripes next to
the gray rectangle (at random) and have the position of the stripes and the solid rectangle
exchanged or not (at random).
10. We can simulate many realistic effects using computer graphics by incorporating simple
physics in the model. Simulate a bouncing ball in two dimensions incorporating both
gravity and elastic collisions with a surface. You can model the ball with a closed
polygon that has a sufficient number of sides to look smooth.
11. Creating simple games is a good way to become familiar with interactive graphics
programming. Program the game of checkers. You can look at each square as an object
that can be picked by the user. You can start with a program in which the user plays both
sides.
12. Plotting packages offer a variety of methods for displaying data. Write an interactive
plotting application for two-dimensional curves. Your application should allow the user
to choose the mode (line strip or polyline display of the data, bar chart, or pie chart),
colors, and line styles.
13. Write a program that allows a user to play a simple version of solitaire. First, design a
simple set of cards using only our basic primitives. Your program can be written in terms
of picking rectangular objects.
14. The orientation of an airplane is described by a coordinate system as shown below. The
forward–backward motion of the joystick controls the up– down rotation with respect to
the axis running along the length of the airplane, called the pitch. The right–left motion of
the joystick controls the rotation about this axis, called the roll. Write a program that uses
the mouse to control pitch and roll for the view seen by a pilot. You can do this exercise
in two dimensions by considering a set of objects to be located far from the airplane, then
having the mouse control the two-dimensional viewing of these objects.
15. Circuit-layout programs are variants of paint programs. Consider the design of logical
circuits using the Boolean and, or, and not functions. Each of these functions is provided
by one of the three types of integrated circuits (gates),the symbols for which are shown in
Figure below. Write a program that allows the user to design a logical circuit by selecting
gates from a menu and positioning them on the screen. Consider methods for connecting
the outputs of one gate to the inputs of others.
16. Write a program to generate a Sierpinski gasket as follows. Start with a white triangle. At
each step, use transformations to generate three similar triangles that are drawn over the
original triangle, leaving the center of the triangle white and the three corners black.
17. The color gamut in chromaticity coordinates is equivalent to the triangle in RGB space
that is defined by the primaries. Write a program that will display this triangle and the
edges of the cube in which it lies. Each point on the triangle should have the color
determined by its coordinates in RGB space. This triangle is called the Maxwell triangle.
18. Write a program to generate the locations of pixels along a rasterized line segment using
Bresenham’s algorithm. Check that your program works for all slopes and all possible
locations of the endpoints. What is the initial value of the decision variable?
19. Another CAD application that can be developed in WebGL is a paint program. You can
display the various objects that can be painted—lines, rectangles, circles, and triangles,
for example—and use picking to select which to draw. The mouse can then enter vertex
data and select attributes such as colors from a menu. Write such an application.
20. Write a library of functions that will allow you to do geometric programming. Your
library should contain functions for manipulating the basic geometric types (points, lines,
vectors) and operations on those types, including dot and cross products. It should allow
you to change frames. You can also create functions to interface with WebGL so that you
can display the results of geometric calculations.
21. Write a program to generate a Sierpinski gasket as follows. Start with a white triangle. At
each step, use transformations to generate three similar triangles that are drawn over the
original triangle, leaving the center of the triangle white and the three corners black.
22. Write a program that allows you to orient the cube with one mouse button, to translate it
with a second, and to zoom in and out with a third.
23. Write a program that draws three black dots of radius 0.25 at x = 0, 1, 2 along the x-axis.
Then display instead three black dots at positions t, t + 1, and t + 2 (using t = 0. 25
initially). Make the display toggle back and forth between the two sets of dots, once
every quarter-second. Do you tend to see the dots as moving? What if you increase t to 0.
5? Include a slider that lets you adjust t from 0 to 3. Does the illusion of the dots moving
ever weaken? When t = 1, you could interpret the motion as “the outer dot jumps back
and forth from the far left (x = 0) to the far right (x = 3) while the middle two dots remain
fixed.” Can you persuade yourself that this is what you’re seeing? The strong impression
that the dots are moving as a group is remarkably hard to abandon, supporting the Gestalt
theory.
24. In animation, often we can save effort by working with two-dimensional patterns that are
mapped onto flat polygons that are always parallel to the camera, a technique known as
billboarding. Write a program that will keep a simple polygon facing the camera as the
camera moves.
25. Write a program to display a rotating cube in a box with three light sources. Each light
source should project the cube onto one of the three visible sides of the box.
26. The goal of this assignment is to introduce you to mesh representation,
curve/surface smoothing, and modeling. You will be creating a basic interactive
modeling program for generating smooth surfaces that allows a user to drag
vertices of a coarse control mesh in 3D while displaying an associated smooth
surface. You will be asked to implement aspects of both the user interface and the
subdivision algorithm, and finally use your program to construct several models.
Specifically, you will write a program that reads a set of triangle from a. ray file,
builds a "control" mesh from these triangles (shown in green above), and displays
it in a window using OpenGL. As the program executes, a user can subdivide the
control mesh (each press of the `S' key subdivides one level further) to produce a
smooth subdivision surface for display (shown in gray above). The user may also
drag vertices of the control mesh with the mouse while the corresponding finest
level of the subdivision surface is updated continuously in the display. To create
the smooth surface, we will be implementing the Loop subdivision scheme.
27. In this assignment you will animate motions for an articulated figure. You will be
given an articulated 3D model and sets of keyframes specifying the orientations of
articulated joints at specific time steps. Your job is to interpolate the keyframes
smoothly over a time interval and display the articulated figure in an OpenGL
window so that it performs animated actions (e.g., walks, dances, etc.) in real
time.
28. How are curves like the B´ezier curve and the B-spline curve useful? 2 Marks. Give an
application where a curve can be used as a reference. Write a program to carry out subdivision of
triangular or quadrilateral meshes. When the subdivision is working correctly, add the averaging
step to form a smoother surface.
29. At the lowest level of processing, we manipulate bits in the framebuffer. In WebGL or
any other language, we can create a virtual framebuffer in our application as a two
dimensional array. You can experiment with simple raster algorithms, such as drawing
lines or circles, through a function that generates a single value in the array. Write a small
library that will allow you to work in a virtual framebuffer that you create in memory.
The core functions should be WritePixel and ReadPixel. Your library should allow you to
set up and display your virtual framebuffer and to run a user program that reads and
writes pixels using gl.POINTS in gl.drawArrays.
30. Plotting packages offer a variety of methods for displaying data. Write an interactive
plotting application for two-dimensional curves. Your application should allow the user
to choose the mode (line strip or polyline display of the data, bar chart, or pie chart),
colors, and line styles.
31. Another CAD application that can be developed in WebGL or any language is a paint
program. You can display the various objects that can be painted—lines, rectangles,
circles, and triangles, for example—and use picking to select which to draw. The mouse
can then enter vertex data and select attributes such as colors from a menu. Write such an
application.
32. Write a program that allows you to orient the cube with one mouse button, to translate it
with a second, and to zoom in and out with a third.
33. Write a vertex shader that takes as input an angle and an axis of rotation and rotates
vertices about this axis.
34. In animation, often we can save effort by working with two-dimensional patterns that are
mapped onto flat polygons that are always parallel to the camera, a technique known as
billboarding. Write a program that will keep a simple polygon facing the camera as the
camera moves.
35. Write a program that will fly around above a mesh. Your program should allow the user
to look around at the hills and valleys rather than always looking at a single point.
36. With regard to framebuffer operations, you can start constructing a ray tracer using a
single routine of the form write_pixel(x, y, color) that places the value of color (either an
RGB color or an intensity) at the pixel located at (x, y) in the framebuffer. Write a
pseudocode routine ray that recursively traces a cast ray. You can assume that you have a
function available that will intersect a ray with an object. Consider how to limit how far
the original ray will be traced.
37. Write a program using mipmaps in which each mipmap is constructed from a different
image. Is there a practical application for such a program?
38. Write a simple circuit layout program in terms of a symbol–instance transformation table.
Your symbols should include the shapes for circuit elements such as resistors, capacitors,
and inductors for electrical circuits, or the shapes for various gates (and, or, not) for
logical circuits.
39. We can write a description of a binary tree, such as we might use for a search, as a list of
nodes with pointers to its children. Write a program that will take such a description and
display the tree graphically.
40. Robotics is only one example in which the parts of the scene show compound motion,
where the movement of some objects depends on the movement of other objects. Other
examples include bicycles (with wheels), airplanes (with propellers), and merry-go-
rounds (with horses). Pick an example of compound motion. Write a graphics program to
simulate your selection.
41. Write a program that will allow the user to construct simple articulated figures from a
small collection of basic shapes. Your program should allow the user to place the joints,
and it should animate the resulting figures.
42. Write a program that, given two polygons with the same number of vertices, will generate
a sequence of images that converts one polygon into the other.
43. If we use the basic formula that we used for the Mandelbrot set, but this time fix the
value of the complex number c and find the set of initial points for which we obtain
convergence, we have the Julia set for that c. Write a program to display Julia sets. Hint:
Use values of c near the edges of the Mandelbrot set.
44. Write a particle systemthat simulates the sparks that are generated by welding or by
fireworks.
45. Write a WebGL or using any other language program that will take as input a set of
control points and produce the interpolating, B-spline, and B´ezier curves for these data.
46. Write a program to generate a cubic B´ezier polynomial from an arbitrary number of
points entered interactively. The user should be able to manipulate the control points
interactively.
47. Write a program to carry out subdivision of triangular or quadrilateral meshes. When the
subdivision is working correctly, add the averaging step to form a smoother surface.