GraphemeToColorSynesthesia.java
|
1 package synesthesia;
2 import java.awt.Color;
3 import java.awt.Point;
4 import javax.swing.JOptionPane;
5 import javax.swing.SwingUtilities;
6 import painter.SPainter;
7 public class GraphemeToColorSynesthesia {
8
9 private static final int fontsize = 30;
10 private static final String theLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
11 private static String[] letters;
12 private static Color[] colors;
13 private void paintingCode() {
14 // INITIALIZATION
15 SPainter miro = new SPainter("miro",1200,220);
16 miro.setScreenLocation(30, 30);
17 miro.setFontSize(fontsize);
18 initializeColorMap(theLetters);
19 // INTERPRETATION
20 while ( true )
21 {
22 String input = JOptionPane.showInputDialog(null,"Please enter a word, or a few words ...");
23 if ( input == null)
24 {
25 input = "EXIT";
26 }
27 input = input.toUpperCase();
28 if ( input.equals("EXIT") )
29 {
30 break;
31 }
32 else if ( input.equals("REMAP") ) {
33 initializeColorMap(theLetters);
34 showLetters(miro,theLetters);
35 }
36 else {
37 showLetters(miro,input.toUpperCase());
38 }
39 }
40 miro.end();
41 }
42
43 private static void showLetters(SPainter miro, String input)
44 {
45 // READY
46 eraseWhiteBoard(miro);
47 // SET
48 miro.moveTo(new Point.Double(100,100));
49 // GO
50 for ( int i = 0; i < input.length(); i = i + 1 )
51 {
52 String letter = input.substring(i, i+1);
53 Color color = getLetterColor(letter);
54 miro.setColor(color);
55 miro.draw(letter);
56 miro.mrt(fontsize);
57 }
58 }
59 private static void initializeColorMap(String specialLetters)
60 {
61 letters = new String[specialLetters.length()];
62 colors = new Color[specialLetters.length()];
63 for ( int i = 0; i < specialLetters.length(); i = i + 1)
64 {
65 letters[i] = specialLetters.substring(i,i+1);
66 colors[i] = randomColor();
67 }
68 }
69 private static Color getLetterColor(String letter)
70 {
71 for ( int i = 0; i < letters.length; i =i + 1 )
72 {
73 if ( letter.equalsIgnoreCase(letters[i]) )
74 {
75 return colors[i];
76 }
77 }
78 return Color.BLACK;
79 }
80 private static Color randomColor()
81 {
82 int rv = (int)(Math.random()*256);
83 int gv = (int)(Math.random()*256);
84 int bv = (int)(Math.random()*256);
85 return new Color(rv,gv,bv);
86 }
87 private static void eraseWhiteBoard(SPainter miro)
88 {miro.setColor(Color.WHITE);
89 miro.wash();
90 miro.paintFrame(Color.black, 5);
91 }
92 // INFRASTRUCTURE FOR SOME SIMPLE PAINTING
93 public GraphemeToColorSynesthesia()
94 {
95 paintingCode();
96 }
97 public static void main(String[] args)
98 {
99 SwingUtilities.invokeLater(new Runnable()
100 {public void run()
101 {new GraphemeToColorSynesthesia();
102 }
103 });}
104 }
105
106
107
108
109
110