//'s' stops //'p' plays //'v' saves the frame to numbered tiff file Scri scri; PFont font; String lines[]; String txt[]; boolean playing = false; boolean help_screen_on; int counter = 0; void setup(){ lines = loadStrings("freud-dream_psychology.txt"); font = loadFont("Times-Roman-48.vlw"); //size(screen.width, screen.height); size(640, 480); help_screen(); noStroke(); fill(0); scri = new Scri(width/2, height/2); textAlign(CENTER); framerate(16); } void draw(){ //-----key commands------------ //play if(keyPressed){ if(key=='h'){ help_screen(); } } if(keyPressed){ if((key=='p')||(key=='P')){ playing=true; if(help_screen_on){ background(255); help_screen_on=false; } } } //stop if(keyPressed){ if((key=='s')||(key=='S')){ playing=false; } } //save frame (mysteriously slows down framerate) if(keyPressed){ if((key=='v')||(key=='V')){ saveFrame(); } } ///set font_factor if(keyPressed){ if(key=='1'){ scri.fontfactor=1; } } if(keyPressed){ if(key=='2'){ scri.fontfactor=2; } } if(keyPressed){ if(key=='3'){ scri.fontfactor=3; } } if(keyPressed){ if(key=='4'){ scri.fontfactor=4; } } if(keyPressed){ if(key=='5'){ scri.fontfactor=5; } } if(keyPressed){ if(key=='6'){ scri.fontfactor=6; } } if(keyPressed){ if(key=='7'){ scri.fontfactor=7; } } if(keyPressed){ if(key=='8'){ scri.fontfactor=8; } } if(keyPressed){ if(key=='9'){ scri.fontfactor=9; } } //set framerate if(keyPressed){ if(key=='q'){ framerate(1); } } if(keyPressed){ if(key=='w'){ framerate(2); } } if(keyPressed){ if(key=='e'){ framerate(4); } } if(keyPressed){ if(key=='r'){ framerate(8); } } if(keyPressed){ if(key=='t'){ framerate(16); } } if(keyPressed){ if(key=='y'){ framerate(32); } } if(keyPressed){ if(key=='u'){ framerate(64); } } if(keyPressed){ if(key=='i'){ framerate(128); } } String line_array[] = split(lines[int(random(lines.length-1))]); if((line_array.length>1)&&(playing)){ String selected_word = line_array[int(random(line_array.length-1))]; scri.place_text(selected_word, 0); } } void help_screen(){ help_screen_on = true; playing = false; background(255); fill(0); textAlign(LEFT); textFont(font, 15); text("key controls:\n1-9: change potential font size\nq,w,e,r,t,y,u,i: change speed\no (hold): change font color to white\ns: stop\np: play\nh: this help screen", 10, 25); textFont(font, 40); text("press p to start\n", 10, 200); textFont(font, 15); text("at slower framerates, keys must be held longer.", 10, 250); } //-------------------functions&classes drawing----------- boolean cointoss(){ if(random(1)>0.5){ return true; } else{ return false; } } int get_expstep(int factor, int possible_depth){ int current_depth = 2; float step = 0.0; while((cointoss())&&(current_depth<=possible_depth)){ step = pow(factor, current_depth); current_depth+=1; } return int(step); } class Scri { int x; int y; int moves_made; int min_font_size; int font_size; int font_step; int xfactor; int yfactor; int fontfactor; Scri(int xin, int yin){ x = xin; y = yin; moves_made = 0; xfactor = 3; yfactor = 3; fontfactor = 1; } void place_text(String word, int white_level){ int oldx = x; int oldy = y; min_font_size = 10; int xstep = get_expstep(xfactor,5); int ystep = get_expstep(yfactor,5); font_step = get_expstep(fontfactor,5); font_size = min_font_size + font_step; if(cointoss()){ x+=xstep; } else{ x-=xstep; } if(cointoss()){ y+=ystep; } else{ y-=ystep; } if((x>=0)&&(x<=width)&&(y>=0)&&(y<=height)){ fill(white_level); if((keyPressed)&&(key=='o')){ fill(255-white_level); } textFont(font, font_size); text(word, x, y); moves_made++; } if((x<0)||(x>width)||(y<0)||(y>height)){ x = oldx; y = oldy; } } }