jam/PaletteTest

From ggc

Jump to: navigation, search

001 package jam;
002 
003 import fang.*;
004 import java.awt.*;
005 import java.awt.geom.*;
006 
007 import java.awt.Color;
008 import java.util.ArrayList;
009 import java.util.Map;
010 
011 /**
012  * This program shows all of the colors
013  * that have names.
014  @author Jam Jenkins 
015  *
016  */
017 public class PaletteTest extends Game
018 {
019   /**the color swatches*/
020   private ArrayList<Sprite> square;
021   /**the name of the color*/
022   private StringSprite colorLabel;
023   /**sample code*/
024   private StringSprite codeLabel;
025 
026   /**makes and adds the sprites*/
027   @Override
028   public void setup()
029   {
030     makeSprites();
031     addSprites();
032     //setHelp("resources/RainbowHelp.txt");
033     //startGameImmediately();
034   }
035 
036   /**makes a sprite square for each color and
037    * adds the to the screen in a matrix.
038    */
039   private void makeSprites()
040   {
041     //adds a color to the palette
042     addColor("Custom Added""#e0E68C");
043 
044     //holds all of the square colors
045     square = new ArrayList<Sprite>();
046 
047     //makes a square per color
048     Map<StringColor> map = Palette.getColorMap();
049     long rows = Math.round(0.5 + Math.sqrt(map.size()));
050     long cols = rows;
051     int = 0;
052     int = 0;
053     for (Color color: map.values())
054     {
055       Sprite sprite = new RectangleSprite(10.75);
056       sprite.setScale(1.0 / rows);
057       sprite.setLocation((+ 0.5/ rows,
058                          0.75*(+ 0.5/ cols);
059       sprite.setColor(color);
060       square.add(sprite);
061       r++;
062       if (>= rows)
063       {
064         = 0;
065         c++;
066       }
067     }
068     colorLabel = new StringSprite("Color");
069     colorLabel.bottomJustify();
070     colorLabel.setLocation(0.50.9);
071     colorLabel.setHeight(0.1);
072     codeLabel=new StringSprite("sprite.setColor(Palette.getColor(\""+"Color"+"\"));");
073     codeLabel.setWidth(0.9);
074     codeLabel.bottomJustify();
075     codeLabel.leftJustify();
076     codeLabel.setLocation(0.050.95);
077     codeLabel.setColor(Palette.getColor("White"));
078     if (colorLabel.getWidth() 0.9)
079     {
080       colorLabel.setWidth(0.9);
081     }
082     colorLabel.setColor(Palette.getColor("white"200));
083   }
084 
085   /**adds all of the sprites*/
086   private void addSprites()
087   {
088     addSprite(square.toArray(new Sprite[0]));
089     addSprite(colorLabel);
090     addSprite(codeLabel);
091   }
092 
093   /**makes the mouse moving over a color
094    * display the color's name
095    @param timePassed not used
096    */
097   @Override
098   public void advance()
099   {
100     //System.out.println("Game is "+getCurrentGame());
101     for (Sprite sprite: square)
102     {
103       if (sprite.intersects(getMouse2D()))
104       {
105         //System.out.println("colorLabel: "+colorLabel);
106         colorLabel.setText(getColorName(sprite.getColor()));
107         colorLabel.setHeight(0.1);
108         if (colorLabel.getWidth() 0.9)
109         {
110           colorLabel.setWidth(0.9);
111         }
112         codeLabel.setText("sprite.setColor(Palette.getColor(\""+
113                           colorLabel.getText()+"\"));");
114         codeLabel.setWidth(0.9);
115 
116       }
117     }
118   }
119 }


Download/View jam/PaletteTest.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