Transform text to colored pixels?

I would like to create and image composed by a text. I would like to say on processing " a = blue pixel, b = red pixel … ". Transform 100 letters on 10x10 image ( or larger ).

THX !

Hi, @MAKESHADY
I’m not sure to get what you mean.
You want a program that translate sentences to images letters by letters ?

If so here is an example :

String str = "some text";
color c[] = new color[str.length()];

for ( int i = 0 ; i < str.length() ; i ++ ) {
  char t = str.charAt(i);
  if ( t == 's' ) c[i] = color(255,0,0);
  if ( t == 'o' ) c[i] = color(0,255,0);
  // etc
}

for ( int i = 0 ; i < height ; i ++ ) {
  for ( int j = 0 ; j < width ; j ++ ) {
    int n = width * i + j ;
    if ( n < c.length ) set( j,  i, c[n] );
  }
}
1 Like

What you want is… not clear.

Here is some example code that I think is what you’re asking for.

color[] colors = new color[100];
char[] chars = new char[100];

void setup() {
  size( 440, 440 );
  textSize(32);
  for ( int i = 0; i < 100; i++ ) {
    colors[i] = color( random(255), random(255), random(255) );
    chars[i] = char( int ('A') + int( random(26) ) );
  }
}

void draw() {
  background(0);
  translate(20,20);
  int t = 0;
  for ( int y = 0; y < 10; y++ ) {
    for ( int x = 0; x < 10; x++ ) {
      fill( colors[t] );
      text( chars[t], 10 + 40 * x, 30 + 40 * y );
      t++;
    }
  }
}

Could you maybe draw a mock up image of what you want?

1 Like

@MAKESHADY – Note that one of the official Processing examples on the site is Keyboard Functions – an adaptation of John Maeda’s Color Typewriter:

https://processing.org/examples/keyboardfunctions.html

Based on your description it seems like this example might be relevant.