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