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