Courses‎ > ‎Computer Graphics‎ > ‎Dyrland-Weaver‎ > ‎


  • You must include a makefile for each assignment!
    • The makefile should invoke whatever is needed to compile and/or run your program. 
    • When I type make, I expect to have your program generate and display an image.
      • If you cannot get the image to display (either programmatically or via the display command line program), then your program should print the name of the image file created.
    • The image created should thoroughly test the assignment.
  • Every assignment (unless otherwise noted) will require both a github submission and an image gallery submission. Full credit will require both.
    • The gallery submission does not have to be the same as the test image generated when your code is tested.
  • All github submissions should be submodules in the correct period directory for the assignment. Please see the resources page for help on linking your own repository as a submodule.
    • You should maintain separate repositories for each assignment.
    • Submodule naming schema:
      • lastF0f1 
        • e.g. dyrland-weaverJo or konstantinovichSa or brooksPe
      • When working with a partner
        • lastF0f1_lastF0f1
        • e.g. brooksPe_dyrland-weaverJo
        • The first name should always be the earlier name alphabetically 
  • NEVER EVER EVER add image files to github
    • Adding image files will result in deductions
    • I will include a useful .gitignore file at the root of each assignment repository, if you want, copy it and rename it to .gitignore in your repo.
  • Gallery submissions should be made here:

Work 12: The End

posted May 28, 2019, 11:41 AM by JonAlf Dyrland-Weaver   [ updated Jun 13, 2019, 6:44 AM ]

Project Due: Friday, 6/14, 11:59PM

Your file must describe what features you have implemented  and any relevant MDL instructions.
  • Start your file with your name(s) and class period.
  • The have a succinct list of the features you have implemented, and any relevant MDL commands.
  • Provide more detailed descriptions below that list if needed.
Step 0
  • Create a GitHub repository for your project.
  • In the file put
    • Your Name(s) at the top
    • Your Team Name
    • List of features you plan to implement.
  • This is due 8am Monday morning (6/3).

For the final project, you are to add any features you'd like to your current graphics engine. Below are some good places to start (you may work on other features if you prefer, just talk to me about it first

  • Existing, MDL Commands/Features:
    • light
      • Add a light to the symbol table
      • When calculating diffuse and specular: loop through all the lights.
    • mesh
      • Use an external .obj file for polygons
      • Read up on the obj format here.
      • Find example files here.
      • Make sure you deal with .obj files that list quadrilateral faces instead of triangles.
    • set
      • Assign a value to a knob
    • saveknobs
      • Save current knob values to a list
    • tween
      • Produce an animation by going between two knob lists
    • shading
      • Use different shading techniques / calculating I more or less frequently.
      • As discussed in class, a hash table structure can be very helpful for dealing with vertex normals. If you are woking in c, check out uthash.
    • save_coordinate_system
      • Save a copy of the top of the stack to the symbol table
      • use this coordinate system when drawing shapes (extra argument required)
  • Additions to MDL that require changes to the language:
    • New primitive shapes
    • Change the behavior of vary
      • add a parameter to change how it calculates the change over time
      • Linear , Exponential, Logarithmic, Arbitrary equation, etc. 
    • Anti-aliasing / Super-sampling 
      • Reduce pixelated edges by calculating a higher resolution version of the image then reducing it to the intended size
    • Texture mapping
    • Using vary to move lights.

Work 11: Gettin' Giffy With It

posted May 19, 2019, 8:27 PM by JonAlf Dyrland-Weaver

Animation! Woohoo!

New MDL commands to implement:
  • frames
    • set the number of frames
  • basename
    • sets the basename for animation file saving
  • vary
    • vary the values for a knob between 2 values in a set range of frames
Animation Features:
  • The key animation commands are frames, basename and vary. You should proceed with animation code in 3 steps:
    • Go through the operations list and look for any of the three animation commands
      • Set frames and basename
      • Handle erros as needed
    • Go through the operations list a second time and look for the vary command
      • Populate a table that has an entry for each frame, and in each frame it has a value for each knob
        • When completed, the table should contain the correctly set values for each knob (perform the varying calculation)
        • In c, there is a struct vary_node defined in parser.h
        • In python, you could use a dictionary/list combination
        • Handle errors as needed
    • Perform the normal interpreting/drawing steps that are currently working, with the following additions if animation code is present. 
      • First, look at the table of knob values (set in the second step) and set each knob in the symbol table to the appropriate value.
      • Run the normal commands
      • At the end of the loop, save the current screen to a file, the file should have the basename followed by a number, so that animate will work correctly. 
        • I suggest you put all the animation frames in a subdirectory, so just append a directory name to the basename when saving files
        • in c, you can pad the beginning of a string with 0's using the following syntax (if x = 12):
          • sprintf (s, "%03d", x ) will set s to the string "012"
          • The 0 indicates that you are padding with 0, and the 3 indicates that if x is less that 3 digits in length the number will be padded with 0
        • python has similar functionality using python formatted strings
          • "%03d"%12  will give you "012"
      • When you are done with each frame loop, don't forget to reset the screen, origin stack and any other pieces of data that are specific to a given frame
  • Once you have all the files created, you can generate the animation using imagemagick's animate and convert commands:
    • animate
      • Will display multiple single image files in succession as a single animation, with a default frame rate of 100 frames per second, by using the -delay option, you can change the fps ( -delay x will set the frame rate to 100/x fps )
        • $ animate -delay 1.7 animations/orb*
      • Convert can, like animate, take a number of frames and animate them, but instead of displaying the animation, it will combine them into a single animated gif file. Note that the only image format that can use animation is gif.
        • $ convert -delay 10 animations/orb* orb.gif will create a single animated gif called orb.gif
    • In python and c, I've included a make_animation function in display.c/py that will generate the animation for you.
github clone link:

Work 10: More Delightful Labor

posted May 10, 2019, 9:03 AM by JonAlf Dyrland-Weaver

(MDL actually stands for Motion Description Language)

Before doing anything else, take a look at MDL.spec, it provides important information about the language structure.

There are many commands and features in MDL that we will not be using yet, you should ignore those for now.

Implement the following mdl commands:
  • push
    • push a copy of the current top of the origins stack onto the origins stack (a full copy, not just a reference to the current top)
  • pop
    • removes the top of the origins stack (nothing needs to be done with this data)
  • move/rotate/scale
    • create a translation/rotation/scale matrix and multiply the current top by it
    • do not try to use the optional arguments for these commands
  • box/sphere/torus
    • add a box/sphere/torus to a temporary polygon matrix, multiply it by the current top and draw it to the screen 
    • if a constants variable is present, use those for lighting, otherwise, use a default set.
    • ignore the optional variable at the end of the command.
  • constants
    • you actually don't need to do anything for this command, the semantic analyzer will already create a symbol table entry for the reflective constants.
  • line
    • add a line to a temporary edge matrix, multiply it by the current top and draw it to the screen
    • do not try to use the optional arguments for this command
  • save
    • save the screen to the provided file name
  • display
    • show the image
  • You only need to modify one of the following files (c/python):
    • C
      • my_main.c 
        • look at print_pcode.c, it is an ideal template to follow for my_main.c
      • mdl.y: there is a comment at the very bottom that you will need to check.
    • Python
github clone links:

Work 09: Providing Illumination

posted May 1, 2019, 7:05 AM by JonAlf Dyrland-Weaver

Due: 8am Monday 5/6

Implement the Phong Reflection model with flat shading. (Note: if you look up information online, do not confuse this with Phong Shading).
  • You should be calculating I once per polygon.
  • Remember to limit I to be in the range [0, 255]. You may not want to do this all at once at the end.
  • There are a lot of user-defined values in lighting calculation, eventually, we will to be able to set them in our scripts. For now, pass them around to the necessary functions, and set them in either your main/parser functions. This is modeled in the provided source code.
  • Once again, our robot friend is not a great test for lighting, boxes in general are not good since they have very few polygons. 
github link:

Work 08: Scanning For Signs of Life

posted Apr 10, 2019, 7:00 AM by JonAlf Dyrland-Weaver

Add scanline conversion and z-buffering to your graphics engine.
  • Parser Note:
    • In the previous assignment, I noted that the clear command was no longer needed, because we immediately clear the polygon/edge matrix after a shape is drawn. In order to test Scanline conversion on multiple shapes, a different version of clear is useful. Now, clear will clear the screen and zbuffer, allowing us to reset and test multiple shapes in the same script. 
    • I have added this command to the provided source code, but everyone should implement it.
  • Scanline conversion
    • Create a new function that handles the scanline conversion.
    • Call this in your draw_polygons function.
    • Make sure that you change color values for each triangle.
  • z-buffering
    • In the base files provided, I've added a z-buffer argument to the necessary functions, but have not done anything with it.
    • The z-buffer should only be modified in your plot function, or when clear_zbuffer is called.
    • You will need to calculate z values in both scanline_convert and draw_line.
      • Your z values are not limited to the integers.
GitHub repository:

Work 07: Let's see how your code stacks up to the competition

posted Apr 3, 2019, 6:33 AM by JonAlf Dyrland-Weaver   [ updated Apr 4, 2019, 6:02 AM ]

(I do not know who or  what the competition is)

Due: 8am Monday, 4/8

Note: If you are working in c, I have provided a basic stack library that you can use in the 66source repository

To implement a relative coordinate system... system, add/modify your current parser so it has the following behavior
  • push
    • push a copy of the current top of the coordinate system (cs) stack onto the cs stack (a full copy, not just a reference to the current top... I'm looking at you python people)
  • pop
    • removes the top of the cs stack (nothing needs to be done with this data)
  • move/rotate/scale
    • create a translation/rotation/scale matrix
    • multiply the current top of the cs stack by it
    • The ordering of multiplication is important here.
  • box/sphere/torus
    • add a box/sphere/torus to a temporary polygon matrix
    • multiply it by the current top of the cs stack
    • draw it to the screen
    • clear the polygon matrix 
  • line/curve/circle
    • add a line to a temporary edge matrix
    • multiply it by the current top
    • draw it to the screen (note a line is not a solid, so avoid draw_polygons)
  • save
    • save the screen with the provided file name
  • display
    • show the image
  • Also note that the identapply and clear commands no longer have any use
github clone link:

Work 06: If your shapes don't look solid, TRI a different ANGLE

posted Mar 21, 2019, 5:40 AM by JonAlf Dyrland-Weaver   [ updated Mar 29, 2019, 6:50 AM ]

Work Due: 8 am Monday 4/1

You must do the following things:
  1. Write correct, functioning code.
  2. Submit code that runs the provided testing script
  3. Upload an original picture to the gallery
The Drawing:
  • Create new functions to add a polygon to a matrix, and go through the matrix 3 points at a time to draw triangles.
    • You should have a new triangle matrix that exists alongside the edge matrix. The edge matrix should be used for the shapes that are exclusively 2d (lines, circles, splines), and the triangle matrix for our 3d shapes.
    • Anything aside from shape drawing that modifies/uses the edge matrix (apply, clear, display, save) should now modify/use the triangle matrix as well.
  • Modify add box, add sphere and add torus to add triangles instead of points.
  • Make sure the parser calls the draw_polygons functions when needed instead of draw_lines
  • More to come...
  • Vector math & Backface culling
    • Implement the following vector functions
      • Normalize a vector (provided as an array/list of 3 values)
      • Find the dot product of 2 vectors (provided as arrays/lists of 3 values)
      • Calculate the surface normal of a triangle in the polygon matrix (provided the polygon matrix and index.
      • Check out gmath.h/c or for headers and comments.
    • Implement Backface culling.

Github clone link

Work 05: 3/15

posted Mar 15, 2019, 6:47 AM by JonAlf Dyrland-Weaver   [ updated Mar 18, 2019, 7:27 AM ]

DUE: 8am Thursday 3/21

We will now begin to add 3d shapes (as points only) to our already simmering graphics stew.

You must do the following things:
  1. Write correct, functioning code.
  2. Create a script file
  3. Upload a new picture to the gallery
  • add the following commands to the parser
    • clear: clears the edge matrix of all points
      • c people: this is an incredibly simple operation that shouldn't involve futzing with any of the points in the edge matrix.
    • box: adds a rectangular prism (box) to the edge matrix - takes 6 parameters (x, y, z, width, height, depth)
    • sphere: adds a sphere to the edge matrix - takes 4 parameters (x, y, z, radius)
    • torus: adds a torus to the edge matrix - takes 5 parameters (x, y, z, radius1, radius2)
      • radius1 is the radius of the circle that makes up the torus
      • radius2 is the full radius of the torus (the translation factor). You can think of this as the distance from the center of the torus to the center of any circular slice of the torus.
  • To future-proof your code, you should split sphere/torus creation into 2 parts:
    • Generating only the points on the surface of the shape.
    • Adding the points to an edge matrix so that they can be drawn.
      • Eventually, this part will be changed to handle solid shapes, but the points part will stay the same.
  • You should actually add edges to draw the box.
  • For the sphere and torus, just add the points for each point on the surface, and an edge from it to a point 1 pixel away to make it easier to see.

Work 04: It's spring training, time to work on your curve.

posted Mar 8, 2019, 6:51 AM by JonAlf Dyrland-Weaver   [ updated Mar 12, 2019, 7:44 AM ]

DUE: 8am Wednesday, 3/13

It's time to add curves to the graphics engine. Everything will work as before, we will just have three more shapes to draw .

Add the following commands to the parser
  • circle: adds a circle to the edge matrix - takes 4 parameters (cx, cy, cz, r)
  • hermite: adds a hermite curve to the edge matrix - takes 8 parameters (x0, y0, x1, y1, rx0, ry0, rx1, ry1)
    • The curve is between points (x0, y0) and (x1, y1).
    • (rx0, ry0) and (rx1, ry1) are the rates of change at each endpoint
  • bezier: adds a bezier curve to the edge matrix - takes 8 parameters (x0, y0, x1, y1, x2, y2, x3, y3)
    • This curve is drawn between (x0, y0) and (x3, y3)
    • (x1, y1) and (x2, y2) are the control points for the curve.

github clone link:

Work 03: Transformations, More than Meets the Eye!

posted Feb 26, 2019, 6:49 AM by JonAlf Dyrland-Weaver

  1. Write code to work with transformation matrices:
    • create a translation matrix
    • create a scale matrix
    • create a rotation matrix about the x-axis
    • create a rotation matrix about the y-axis
    • create a rotation matrix about the z-axis
      • Note: The trig functions in python and c take radians as parameters, but you should assume degree input, make sure to convert or things won't look right.
  2. Modify your main routine so that it keeps track of:
    • A single edge matrix
    • A single master transformation matrix
  3. Create a parser that will interpret a script to be used to draw an image.
    • Each command is a single word without spaces in it, and if it takes arguments, the line after will contain the arguments, separated by spaces. For example, a line of the file might look like this:
      • line
      • 0 0 0 100 100 0
    • Here is the full list of commands:
      • line: add a line to the point matrix -  takes 6 arguemnts (x0, y0, z0, x1, y1, z1)
      • ident: set the transform matrix to the identity matrix
      • scale: create a scale matrix, then multiply the transform matrix by the scale matrix -  takes 3 arguments (sx, sy, sz)
      • move: create a translation matrix, then multiply the transform matrix by the translation matrix - takes 3 arguments (tx, ty, tz)
      • rotate: create a rotation matrix, then multiply the transform matrix by the rotation matrix - takes 2 arguments (axis theta)
      • apply: apply the current transformation matrix to the edge matrix
      • display: clear the screen, draw the lines of the point matrix to the screen, display the screen
      • save: clear the screen, draw the lines of the point matrix to the screen/frame save the screen/frame to a file - takes 1 argument (file name)\
  4. The included script tests the various transformations, it should be used when I run make. You still need to create your own image and submit it to the gallery. Please include your script code only when you upload code to the gallery, this way it will be easy for others to try out your pictures!
github link:

1-10 of 13