Assignment 1

Modified: 02/02/2006

This assignment assumes you have successfully completed assignment 0. Try to compile and run mouseDraw.c. You can do the following on the Edlab machines:

  1. Copy mouseDraw.c into your development directory:

  2. Compile and run mouseDraw.c:

    cd ~/cs591b/
    gcc mouseDraw.c -lSDL -o mouseDraw
    mouseDraw

  3. mouseDraw is a simple program that opens up a window with 640x480 pixels and leaves a randomly colored trail of pixels wherever you move your mouse. You should use the code in mouseDraw.c as a starting point for the rest of the assignment. In general, you should not need to modify the code outside of the region marked in the source code, but you are welcome to if you wish.

  4. Your first step should be to make sure you understand the code in the "modification" region. This code simply reads the state of the mouse, creates a random value representing the color of the next pixel, and draws a single pixel in the frame buffer.

  5. Your next job is to implement the following functions and programs.

    A) (10 points) Write a function to draw a line in the frame buffer. Its declaration should be

    void drawLine(int x1,int y1,int x2,int y2,int color);

    B) (10 points) Use this function to write another function for drawing a circle. Make sure the circle closes completely, or you may have problems with the next step. Your circle function should be declared as

    void drawCircle(int centerx,int centery,double radius,int color);

    C) (30 points) Write a function which, given a mouse click on a black region, will fill the region using the color of the shape that was clicked in. You may assume that the shape that was clicked in was drawn with a constant color. In other words, when the function is called, it will wait for a mouse click, and then fill the region starting from that point. The function should be declared as

    void fillShapeNativeColor();

    D) YOU SHOULD TURN IN a program named fillCircle.c which includes the drawLine function, the drawCircle function, the fillShapeNativeColor function, and any other functions you need to achieve this behavior. The program should draw a circle, then call fillShapeNativeColor and wait for the user to click in the circle, after which it should fill the circle.

    E) (50 points) WRITE A "SCREEN SAVER" called screenSaver.c. By "screen saver" I just mean a program which draws some sort of interesting patterns on the screen. The screen saver should incorporate at least the following properties:

    i) Use randomness in some way.

    ii) Vary color in some interesting way.

    iii) Use mouse movement or mouse clicks to influence what is drawn in a way that is obvious to the observer (namely me and Alex!)

You should turn in the two program files named above. Please put all of the functions necessary for each program in a single file with the names fillCircle.c and screenSaver.c.

Then email me the files by the due time.

Back to the course homepage