Rohrer/Loops Assignment 4

From ggc

Jump to: navigation, search

001 package Rohrer;
002 
003 import fang.*;
004 import java.awt.*;
005 import java.awt.geom.*;
006 
007 /**
008  * My loop programs 
009  @author Kevin Rohrer
010  */
011 public class Loops_Assignment_4 extends Game
012 {
013   /** sets up the game */
014   public void setup()
015   {
016 
017     StringSprite steps = new StringSprite("Press a number Between 1 and 7 to Begin");
018     steps.setSize(.75);
019     steps.setLocation(.5,.4);
020     addSprite(steps);
021 
022     // Horizontal();  //  1  point
023     // diagonal();    //  1  point
024     // Grid();        //  4  points
025     // Target();      //  2  points
026     // Target_4();    //  4  points
027     // Cone();        //  3  points
028     // Cone_4();      //  5  points
029     //                //  20 points total
030   }
031 
032   /** makes dots in a horizontal line*/
033   private void Horizontal()  //  1 point
034   {
035     int h_Dots = 5;
036     for(int i=; i <=h_Dots ; i++)
037     {
038       OvalSprite hDot = new OvalSprite(1,1);
039       hDot.setSize(0.9/h_Dots);
040       double = 0.5/h_Dots + 1.0/h_Dots * (i-1);
041       hDot.setLocation(x, 0.5);
042       addSprite(hDot);
043     }
044   }
045 
046   /** maked dots in a diagonal line */
047   private void Diagonal()  //1 point
048   {
049     int d_Dots = 15;
050     for(int i=; i <=d_Dots ; i++)
051     {
052       OvalSprite dDot = new OvalSprite(1,1);
053       dDot.setSize(0.9/d_Dots);
054       double = 0.5/d_Dots + 1.0/d_Dots * (i-1);
055       double = 0.5/d_Dots + 1.0/d_Dots * (i-1);
056       dDot.setLocation(x, y);
057       addSprite(dDot);
058     }
059   }
060 
061   /** makes dots into a full grid*/
062   private void Grid()  //4 points
063   {
064     int h_Row =20;
065     int v_Row =20;
066     for(int v=0; v < v_Row; v++)
067     {
068       for(int h=1; h<=h_Row; h++)
069       {
070         OvalSprite gDot=new OvalSprite(11);
071         gDot.setSize(0.9/h_Row);
072         double = 0.5 / h_Row + 1.0 / h_Row * (h-1);
073         double = 0.5 / h_Row + (v+0.0/ h_Row;
074         gDot.setLocation(x, y);
075         addSprite(gDot);
076       }
077     }
078 
079   }
080 
081   /** makes a target with circles*/
082   private void Target()  //2 points
083   {
084     int rings = 10;
085     for(int i=1; i <= rings; i++)
086     {
087       OvalSprite ring = new OvalSprite(2,2);
088       ring.setSize(1.0 -(1.0*(i-1)/rings));
089       ring.setLocation(0.5,0.5);
090       if (% == 0)
091         ring.setColor(Palette.getColor("Lawn Green"));
092       else
093         ring.setColor(Palette.getColor("Orange Red"));
094 
095       addSprite(ring);
096     }
097   }
098 
099 
100   /** makes four smaller targets*/
101   private void Target_4()  //4 points
102   {
103     for(double j=1; j<=4; j++)
104     {
105       double = .25;
106       double = .25;
107       if(== 4)
108       {
109         x=x+.5;
110         y=y+.5;
111       }
112       else
113       {
114         if (% == 0)
115         {
116           y= y + ((j-0.0)/4);
117           x=x;
118         }
119         else
120         {
121           x= x + ((j-1.0)/4);
122           y=y;
123         }
124       }
125 
126       int rings = 10;
127       for(int i=1; i <= rings; i++)
128       {
129         OvalSprite ring = new OvalSprite(2,2);
130         ring.setSize(.5 -(.5*(i-1)/rings));
131 
132         ring.setLocation(x,y);
133 
134         if (% == 0)
135           ring.setColor(Palette.getColor("Lawn Green"));
136         else
137           ring.setColor(Palette.getColor("Orange Red"));
138         addSprite(ring);
139 
140       }
141     }
142   }
143 
144   /** makes a cone with circles*/
145   private void Cone()  //3 points
146   {
147     int rings = 10;
148     for(int i=1; i <= rings; i++)
149     {
150       OvalSprite ring = new OvalSprite(1,1);
151       ring.setSize(1.0 -(1.0*(i-1)/(rings)));
152       double = .5 -(.5*(i-1)/rings);
153       double = .5 -(.5*(i-1)/rings);
154       ring.setLocation(x,y);
155 
156       if (% == 0)
157         ring.setColor(Palette.getColor("Lawn Green"));
158       else
159         ring.setColor(Palette.getColor("Orange Red"));
160 
161       addSprite(ring);
162     }
163   }
164 
165   /**makes four smaller cones*/
166   private void Cone_4()  //5 points
167   {
168     for(double j=1; j<=4; j++)
169     {
170       double xx = 0.0;
171       double yy = 0.0;
172       if(== 4)
173       {
174         xx=xx+.5;
175         yy=yy+.5;
176       }
177       else
178       {
179         if (% == 0)
180         {
181           yy=yy + ((j-0.0)/4);
182           xx=xx;
183         }
184         else
185         {
186           xx=xx + ((j-1.0)/4);
187           yy=yy;
188         }
189       }
190 
191       int rings = 10;
192       for(int i=1; i <= rings; i++)
193       {
194         OvalSprite ring = new OvalSprite(1,1);
195         ring.setSize((1.0 -(1.0*(i-1)/(rings)))/2);
196         double =xx + .25 -(.25*(i-1)/rings);
197         double =yy + .25 -(.25*(i-1)/rings);
198         ring.setLocation(x,y);
199 
200         if (% == 0)
201           ring.setColor(Palette.getColor("Lawn Green"));
202         else
203           ring.setColor(Palette.getColor("Orange Red"));
204         addSprite(ring);
205 
206       }
207     }
208   }
209 
210 
211 
212   /** change display on keypress */
213   public void advance()
214   {
215     if(getKeyPressed()=='1')
216     {
217       removeAllSprites();
218       Horizontal();
219     }
220     if(getKeyPressed()=='2')
221     {
222       removeAllSprites();
223       Diagonal();
224     }
225     if(getKeyPressed()=='3')
226     {
227       removeAllSprites();
228       Grid();
229     }
230     if(getKeyPressed()=='4')
231     {
232       removeAllSprites();
233       Target();
234     }
235     if(getKeyPressed()=='5')
236     {
237       removeAllSprites();
238       Cone();
239     }
240     if(getKeyPressed()=='6')
241     {
242       removeAllSprites();
243       Target_4();
244     }
245     if(getKeyPressed()=='7')
246     {
247       removeAllSprites();
248       Cone_4();
249     }
250   }
251 }


Download/View Rohrer/Loops_Assignment_4.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter