GBell/InteractiveArt

From ggc

Jump to: navigation, search

001 package GBell;
002 
003 import wiki.Wiki;
004 import fang.*;
005 import java.awt.*;
006 import java.awt.geom.*;
007 import Beta.OutlineTracker;
008 
009 /**
010  * This is an interactive display of
011  * artistic audio, images, and movement  
012  @author Geremy Bell
013  */
014 public class InteractiveArt extends GameLoop
015 {
016   /**sprites*/
017   private Sprite diamond, diamond2, outline, outline2, background, spiral, polygon, twelve, three, six, nine, title, title2;
018   /**tracker to move diamonds*/
019   private OutlineTracker tracker, tracker2;
020   /**trackers for clock*/
021   private OutlineTracker tracker3, tracker4, tracker5, tracker6;
022   /**tracker to rotate center image*/
023   private ProjectileTracker center;
024   /**sets condition for audio and change in rotation*/
025   private boolean intersecting=false;
026   /**angular velocity for trackers*/
027   private int x;
028   /**sound when diamonds collide*/
029   private Sound sound=new Sound(Wiki.getMedia("Pluck.wav"));
030 
031   /** starts game */
032   public void startGame()
033   {
034     makeSprites();
035     setHelpText("Click to add random shapes with random colors. Press 'x' to change the clock colors. Enjoy!");
036     toggleAudible();
037     pauseToggle();
038     x=3;
039   }
040 
041   /** makes sprites and trackers */
042   private void makeSprites()
043   {
044     title=new StringSprite("Interactive Art");
045     title.setScale(.3);
046     title.setColor(Color.RED);
047     title.setLocation(.5.05);
048     canvas.addSprite(title);
049 
050     title2=new StringSprite("by Geremy");
051     title2.setScale(.15);
052     title2.setColor(Color.GREEN);
053     title2.setLocation(.5.97);
054     canvas.addSprite(title2);
055 
056     createOutline();
057     createClock();
058     createDiamond();
059     createDiamond2();
060     createSpiral();
061   }
062 
063   /** creates oval as path for tracker */
064   private void createOutline()
065   {
066     background=new OvalSprite(11);
067     background.setScale(0.6);
068     background.setLocation(0.50.5);
069     background.setColor(Color.black);
070     canvas.addSprite(background);
071 
072     outline=new OvalSprite(11);
073     outline.setScale(0.5);
074     outline.setLocation(0.50.5);
075     outline.setColor(Color.WHITE);
076     canvas.addSprite(outline);
077 
078     outline2=new OvalSprite(11);
079     outline2.setScale(0.43);
080     outline2.setLocation(0.50.5);
081     outline2.setColor(Color.WHITE);
082     canvas.addSprite(outline2);
083 
084   }
085 
086   /**creates twelve and tracker for motion*/
087   private void createTwelve()
088   {
089     twelve=new StringSprite("12");
090     twelve.setLocation(0.50.2875);
091     twelve.setScale(.05);
092     twelve.setColor(Color.BLACK);
093     canvas.addSprite(twelve);
094 
095     tracker3=new OutlineTracker(outline2, -0.5);
096     twelve.setTracker(tracker3);
097     twelve.setLocation(tracker3.getCurrentPoint());
098     tracker3.setLooping(true);
099   }
100 
101   /**creates three and tracker for motion*/
102   private void createThree()
103   {
104     three=new StringSprite("3");
105     three.setLocation(0.7250.5);
106     three.setScale(.05);
107     three.setColor(Color.BLACK);
108     canvas.addSprite(three);
109 
110     tracker4=new OutlineTracker(outline2, -0.5);
111     three.setTracker(tracker4);
112     three.setLocation(tracker4.getCurrentPoint());
113     tracker4.setLooping(true);
114   }
115 
116   /**creates six and tracker for motion*/
117   private void createSix()
118   {
119     six=new StringSprite("6");
120     six.setLocation(0.50.72);
121     six.setScale(.05);
122     six.setColor(Color.BLACK);
123     canvas.addSprite(six);
124 
125     tracker5=new OutlineTracker(outline2, -0.5);
126     six.setTracker(tracker5);
127     six.setLocation(tracker5.getCurrentPoint());
128     tracker5.setLooping(true);
129   }
130 
131   /**creates nine and tracker for motion*/
132   private void createNine()
133   {
134     nine=new StringSprite("9");
135     nine.setLocation(0.280.5);
136     nine.setScale(.05);
137     nine.setColor(Color.BLACK);
138     canvas.addSprite(nine);
139 
140     tracker6=new OutlineTracker(outline2, -0.5);
141     nine.setTracker(tracker6);
142     nine.setLocation(tracker6.getCurrentPoint());
143     tracker6.setLooping(true);
144   }
145 
146   /**creates numbers and trackers for clock*/
147   private void createClock()
148   {
149     createTwelve();
150     createThree();
151     createSix();
152     createNine();
153   }
154 
155   /** creates a diamond and sets it
156     * in motion given a tracker */
157   private void createDiamond()
158   {
159     diamond=new PolygonSprite(4);
160     diamond.setScale(0.1);
161     canvas.addSprite(diamond);
162 
163     tracker=new OutlineTracker(outline, -0.5);
164     diamond.setTracker(tracker);
165     diamond.setLocation(tracker.getCurrentPoint());
166     tracker.setLooping(true);
167   }
168 
169   /** creates a diamond and sets it
170     * in motion given a tracker */
171   private void createDiamond2()
172   {
173     diamond2=new PolygonSprite(4);
174     diamond2.setScale(0.1);
175     canvas.addSprite(diamond2);
176 
177     tracker2=new OutlineTracker(outline, 0.5);
178     diamond2.setTracker(tracker2);
179     diamond2.setLocation(tracker.getCurrentPoint());
180     tracker2.setLooping(true);
181   }
182 
183   /** creates spiral image and sets
184     * it in motion given a tracker */
185   private void createSpiral()
186   {
187     spiral=new ImageSprite(Wiki.getMedia("Spiral4.png"));
188     spiral.setScale(0.3);
189     spiral.setLocation(0.50.5);
190     canvas.addSprite(spiral);
191 
192     Point2D.Double direction=new Point2D.Double(0.00.0);
193     center=new ProjectileTracker(direction);
194     /** rotate 1/2 a revolution per second */
195     center.setAngularVelocity(x);
196     spiral.setTracker(center);
197   }
198 
199   /** makes collision of diamonds change
200     * rotation of the center and play audio */
201   private void handleCollisions()
202   {
203     if(diamond.intersects(diamond2))
204     {
205       if(intersecting==false)
206       {
207         x=-x;
208         center.setAngularVelocity(x);
209         sound.play();
210         intersecting=true;
211       }
212     }
213     else
214     {
215       intersecting=false;
216     }
217 
218   }
219 
220   /** changes color of
221   * diamonds every 5 seconds*/
222   private void changeColors()
223   {
224     if(getTime()>0)
225     {
226       diamond.setColor(Color.RED);
227       diamond2.setColor(Color.RED);
228     }
229     if(getTime()>5)
230     {
231       diamond.setColor(Color.GREEN);
232       diamond2.setColor(Color.GREEN);
233     }
234     if(getTime()>10)
235     {
236       diamond.setColor(Color.ORANGE);
237       diamond2.setColor(Color.ORANGE);
238     }
239     if(getTime()>15)
240     {
241       diamond.setColor(Color.BLUE);
242       diamond2.setColor(Color.BLUE);
243     }
244     if(getTime()>20)
245     {
246       diamond.setColor(Color.YELLOW);
247       diamond2.setColor(Color.YELLOW);
248     }
249     if(getTime()>25)
250     {
251       resetTime();
252     }
253   }
254 
255   private void addShapes()
256   {
257     if(getPlayer().getMouse().getClickLocation()!=null)
258     {
259       Point2D.Double click=getPlayer().getMouse().getClickLocation();
260       if(!background.intersects(click))
261       {
262         polygon=new PolygonSprite(random.nextInt(3)+3);
263         polygon.setScale(.02);
264         polygon.setLocation(getPlayer().getMouse().getClickLocation());
265         Color color=new Color(random.nextFloat(), random.nextFloat(), random.nextFloat());
266         polygon.setColor(color);
267         canvas.addSprite(polygon);
268       }
269     }
270   }
271 
272   /**runs handleCollisions method and
273   * makes diamonds change color with time*/
274   public void advanceFrame(double timePassed)
275   {
276     handleCollisions();
277     changeColors();
278     addShapes();
279   }
280 }

Compiler Errors:
----------
1. ERROR in GBell/InteractiveArt.java (at line 187)
	spiral=new ImageSprite(Wiki.getMedia("Spiral4.png"));
	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
1 problem (1 error)

Download/View GBell/InteractiveArt.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