GraphemeToColorSynesthesia.java
|
1 /*
2 Program to simulate the phenomenon know 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 mapping from letters to colors
6 - WORD OR PHRASE | simply show the word or phrase in synesthesia color
7 */
8
9
10 package synesthesia;
11
12 import painter.SPainter;
13 import javax.swing.*;
14 import java.awt.*;
15
16 public class GraphemeToColorSynesthesia {
17
18 private static final int fontsize = 30;
19 private static final String theLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
20 private static String[] letters;
21 private static Color[] colors;
22
23 private void paintingCode() {
24
25 //INITIALIZATION
26 SPainter miro = new SPainter("Grapheme to color Synesthesia",1200,220);
27 miro.setScreenLocation(30, 30);
28 miro.setFontSize(fontsize);
29 initializeColorMap(theLetters);
30
31 //INTERPRETATION
32 while (true) {
33 String input = JOptionPane.showInputDialog(null, "Please enter a word or a few words...");
34 if (input == null) {
35 input = "EXIT";
36 }
37 input = input.toUpperCase();
38
39 if (input.equals("EXIT")) {
40 break;
41 }
42 else if (input.equals("REMAP")) {
43 initializeColorMap(theLetters);
44 showLetters(miro, theLetters);
45 }
46 else {
47 showLetters(miro, input.toUpperCase());
48 }
49 }
50 miro.end();
51 }
52
53 private static void showLetters(SPainter miro, String input) {
54 //READY
55 eraseWhiteBoard(miro);
56 //SET
57 miro.moveTo(new Point.Double(100,100));
58 //GO
59 for (int i = 0; i < input.length(); i++) {
60 String letter = input.substring(i, i+1);
61 Color color = getLetterColor(letter);
62 miro.setColor(color);
63 miro.draw(letter);
64 miro.mrt(fontsize);
65 }
66 }
67
68
69 private 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 ++) {
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++){
80 if (letter.equalsIgnoreCase(letters[i])){
81 return colors[i];
82 }
83 }
84 return Color.black;
85 }
86
87 private 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 @Override
108 public void run() {
109 new GraphemeToColorSynesthesia();
110 }
111 });
112 }
113
114
115
116
117
118 }