Difference between revisions of "CSC103 Take-Home Final Exam Spring 2012"
(Created page with "<onlydft> =Boolean Logic= =Processing= * Modify this program =Assembly Language Program= * Write a assembly language program that contains 1 variable, '''var1''', and one loop...") |
|||
Line 3: | Line 3: | ||
=Boolean Logic= | =Boolean Logic= | ||
− | =Processing= | + | =Programming in Processing= |
− | * | + | |
+ | ==Initial Program== | ||
+ | * Copy/Paste this program into the Processing editor. | ||
+ | <br /> | ||
+ | <code><pre> | ||
+ | float diameter; | ||
+ | void setup() { | ||
+ | size( 500, 500 ); | ||
+ | frameRate( 30 ); | ||
+ | smooth(); | ||
+ | } | ||
+ | |||
+ | void draw() { | ||
+ | diameter = random( 200 ); | ||
+ | fill( random(255),100, 200 ); | ||
+ | for ( int i=0; i<10; i++ ) { | ||
+ | ellipse( random( 500 ), random( 500 ), diameter, diameter ); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </pre></code> | ||
+ | <br /> | ||
+ | * Run it and observe how it works. | ||
+ | ==Some Explanations== | ||
+ | |||
+ | * There are 2 new elements in the program: | ||
+ | ** <tt>float diameter</tt>, and | ||
+ | ** <tt>random( )</tt>. | ||
+ | * <tt>float diameter</tt> simply says that '''diameter''' is used in the program as a ''variable'' that will contain a real number (real numbers are numbers with a decimal point). | ||
+ | * <tt>random()</tt> is a function that returns a random number. If you call <tt>random(10)</tt>, it will return a random number between 0 and 10, not inclusive. So, when we write: | ||
+ | |||
+ | diameter = random( 200 ); | ||
+ | |||
+ | :we make the sketch store a random number into the variable diameter, and we force this random number to be larger than or equal to 0, and less than 200. | ||
+ | :When we call '''ellipse()''' and write <tt>random(500)</tt> for both the ''x'' and ''y'' coordinates, we make the sketch put a circle in the window at a random position, but we force the center of the circle to remain inside the window. | ||
+ | |||
+ | ==Your Assignment== | ||
+ | |||
+ | # make your sketch display circles only on the sketch only when the mouse button is ''pressed''. | ||
+ | # | ||
=Assembly Language Program= | =Assembly Language Program= | ||