Charles/DotPatterns

From ggc

Jump to: navigation, search

001 package Charles;
002 
003 import wiki.Wiki;
004 import fang.*;
005 import java.awt.*;
006 import java.awt.geom.*;
007 
008 /**
009  * All about my game here.
010  @author Charles
011  */
012 /**
013  *Used Frank Andersons SineWave to get an idea of how to change the height.
014  *Used Derrick Dixon's bulls eye to help with alternating the colors.
015  */
016 public class DotPatterns extends Game
017 {
018   public void setup()
019   {
020     makeAndShowTitlePage();
021     //makeAndShowHorizontal();
022     //makeAndShowDiagonal();
023     //makeAndShowSineWave();
024     //makeAndShowVertWave();
025     //makeAndShowSquareGrid();
026     //makeAndShowBow();
027     //makeAndShowBullsEye();
028     //makeAndShowFourBullsEyes();
029     //makeAndShowEnd();
030   }
031   private void makeAndShowTitlePage()
032   {
033     StringSprite title=new StringSprite("Chanelle and Charles");
034     title.setSize(.8);
035     title.setLocation(.5.3);
036     title.setColor(Palette.getColor("Hot Pink"));
037     addSprite(title);
038 
039     StringSprite title2=new StringSprite("Dot Patterns");
040     title2.setSize(.5);
041     title2.setLocation(.5.7);
042     title2.setColor(Palette.getColor("Hot Pink"));
043     addSprite(title2);
044 
045     StringSprite title3=new StringSprite("Use keys 1-9 to navigate.");
046     title3.setSize(.3);
047     title3.setLocation(.5.9);
048     title3.setColor(Palette.getColor("Hot Pink"));
049     addSprite(title3);
050 
051   }
052   private void makeAndShowEnd()
053   {
054     StringSprite title=new StringSprite("The End");
055     title.setSize(.98);
056     title.setLocation(.5.5);
057     title.setColor(Palette.getColor("Hot Pink"));
058     addSprite(title);
059   }
060   private void makeAndShowHorizontal()
061   {
062     int dotsAcross=5;
063     for(int i=1; i<=dotsAcross; i++)
064     {
065       OvalSprite dot= new OvalSprite(11);
066       dot.setSize(0.9/dotsAcross);
067       double x=0.5/dotsAcross + 1.0/dotsAcross * (i-1);
068       dot.setLocation(x, .5);
069       dot.setColor(Palette.getColor("Fire Brick"));
070       addSprite(dot);
071     }
072 
073 
074   }
075 
076   private void makeAndShowDiagonal()
077   {
078     int dotsAcross=8;
079     for(int i=1; i<=dotsAcross; i++)
080     {
081       OvalSprite dot= new OvalSprite(11);
082       dot.setSize(0.9/dotsAcross);
083       double x=0.5/dotsAcross + 1.0/dotsAcross * (i-1);
084       double y=0.5/dotsAcross + 1.0/dotsAcross * (i-1);
085       dot.setLocation(x, y);
086       dot.setColor(Palette.getColor("Hot Pink"));
087       addSprite(dot);
088     }
089 
090   }
091   private void makeAndShowSineWave()
092   {
093     int dots=60;
094     {
095       double adj_h;
096       adj_h=.3;
097       for(int i=1; i<=dots; i++)
098       {
099         OvalSprite dot=new OvalSprite(1,1);
100         dot.setSize(0.6/dots);
101         double x=(i-1)*(1.0/dots)+1.0/(2.0*dots);
102         double y=.5 - adj_h*(Math.sin((i-1)*2.0*3.14/dots));
103         dot.setLocation(x,y);
104         dot.setColor(Palette.getColor("Hot Pink"));
105         addSprite(dot);
106       }
107     }
108 
109   }
110   private void makeAndShowVertWave()
111   {
112     int dots=60;
113     {
114       double adj_h;
115       adj_h=.3;
116       for(int i=1; i<=dots; i++)
117       {
118         OvalSprite dot=new OvalSprite(1,1);
119         dot.setSize(0.6/dots);
120         double y=(i-1)*(1.0/dots)+1.0/(2.0*dots);
121         double x=.5 - adj_h*(Math.sin((i-1)*2.0*3.14/dots));
122         dot.setLocation(x,y);
123         dot.setColor(Palette.getColor("Fire Brick"));
124         addSprite(dot);
125       }
126     }
127 
128   }
129 
130 
131 
132   private void makeAndShowSquareGrid()
133   {
134     int dotsAcross=10;
135     int dotsDown=10;
136     for(int j=0; j<dotsDown; j++)
137     {
138       for(int i=1; i<=dotsAcross; i++)
139       {
140         OvalSprite dots=new OvalSprite(1,1);
141         dots.setSize(0.9/dotsAcross);
142         double x=0.5/dotsAcross+1.0/dotsAcross*(i-1);
143         double y=0.5/dotsAcross+(j+0.0)/dotsAcross;
144         dots.setLocation(x,y);
145         dots.setColor(Palette.getColor("Medium Blue"));
146         addSprite(dots);
147       }
148     }
149   }
150   private void makeAndShowBow()
151   {
152     OvalSprite oval1=new OvalSprite(1,1);
153     oval1.setSize(1.0);
154     oval1.setLocation(0.5,0.5);
155     oval1.setColor(Palette.getColor("Teal"));
156     addSprite(oval1);
157 
158     OvalSprite oval2=new OvalSprite(1,1);
159     oval2.setSize(1.0);
160     oval2.setLocation(0.5,0.0);
161     oval2.setColor(Color.BLACK);
162     addSprite(oval2);
163 
164     OvalSprite oval3=new OvalSprite(1,1);
165     oval3.setSize(1.0);
166     oval3.setLocation(0.5,1.0);
167     oval3.setColor(Color.BLACK);
168     addSprite(oval3);
169   }
170 
171   private void makeAndShowBullsEye()
172   {
173     int rings=10;
174     for(int i=1; i<=rings; i++)
175     {
176       OvalSprite ring=new OvalSprite(1,1);
177       ring.setLocation(0.50.5);
178       double s=(0.9-(0.9*(i-1)/rings));
179       ring.setSize(s);
180       if (i%2==0)
181         ring.setColor(Palette.getColor("Fire Brick"));
182       else
183         ring.setColor(Palette.getColor("Medium Blue"));
184       addSprite(ring);
185     }
186 
187   }
188   private void makeAndShowFourBullsEyes()
189   {
190     int rings1=10;
191     for(int i=1; i<=rings1; i++)
192     {
193       OvalSprite bi1=new OvalSprite(1,1);
194       bi1.setLocation(0.250.25);
195       double s=(0.5-(0.5*(i-1)/rings1));
196       bi1.setSize(s);
197       if (i%2==0)
198         bi1.setColor(Palette.getColor("Fire Brick"));
199       else
200         bi1.setColor(Palette.getColor("Medium Blue"));
201       addSprite(bi1);
202     }
203     int rings2=10;
204     for(int i=1; i<=rings2; i++)
205     {
206       OvalSprite bi2=new OvalSprite(1,1);
207       bi2.setLocation(0.750.25);
208       double s=(0.5-(0.5*(i-1)/rings2));
209       bi2.setSize(s);
210       if (i%2==0)
211         bi2.setColor(Palette.getColor("Fire Brick"));
212       else
213         bi2.setColor(Palette.getColor("Medium Blue"));
214       addSprite(bi2);
215     }
216     int rings3=10;
217     for(int i=1; i<=rings3; i++)
218     {
219       OvalSprite bi3=new OvalSprite(1,1);
220       bi3.setLocation(0.250.75);
221       double s=(0.5-(0.5*(i-1)/rings3));
222       bi3.setSize(s);
223       if (i%2==0)
224         bi3.setColor(Palette.getColor("Fire Brick"));
225       else
226         bi3.setColor(Palette.getColor("Medium Blue"));
227       addSprite(bi3);
228     }
229     int rings4=10;
230     for(int i=1; i<=rings4; i++)
231     {
232       OvalSprite bi4=new OvalSprite(1,1);
233       bi4.setLocation(0.750.75);
234       double s=(0.5-(0.5*(i-1)/rings4));
235       bi4.setSize(s);
236       if (i%2==0)
237         bi4.setColor(Palette.getColor("Fire Brick"));
238       else
239         bi4.setColor(Palette.getColor("Medium Blue"));
240       addSprite(bi4);
241     }
242 
243   }
244 
245   public void advance()
246   {
247     if(getKeyPressed()=='7')
248     {
249       removeAllSprites();
250       makeAndShowBullsEye();
251     }
252     if(getKeyPressed()=='5')
253     {
254       removeAllSprites();
255       makeAndShowSquareGrid();
256     }
257     if(getKeyPressed()=='6')
258     {
259       removeAllSprites();
260       makeAndShowBow();
261     }
262     if(getKeyPressed()=='1')
263     {
264       removeAllSprites();
265       makeAndShowHorizontal();
266     }
267     if(getKeyPressed()=='2')
268     {
269       removeAllSprites();
270       makeAndShowDiagonal();
271     }
272     if(getKeyPressed()=='3')
273     {
274       removeAllSprites();
275       makeAndShowSineWave();
276     }
277     if(getKeyPressed()=='4')
278     {
279       removeAllSprites();
280       makeAndShowVertWave();
281     }
282     if(getKeyPressed()=='8')
283     {
284       removeAllSprites();
285       makeAndShowFourBullsEyes();
286     }
287     if(getKeyPressed()=='9')
288     {
289       removeAllSprites();
290       makeAndShowEnd();
291     }
292   }
293 
294 }


Download/View Charles/DotPatterns.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