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 SPainter miro = new SPainter(1200,220);
19 miro.setScreenLocation(30,30);
20 miro.setFontSize(fontsize);
21 initializeColorMap(theLetters);
22
23 while (true) {
24
25 String input = JOptionPane.showInputDialog(null,
26 "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,input.toUpperCase());
34 } else {
35 showLetters(miro,input.toUpperCase());
36 }
37 }
38 miro.end();
39 }
40
41 private static void showLetters(SPainter miro, String input) {
42
43 eraseWhiteBoard(miro);
44
45 miro.moveTo(new Point.Double(100, 100));
46
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
58 letters = new String[specialLetters.length()];
59 colors = new Color[specialLetters.length()];
60 for (int i = 0; i < specialLetters.length(); i = i + 1) {
61 letters[i] = specialLetters.substring(i,i+1);
62 colors[i] = randomColor();
63 }
64 }
65
66 private static Color getLetterColor(String letter) {
67 for ( int i = 0; i < letters.length; i = i + 1 ) {
68 if ( letter.equalsIgnoreCase(letters[i])) {
69 return colors[i];
70 }
71 }
72
73 return Color.BLACK;
74
75 }
76
77 private static Color randomColor() {
78
79 int rv = (int)(Math.random()*256);
80 int gv = (int)(Math.random()*256);
81 int bv = (int)(Math.random()*256);
82 return new Color(rv,gv,bv);
83
84 }
85
86 private static void eraseWhiteBoard(SPainter miro) {
87
88 miro.setColor(Color.WHITE);
89 miro.wash();
90 miro.paintFrame(Color.black, 5);
91
92 }
93
94 public GraphemeToColorSynesthesia() {
95
96 paintingCode();
97
98 }
99
100 public static void main(String[] args) {
101
102 SwingUtilities.invokeLater(new Runnable(){
103
104 public void run() {
105 new GraphemeToColorSynesthesia();
106 }
107 });
108 }
109 }
110