import processing.opengl.*; import fullscreen.*; /** * Copyright (c) 2007 Daniele Poggi */ //variabili int WIDTH = 800; int HEIGHT = 600; int DROP_LIMIT = 10; int COUNT_LIMIT = 50; int Z_DEPTH = 40; int Z_COEFFICIENT = 15; int FONT_DIM = WIDTH/30; float COUNTDOWN_SECONDS = 50; int X_INCREMENT = WIDTH/8; float Y_ACCELERATION = 0.7; float ANGLE_INCREMENT = TWO_PI/(HEIGHT/4); //setup generale TextList textlist; boolean start = false; int modo; boolean changed_mode = false; PImage base; //setup lettura testo String[] parole; String[] parole_chiave; int[] valori_chiave; int current_text = 0; //setup dell'animazione int cntdwn = -1; int xtrans = 0; //fullscreen setup FullScreen fs; //A fullscreen object boolean fsb; float counter_tempo = 0; void setup() { size(WIDTH,HEIGHT,OPENGL); frameRate(24); noStroke(); //smooth(); //fullscreen init fs = new FullScreen(this); fsb = false; //text init textlist = new TextList(); //carico l'immagine base base = loadImage("base800.png"); //carica il testo in memoria parole = loadText("testo"); parole_chiave = loadText("riassunto"); valori_chiave = createArrayZAnimation(parole, parole_chiave); directionalLight(126, 126, 126, 0, 0, -1); ambientLight(102, 102, 102); } void draw() { background(30); if (start) { //image(base, 0, HEIGHT-100); if (cntdwn == -1) cntdwn = round(random(COUNTDOWN_SECONDS)); updateTextObject(); textlist.draw(); counter_tempo ++; //spotLight(51, 102, 126, mouseX, mouseY, 40, -1, 0, 0, PI/2, 2); } else { fill(230); textFont(createFont("LucidaGrande", FONT_DIM)); text("Presentazione",width/2,height/2); textFont(createFont("LucidaGrande", FONT_DIM-2)); text("Premi 'a' per iniziare",width/2,height/2 + 55); text("Premi 'd' per terminare",width/2,height/2 + 110); noFill(); if (counter_tempo != 0) { System.out.println("Terminato in : " + counter_tempo + " frame pari a " + counter_tempo/24 + " secondi."); counter_tempo = 0; } } } void keyPressed() { // if the key is between 'A'(65) and 'z'(122) if( key == 'a' || key == 'A') { modo = 1; start = true; } if( key == 's' || key == 'S') { modo = 2; start = true; } if( key == 'd' || key == 'D') { modo = 3; reset(); } if( key == 'q' || key == 'Q') { if (Y_ACCELERATION > 0) Y_ACCELERATION -= 0.1; else Y_ACCELERATION=0; COUNTDOWN_SECONDS ++; System.out.println("Y_ACCELERATION: " + Y_ACCELERATION); System.out.println("COUNTDOWN_SECONDS: " +COUNTDOWN_SECONDS); } if( key == 'w' || key == 'W') { Y_ACCELERATION += 0.1; if (COUNTDOWN_SECONDS > 0) COUNTDOWN_SECONDS --; else COUNTDOWN_SECONDS=0; System.out.println("Y_ACCELERATION: " + Y_ACCELERATION); System.out.println("COUNTDOWN_SECONDS: " + COUNTDOWN_SECONDS); } if( key == 'e' || key == 'E') { if (Z_COEFFICIENT > 0) Z_COEFFICIENT --; else Z_COEFFICIENT=0; System.out.println("Z_COEFFICIENT: " + Z_COEFFICIENT); } if( key == 'r' || key == 'R') { Z_COEFFICIENT ++; System.out.println("Z_COEFFICIENT: " + Z_COEFFICIENT); } if( key == 'f' || key == 'F') { if (fsb == true) { fs.setResolution(WIDTH, HEIGHT); fs.leave(); fsb = false; } else { //fs.setResolution(1680, 1050); fs.enter(); fsb = true; } } } String[] loadText(String filename) { String[] testo; String[] parole; int word_counter; int counter = 0; System.out.println("Loading '" + filename + "' file..."); testo = loadStrings(filename + ".txt"); if(testo != null) { //conta quante parole ci sono nel testo for (int i=0; i= (WIDTH - X_INCREMENT)) { xtrans = X_INCREMENT; } x = xtrans; y = -10; angle = random(360); z = zrand; txt = parole[current_text]; yvelocity = random(0.3) + Y_ACCELERATION; textlist.activate(index); textlist.update(index, x, y, angle, ANGLE_INCREMENT, txt, yvelocity, z); current_text += 1; } void mouseMoved() { //int temp = ((mouseX * 10) / width) + 1; //numero da 0 a 10 //COUNT_LIMIT = temp; //System.out.println("COUNT_LIMIT set: " + COUNT_LIMIT); } void reset() { start = false; current_text = 0; cntdwn = -1; modo = -1; } //-------------------------------------------------------------------------------------------------- //helper classes class TextList { java.util.Hashtable objectList; private int count_text; //numero attuale di testi fluttuanti private Integer temp_id; TextList() { objectList = new Hashtable(); count_text = 0; textFont(createFont("Courier", FONT_DIM*3)); } void draw() { Enumeration e = objectList.elements(); while (e.hasMoreElements()) { TextObject textobj = (TextObject)e.nextElement(); //analizzo ciascun testo fluttuante if (textobj.finished) deactivate(textobj.session_id); else textobj.draw(); } } int getCountText() { return count_text; } void setCountText(int sct) { this.count_text = sct; } TextObject getObject(int s_id) { temp_id = new Integer(s_id); return (TextObject)objectList.get(temp_id); } void activate(int s_id) { TextObject nobj = new TextObject(s_id); temp_id = new Integer(s_id); objectList.put(temp_id,nobj); count_text ++; } void deactivate(int s_id) { temp_id = new Integer(s_id); objectList.remove(temp_id); count_text --; } void update(int s_id, float xpos, float ypos, float angle, float inc, String txt, float yvelocity, float z) { temp_id = new Integer(s_id); TextObject tobj = (TextObject)objectList.get(temp_id); if (tobj!=null) tobj.update(xpos,ypos,angle,inc,txt,yvelocity,z); } } class TextObject { int session_id; float xpos, ypos, angle, inc, yvelocity, colorz, z; String txt; boolean finished; TextObject(int s_id) { session_id = s_id; finished = false; //textAlign(CENTER); } void update(float xpos, float ypos, float angle, float inc, String txt, float yvelocity, float z) { this.xpos = xpos; this.ypos = ypos; this.angle = angle; this.inc = inc; this.txt = txt; this.yvelocity = yvelocity; this.z = z; //se z=0 colorz=100, se z=-60 colorz=250 colorz = round((((z + 60)/60)*150)+100); //numero da 100 a 250 } void draw() { updateMovement(); fill(colorz); text(txt, xpos, ypos, z*20); //System.out.println(session_id + " text has width: " + text.width); noFill(); } void updateMovement() { if (ypos < height) { xpos += sin(angle)/10; //if (session_id == 0) System.out.println("sin: " + sin(angle) + " xpos: " + xpos); angle += inc; ypos += yvelocity; } else { finished = true; } } }