Visual Poetry

For this weeks project, I created a visualization tool that turns characters of a text file into circles on the screen. The parameters are based on the ascii code of each characters.

I tried to use supercollider to generate sound based on ascii code as well, but for some reason, the code is running but there is no sound coming out. So instead, I am using MidiBus library to generate simple MIDI sound based on the ascii code. The value of ascii is set to the pitch of the sound.

In order to run this, you need to download the MidiBus library into your sketchbook directory.

import java.io.*;
import themidibus.*;

MidiBus myBus;

String poem[];
char[] charArray;
int[] asciiArray = new int[1000];

int counter = 0;

void setup(){
  poem = loadStrings("poem.txt");
  for(int i=0; i < poem.length; i++){
    charArray = poem[i].toCharArray();
    for(int j=0; j<charArray.length; j++){
      asciiArray[counter] = (int)charArray[j];
      counter++;
    }
  }
  counter = 0;
  
  size(500, 500);
  background(255);
  frameRate(6);
  
  MidiBus.list();
  
  myBus = new MidiBus(this, -1, 1);

}

void draw(){
  int channel = 0;
  int pitch;
  int velocity = 100;
  
  println(asciiArray[counter]);
  Ball ball = new Ball(asciiArray[counter]);
  ball.render();
  
  pitch = asciiArray[counter];
  
  myBus.sendNoteOn(channel, pitch, velocity);
  delay(100);
  
  if(asciiArray[counter] == 32){
    delay(1000);
  }
  
  myBus.sendNoteOff(channel, pitch, velocity);
  
  int number = 0;
  int value = 90;
  myBus.sendControllerChange(channel, number, value);
  
  counter++;
}

And below is the code for class “Ball”:

class Ball{
  
  float xPos = width/2;
  float yPos = width/2;
  float R;
  float G;
  float B;
  
  int ascii;
  
  Ball(int a){
    ellipseMode(CENTER);
    ascii = a;
    
    R = random(0, a);
    G = random(0, a);
    B = random(0, a);
    
  }
  
  void render(){
    if(ascii == 32){
      fill(255, 75);
      ellipse(xPos, yPos, ascii*4, ascii*4);
    }
    else{
      noStroke();
      fill(R, G, B, 75);
      ellipse(xPos, yPos, ascii*4, ascii*4);
    }
  }
  
}

 

Leave a Reply