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