GraphemeToColorSynesthesia.java
|
1 package synesthesia;
2
3 import java.awt.*;
4 import javax.swing.SwingUtilities;
5 import javax.swing.JOptionPane;
6 import painter.SPainter;
7
8
9 public class GraphemeToColorSynesthesia {
10
11 private static final int fontsize = 30;
12 @SuppressWarnings("SpellCheckingInspection")
13 private static final String theLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
14 private static String[] letters;
15 private static Color[] colors;
16
17 private void paintingCode() {
18 //INITIALIZE
19
20 SPainter miro = new SPainter("GRAPHEME TO COLOR SYNESTESIA", 1200, 220);
21 miro.setScreenLocation(30,30);
22 miro.setFontSize(fontsize);
23 initializeColorMap();
24
25 // INTERPRETATION
26 while ( true ) {
27 String input = JOptionPane.showInputDialog(null, "Please enter a word, or a few words ...");
28 if ( input == null ) { input = "EXIT"; }
29 input = input.toUpperCase();
30 if ( input.equals("EXIT") ) {
31 break;
32 } else if ( input.equals("REMAP")) {
33 initializeColorMap();
34 showLetters(miro, theLetters);
35 } else {
36 showLetters(miro, input.toUpperCase());
37 }
38 }
39 miro.end();
40 }
41
42 private static void showLetters(SPainter miro, String input) {
43 // READY
44 eraseWhiteBoard(miro);
45 // SET
46 miro.moveTo(new Point.Double(100, 100));
47 // GO
48 for ( int i = 0; i < input.length(); i = i + 1 ) {
49 String letter = input.substring(i, i+1);
50 Color color = getLetterColor(letter);
51 miro.setColor(color);
52 miro.draw(letter);
53 miro.mrt(fontsize);
54 }
55 }
56
57 private void initializeColorMap() {
58 letters = new String[GraphemeToColorSynesthesia.theLetters.length()];
59 colors = new Color[GraphemeToColorSynesthesia.theLetters.length()];
60 for (int i = 0; i < GraphemeToColorSynesthesia.theLetters.length(); i = i + 1 ) {
61 letters[i] = GraphemeToColorSynesthesia.theLetters.substring(i, i + 1);
62 System.out.println("I work!");
63 colors[i] = randomColor();
64 }
65 }
66
67 private static Color getLetterColor(String letter) {
68 for ( int i = 0; i < letters.length; i = i + 1 ){
69 if ( letter.equalsIgnoreCase(letters[i]) ) {
70 System.out.println("I work!");
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, gv, bv);
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 // INFASTRUCTURE FOR SOME SIMPLE PAINTING
90 private GraphemeToColorSynesthesia() {
91 paintingCode();
92 }
93
94 public static void main (String[] args) {
95 SwingUtilities.invokeLater(GraphemeToColorSynesthesia::new);
96 }
97
98 }
99