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