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