Programming Project #1 - Programming in C#

In this short assignment you will have two tasks to accomplish within the context of the ConcentricCircles program we developed in class.

  • Add a new button "Draw Colors" which, rather than drawing the circles in predetermined colors, randomly chooses a color for each circle.
  • Add a new button "Spiro" which not only chooses a random color, but also chooses random positions and sizes for the circles.

    If you have any questions - please see me in office hours, or send me e-mail at egolubUMD@gmail.com.



    Draw Colors
    Add a new button to your form, have it display "Draw Colors" on it. Add a Click event handler into which you will add a copy of the code that you have in your existing event handler for the "Draw" button. We've seen how to randomly generate red/green/blue channel values, and how to use them to create a new color. For this task you will need to create a new Pen using that color. The following will allow you to create a new Pen inside the loop, which you can then use in the call to the DrawEllipse() method.

           Pen myPen = new Pen(Color.FromArgb(red,green,blue));
    
    Experiment with different numbers of concentric circles to see whether the Moire effect is impacted by using multiple colors rather than a single color.



    Spiro
    Add a new button to your form, have it display "Spiro" on it. Add a Click event handler into which you will add a new code which will have many things in common with the code from the "Draw" button's Click event handler. For this task, rather than having a loop that helps determine the size and position of the ellipse, the loop will just act as a way of counting from 1 to the number of circles you want to draw. Within the loop, randomly generate an x and a y coordinate for the upper-left corner of the ellipse's bounding rectangle, and then randomly generate a width and height for the bounding rectangle. Finally, draw an ellipse within that rectangle. You should have at least 8 ellipses drawn.



    Optional Stage just for fun
    So far you have had to go into the program code to change the number used within the loop (ie: how big the increment should be when drawing the concentric circles, or how many circles the spirograph should contain). There is an object called NumericUpDown that you can add to your form to allow the user to set the number that is then used. You can add a NumericUpDown object to your form in the same manner as we added the PictureBox and the Button objects. Once you have added it to the form, you should set the following three properties:

  • Minimum (the smallest integer that can be chosen)
  • Maximum (the largest integer than can be chosen)
  • Value (the default value for the integer when the program starts)



    Submitting
    To submit the project, make sure that your names are in the program as comments (if you type // at the start of a line, the rest of that line is treated as a comment). Create a ZIP file of the entire project folder, and you will upload it to the submit.cs.umd.edu server.

    You need to have this submitted before December 5th. I would encourage you to aim to have it done sooner.




    Web Accessibility