|
001 packagepackage is used to name the directory or folder a class is in FA;
002
003 importimport means to make the classes and/or packages available in this program fang.*;
004 importimport means to make the classes and/or packages available in this program java.awt.*;
005 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
006 importimport means to make the classes and/or packages available in this program wiki.Wiki;
007 importimport means to make the classes and/or packages available in this program java.lang.Math.*;
008
009 /**
010 * The program displays sets of dots arranged in the shape of a circle,
011 * spiral, a rectangular grid and a sine wave.A;so, a flower is displayed by rotating
012 * reducing a series of ellipses place about a common center.
013 * @authorFrank Anderson
014 */
015 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects Assignment4_AllShapes extendsextends means to customize or extend the functionality of a class Game
016 {open braces start code blocks and must be matched with a close brace
017 /**sets up the game*/
018
019 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value Assignment4Circle()
020 {open braces start code blocks and must be matched with a close brace
021 /**
022 * Display a circle with dots of equal angular separation of 36 degrees.
023 * x- and y-coordinates where the center of the dots
024 * outlining the circle will be drawn. */
025 doubledouble is the type for numbers that can contain decimal fractions xCoordinate;
026 doubledouble is the type for numbers that can contain decimal fractions yCoordinate;
027
028 // The center of the cirlce is at the center of the screen, (.5, .5).
029 doubledouble is the type for numbers that can contain decimal fractions x_CircleCenter =this assignment operator makes the left side equal to the right side .5;
030 doubledouble is the type for numbers that can contain decimal fractions y_CircleCenter =this assignment operator makes the left side equal to the right side .5;
031
032 /* The circle whose circumference will be drawn has a radius of .35,
033 *thus the circle should occupy 2(.35) =this assignment operator makes the left side equal to the right side 70%this divides the left side by the right side and evaluates to the remainder of the screen. */
034 doubledouble is the type for numbers that can contain decimal fractions radius_of_circle =this assignment operator makes the left side equal to the right side .35;
035
036 // Select the number of dots to be located along the circumference.
037 intint is the type for whole numbers and it is short for integer number_of_dots =this assignment operator makes the left side equal to the right side 10;
038
039 // Dots will begin at a selected initial angle. This case it is 0 degrees.
040 doubledouble is the type for numbers that can contain decimal fractions initial_angle =this assignment operator makes the left side equal to the right side 0;
041
042 /* To have the dots placed at equal angular distances, the angle must
043 * must be increased the same percentange of the circle each time. */
044 doubledouble is the type for numbers that can contain decimal fractions angle_increment =this assignment operator makes the left side equal to the right side 2*3.14/number_of_dots;
045 doubledouble is the type for numbers that can contain decimal fractions angle_of_radius;
046
047
048 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 1; i <=this evaluates to true if the left side is not more than the right side number_of_dots; i++this is the increment operator, which increases the variable by 1)
049 {open braces start code blocks and must be matched with a close brace
050 /* A circle will be used to represent the dots. Its circle's size
051 * will occupy .05 of the screen. */
052 OvalSprite oval =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1,1);
053
054 // Adjust the size of the dots to the number of individual dots to be shown.
055 oval.setSize(.5/number_of_dots);
056
057 /* The angle that the radius makes with the horizontal will
058 * change forfor is a looping structure for repeatedly executing a block of code the location of each dot along the circumference.
059 * The angle changes by the same increment as it changes position. */
060 angle_of_radius =this assignment operator makes the left side equal to the right side initial_angle +adds two numbers together or concatenates Strings together i*angle_increment;
061
062 /* Convert the radius's polar coordinates to Cartesian coordinates
063 * using x =this assignment operator makes the left side equal to the right side r cos(angle) and y =this assignment operator makes the left side equal to the right side r sin(angle). */
064
065 xCoordinate =this assignment operator makes the left side equal to the right side radius_of_circle*Math.sin(angle_of_radius);
066 xCoordinate =this assignment operator makes the left side equal to the right side xCoordinate +adds two numbers together or concatenates Strings together x_CircleCenter;
067
068 yCoordinate =this assignment operator makes the left side equal to the right side radius_of_circle*Math.cos(angle_of_radius);
069 yCoordinate =this assignment operator makes the left side equal to the right side yCoordinate +adds two numbers together or concatenates Strings together y_CircleCenter;
070
071 // Set the location of the center of the dot and display the dot.
072 oval.setLocation(xCoordinate, yCoordinate);
073 addSprite(oval);
074 }close braces end code blocks and must match an earlier open brace
075 }close braces end code blocks and must match an earlier open brace
076
077 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value Assignment4SineWave()
078 {open braces start code blocks and must be matched with a close brace/**
079 *Determine the number of dots to be placed on the screen. */
080 intint is the type for whole numbers and it is short for integer number_of_dots;
081 number_of_dots =this assignment operator makes the left side equal to the right side 20;
082
083 /*For each dot determine the x location and the y location
084 on the screen where the center of the sine curve will be at (.5, .5).
085
086 The y value will be the appropriate coordinate above or below
087 the horizontal line across the middle of the screen.*/
088
089 doubledouble is the type for numbers that can contain decimal fractions xCoordinate;
090 doubledouble is the type for numbers that can contain decimal fractions yCoordinate;
091 doubledouble is the type for numbers that can contain decimal fractions adjust_ht;
092 adjust_ht=this assignment operator makes the left side equal to the right side.4;
093
094 /* Display number_of_dots on the screen*/
095 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 1; i<=this evaluates to true if the left side is not more than the right side number_of_dots; i++this is the increment operator, which increases the variable by 1)
096 {open braces start code blocks and must be matched with a close brace
097 /*Determine the x- and y-coordinates forfor is a looping structure for repeatedly executing a block of code each point and plot that point*/
098
099 OvalSprite oval =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1,1);
100 oval.setSize(.03);
101 xCoordinate =this assignment operator makes the left side equal to the right side (i-1)*(1.0/number_of_dots)+adds two numbers together or concatenates Strings together1.0/(2.0*number_of_dots);
102 yCoordinate =this assignment operator makes the left side equal to the right side .5 - adjust_ht*(Math.sin((i-1)*2.0*3.14/number_of_dots));
103
104 oval.setLocation(xCoordinate, yCoordinate);
105 addSprite(oval);
106 }close braces end code blocks and must match an earlier open brace
107 }close braces end code blocks and must match an earlier open brace
108
109
110 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value Assignment4Spiral()
111 {open braces start code blocks and must be matched with a close brace
112 /**
113 * Display a spiral with dots of equal angular separation of 36 degrees.
114 * The radius increases in equal increments starting at the center of the screen.
115 */
116
117 doubledouble is the type for numbers that can contain decimal fractions xCoordinate;
118 doubledouble is the type for numbers that can contain decimal fractions yCoordinate;
119 doubledouble is the type for numbers that can contain decimal fractions x_Spiral_Center =this assignment operator makes the left side equal to the right side .5;
120 doubledouble is the type for numbers that can contain decimal fractions y_Spiral_Center =this assignment operator makes the left side equal to the right side .5;
121 doubledouble is the type for numbers that can contain decimal fractions radius_of_spiral;
122 intint is the type for whole numbers and it is short for integer number_of_dots =this assignment operator makes the left side equal to the right side 40;
123 doubledouble is the type for numbers that can contain decimal fractions initial_angle =this assignment operator makes the left side equal to the right side 0.0;
124 doubledouble is the type for numbers that can contain decimal fractions angle_increment =this assignment operator makes the left side equal to the right side 470.0/number_of_dots;
125 doubledouble is the type for numbers that can contain decimal fractions radius_increment =this assignment operator makes the left side equal to the right side.4/number_of_dots
126 ;
127 doubledouble is the type for numbers that can contain decimal fractions angle_of_radius;
128 doubledouble is the type for numbers that can contain decimal fractions initial_radius =this assignment operator makes the left side equal to the right side 0;
129
130
131 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 1; i <=this evaluates to true if the left side is not more than the right side number_of_dots; i++this is the increment operator, which increases the variable by 1)
132 {open braces start code blocks and must be matched with a close brace
133 // create the dots to be displayed.
134 OvalSprite oval =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1,1);
135 oval.setSize(.5/number_of_dots);
136
137 /* Increase the angle of the radius by 360/number of dots
138 forfor is a looping structure for repeatedly executing a block of code each newnew is used to create objects by calling the constructor dot location. */
139 angle_of_radius =this assignment operator makes the left side equal to the right side initial_angle +adds two numbers together or concatenates Strings together (i-1)*angle_increment;
140
141 /*Increase the radius of the spiral in equal lengths.*/
142 radius_of_spiral =this assignment operator makes the left side equal to the right side initial_radius +adds two numbers together or concatenates Strings together(i-1)*radius_increment;
143
144 /* Convert from polar to Cartesian coordinates.
145 * using x =this assignment operator makes the left side equal to the right side r cos(angle) and y =this assignment operator makes the left side equal to the right side r sin(angle) */
146 xCoordinate =this assignment operator makes the left side equal to the right side radius_of_spiral*Math.sin(angle_of_radius*3.14/180);
147 xCoordinate =this assignment operator makes the left side equal to the right side xCoordinate +adds two numbers together or concatenates Strings together x_Spiral_Center;
148
149 yCoordinate =this assignment operator makes the left side equal to the right side radius_of_spiral*Math.cos(angle_of_radius*3.14/180);
150 yCoordinate =this assignment operator makes the left side equal to the right side yCoordinate +adds two numbers together or concatenates Strings together y_Spiral_Center;
151
152 // Set the center of the dot and display it on the screen.
153 oval.setLocation(xCoordinate, yCoordinate);
154 addSprite(oval);
155 }close braces end code blocks and must match an earlier open brace
156 }close braces end code blocks and must match an earlier open brace
157
158 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value Assignment4Grid()
159 {open braces start code blocks and must be matched with a close brace
160 /**
161 * This program will place 100 dots on the screen in a square grid
162 * with 10 rows and 10 columns.
163 */
164 intint is the type for whole numbers and it is short for integer number_of_rows =this assignment operator makes the left side equal to the right side 10;
165 intint is the type for whole numbers and it is short for integer ovals_per_row =this assignment operator makes the left side equal to the right side 10;
166
167 doubledouble is the type for numbers that can contain decimal fractions xCoordinate;
168 doubledouble is the type for numbers that can contain decimal fractions yCoordinate;
169 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer j =this assignment operator makes the left side equal to the right side 1; j <=this evaluates to true if the left side is not more than the right side number_of_rows; j++this is the increment operator, which increases the variable by 1)
170 {open braces start code blocks and must be matched with a close brace
171 yCoordinate =this assignment operator makes the left side equal to the right side (1.0/number_of_rows)*(j-1) +adds two numbers together or concatenates Strings together 1.0/(2*number_of_rows);
172 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 1; i <=this evaluates to true if the left side is not more than the right side ovals_per_row; i++this is the increment operator, which increases the variable by 1)
173 {open braces start code blocks and must be matched with a close brace
174 OvalSprite oval =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1,1);
175 oval.setSize(.02);
176 xCoordinate =this assignment operator makes the left side equal to the right side 1.0/(2*ovals_per_row) +adds two numbers together or concatenates Strings together (1.0/ovals_per_row)*(i-1);
177 oval.setLocation(xCoordinate, yCoordinate);
178 addSprite(oval);
179 }close braces end code blocks and must match an earlier open brace
180 }close braces end code blocks and must match an earlier open brace
181 }close braces end code blocks and must match an earlier open brace
182
183 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value Assignment4Rose()
184 {open braces start code blocks and must be matched with a close brace
185 /**
186 * This program displays a series of rose petals made of oval shapes that have been rotated equal amounts.
187 * The number of petals is represented by the layers in the rose. Each petal is smaller in size than the previous layer.
188 * All petals are centered at the middle of the screen.
189 * @authorthis is the Javadoc tag for documenting who created the source code Frank Anderson &this performs a bit-wise and (not the same as boolean and which is &&) Derrick Dixon
190 */
191
192 /* The number of petals on rose will be represented as layers. */
193 intint is the type for whole numbers and it is short for integer layers =this assignment operator makes the left side equal to the right side 10;
194 doubledouble is the type for numbers that can contain decimal fractions initial_angle;
195 /* Each oval representing a layer of the rose will be rotated the same
196 number of degrees forfor is a looping structure for repeatedly executing a block of code each subsequent oval. */
197 initial_angle =this assignment operator makes the left side equal to the right side 360.0/layers;
198 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side1; i <=this evaluates to true if the left side is not more than the right side layers; i++this is the increment operator, which increases the variable by 1)
199 {open braces start code blocks and must be matched with a close brace
200 OvalSprite petal=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite (3, 2);
201 petal.rotateDegrees(initial_angle +adds two numbers together or concatenates Strings together (i - 1)*360.0/layers);
202
203 /* The size of the petal originally occupies .90%this divides the left side by the right side and evaluates to the remainder
204 of the screen and is then decreased in size 90%this divides the left side by the right side and evaluates to the remainder forfor is a looping structure for repeatedly executing a block of code subsequent petals.*/
205 petal.setSize(.9 -(0.9*(i-1)/layers));
206
207 /* The center of each oval representing a petal is at
208 * the center of the screen, (.5, .5). */
209 petal.setLocation(0.5, 0.5);
210
211 /* Alternate the colors of the petals between blue and yellow depending on
212 whether the petal number is odd or even. Blue forfor is a looping structure for repeatedly executing a block of code even numbered petals;
213 yellow forfor is a looping structure for repeatedly executing a block of code odd numbered petals. */
214
215 ifif executes the next statement only if the condition in parenthesis evaluates to true (i %this divides the left side by the right side and evaluates to the remainder 2 ==this is the comparison operator which evaluates to true if both sides are the same 0)
216 petal.setColor(Palette.getColor("Blue"));
217 elseelse is what happens when the if condition is false
218 petal.setColor(Palette.getColor("Yellow"));
219
220 // Display the petal of the rose.
221 addSprite(petal);
222 }close braces end code blocks and must match an earlier open brace
223 }close braces end code blocks and must match an earlier open brace
224
225
226
227
228
229
230 /**handle input and game events*/
231 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
232 {open braces start code blocks and must be matched with a close brace
233 /* Place directions on the screen. */
234
235 StringSprite directions =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite( "Depress: c, g, l, r, or s.");
236 directions.setWidth(1);
237 directions.leftJustify();
238 directions.setHeight(.06);
239 directions.setLocation(0,.95);
240 directions.setColor(newnew is used to create objects by calling the constructor Color(255,0,0));
241 addSprite(directions);
242
243 /* Display graphic depending on character chosen. */
244 ifif executes the next statement only if the condition in parenthesis evaluates to true (getKeyPressed() ==this is the comparison operator which evaluates to true if both sides are the same 'c')
245 {open braces start code blocks and must be matched with a close brace
246 removeAllSprites();
247 Assignment4Circle();
248 }close braces end code blocks and must match an earlier open brace
249 ifif executes the next statement only if the condition in parenthesis evaluates to true (getKeyPressed() ==this is the comparison operator which evaluates to true if both sides are the same 'r')
250 {open braces start code blocks and must be matched with a close brace
251 removeAllSprites();
252 Assignment4Rose();
253 }close braces end code blocks and must match an earlier open brace
254 ifif executes the next statement only if the condition in parenthesis evaluates to true (getKeyPressed() ==this is the comparison operator which evaluates to true if both sides are the same 'l')
255 {open braces start code blocks and must be matched with a close brace
256 removeAllSprites();
257 Assignment4Spiral();
258 }close braces end code blocks and must match an earlier open brace
259 ifif executes the next statement only if the condition in parenthesis evaluates to true (getKeyPressed() ==this is the comparison operator which evaluates to true if both sides are the same 'g')
260 {open braces start code blocks and must be matched with a close brace
261 removeAllSprites();
262 Assignment4Grid();
263 }close braces end code blocks and must match an earlier open brace
264 ifif executes the next statement only if the condition in parenthesis evaluates to true (getKeyPressed() ==this is the comparison operator which evaluates to true if both sides are the same 's')
265 {open braces start code blocks and must be matched with a close brace
266 removeAllSprites();
267 Assignment4SineWave();
268 }close braces end code blocks and must match an earlier open brace
269 }close braces end code blocks and must match an earlier open brace
270
271 }close braces end code blocks and must match an earlier open brace
|