mcclarty/Assignment 4

From ggc

Jump to: navigation, search

001 package mcclarty;
002 
003 import wiki.Wiki;
004 import fang.*;
005 import java.awt.*;
006 import java.awt.geom.*;
007 import java.awt.Color;
008 
009 /**
010  * This program generates a rose using ovals rotated at equal intervals.
011  * The rose is made of ovals stacked on top of each other.
012  * The petals decrease in size by 10%.
013  @author My Name Here
014  */
015 public class Assignment_4 extends Game
016 {
017   public void Assignment4Rose()
018   {
019 
020     int petals = 10;
021 
022     for(int i=1; i<=petals; i++)
023     {
024       OvalSprite rosepetal=new OvalSprite(2,1);
025 
026       // The petals are centered and start off taking up 85% of the screen and decrease in size by 10%.
027       rosepetal.setLocation (0.5,0.5);
028       rosepetal.setSize(0.85*(1-(0.1*(i-1))));
029 
030       //The petals are rotated 36 degrees for each new petal created.
031       rosepetal.rotateDegrees(360.0-36.0*i);
032 
033       //Make the petals alternate between red and white.  If it is even then the petal is red and if odd it is white.
034 
035       if (% == 0)
036 
037         rosepetal.setColor(Palette.getColor("Red"));
038 
039       else
040 
041         rosepetal.setColor(Palette.getColor("White"));
042 
043       addSprite(rosepetal);
044     }
045   }
046 
047   private void Assignment4SquareGrid()
048   {
049     /**
050     *This program creates a 10 by 10 grid of circles.
051     */
052 
053     int circlesAcross=10;
054     int circlesDown=10;
055     for(int j=0; j<circlesDown; j++)
056     {
057       for(int i=1; i<=circlesAcross; i++)
058       {
059         OvalSprite dot=new OvalSprite(11);
060         dot.setSize(0.75/circlesAcross);
061         double x=0.5/circlesAcross+1.0/circlesAcross*(i-1);
062         double y=0.5/circlesAcross+(j+0.0)/circlesAcross;
063         dot.setLocation(x, y);
064         addSprite(dot);
065 
066       }
067     }
068   }
069   private void Assignment4Bullseye()
070   {
071     /**
072     *This program creates a bullseye with the colors red and yellow.
073     *The bullseye is made of circles decreasing by 10% as they approach the center.
074     */
075 
076     int layers = 10;
077 
078     for(int i=1; i<=layers; i++)
079     {
080       OvalSprite bulls=new OvalSprite (1,1);
081 
082       // The circles are centered and start off taking up 90% of the screen and decrease in size by 10%.
083       bulls.setLocation (0.5,0.5);
084       bulls.setSize(0.9*(1-(0.1*(i-1))));
085 
086       //Make the circles alternate between red and yellow.  If it is even then the circle is red and if odd it is yellow.
087 
088       if (% == 0)
089 
090         bulls.setColor(Palette.getColor("Red"));
091 
092       else
093 
094         bulls.setColor(Palette.getColor("Yellow"));
095 
096       addSprite(bulls);
097     }
098   }
099   public void Assignment4Cone()
100   {
101     /**
102         *This program creates a cone with the colors blue and green.
103         *The cone is made of circles decreasing by 10% as they shift.
104         *The circles also shift up and to the right 10% as they get smaller.
105         */
106 
107     int layers = 10;
108 
109     for(int i=1; i<=layers; i++)
110     {
111       OvalSprite cones=new OvalSprite (1,1);
112 
113       // The circless are centered and start off taking up 90% of the screen and decrease in size by 10%.
114       cones.setSize(0.9*(1-(0.1*(i-1))));
115 
116       //The circles are shifted up and right at 10% invervals.
117       double x=0.45+0.05*i;
118       double y=0.55-0.05*i;
119       cones.setLocation (x, y);
120 
121       //Make the circles alternate between blue and green.  If it is even then the circle is blue and if odd it is green.
122 
123       if (% == 0)
124 
125         cones.setColor(Palette.getColor("Blue"));
126 
127       else
128 
129         cones.setColor(Palette.getColor("Green"));
130 
131       addSprite(cones);
132     }
133   }
134   public void Assignment4Bullseyesx4()
135   {
136     /**
137     *This program creates 4 bullseyes that take up 1/4 of the screen each.
138     */
139 
140     for(double j=1; j<=4; j++)
141     {
142       double = .25;
143       double = .25;
144       if(== 1)
145       {
146         x=x;
147         y=y;
148       }
149       if(== 2)
150       {
151         x=x+0.5;
152         y=y;
153       }
154       if(== 3)
155       {
156         x=x;
157         y=y+0.5;
158       }
159       if(== 4)
160       {
161         x=x+0.5;
162         y=y+0.5;
163 
164       }
165 
166 
167       int layers = 10;
168 
169       for(int i=1; i<=layers; i++)
170       {
171         OvalSprite bull=new OvalSprite (1,1);
172 
173         // The circles are centered and start off taking up 25% of the screen and decrease in size by 10%.
174         bull.setSize(0.45*(1-(0.1*(i-1))));
175         bull.setLocation (x,y);
176 
177         //Make the circles alternate between red and yellow.  If it is even then the circle is red and if odd it is yellow.
178 
179         if (% == 0)
180 
181           bull.setColor(Palette.getColor("Red"));
182 
183         else
184 
185           bull.setColor(Palette.getColor("Yellow"));
186 
187         addSprite(bull);
188 
189       }
190     }
191   }
192 
193 
194 
195   /**handle input and game events*/
196   public void advance()
197   {
198     /* Place commands on the screen. */
199 
200     StringSprite commands = new StringSprite"Press: g, r, b, c, or f.");
201     commands.setWidth(1);
202     commands.setHeight(0.05);
203     commands.setLocation(0.5,0.95);
204     commands.setColor(Palette.getColor("Ivory"));
205     addSprite(commands);
206 
207     /* Display graphic depending on command chosen. */
208     if (getKeyPressed() == 'g')
209     {
210       removeAllSprites();
211       Assignment4SquareGrid();
212     }
213     if (getKeyPressed() == 'r')
214     {
215       removeAllSprites();
216       Assignment4Rose();
217     }
218     if (getKeyPressed() == 'b')
219     {
220       removeAllSprites();
221       Assignment4Bullseye();
222     }
223     if (getKeyPressed() == 'c')
224     {
225       removeAllSprites();
226       Assignment4Cone();
227     }
228     if (getKeyPressed() == 'f')
229     {
230       removeAllSprites();
231       Assignment4Bullseyesx4();
232     }
233 
234   }
235 }


Download/View mcclarty/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