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