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