Skip to content

Instantly share code, notes, and snippets.

@ramayac
Created February 28, 2014 22:43
Show Gist options
  • Save ramayac/9281588 to your computer and use it in GitHub Desktop.
Save ramayac/9281588 to your computer and use it in GitHub Desktop.
A simple clone of http://spreeder.com/index.php made in processing with drag & drop support.
/*
Primera version 0.1 28/Feb/2014
Segunda version 0.2 28/Feb/2014
@author ramayac
*/
import sojamo.drop.*;
SDrop drop;
String[] palabras = null;
String palabraActual = "";
int wpm = 0;
float time = 0.0;
float timerDelay = 0.0;
boolean archCargado = false, paused = false;
int countPalabra = 0, totalDePalabras = 0;
boolean sleep() {
if ( millis() > time ) {
time = millis() + timerDelay;
return true;
}
return false;
}
void setup() {
size(400, 200);
frameRate(30);
drop = new SDrop(this);
timerDelay = wpm/60*10;
println(" timer delay: " + timerDelay);
time = millis() + timerDelay;
textAlign(CENTER, CENTER);
fill(#ffeeee);
}
void draw() {
background(0);
textSize(32);
text(palabraActual, width/2, height/2);
textSize(10);
text("Palabras restantes:" + (totalDePalabras-countPalabra), width/2, 10);
if (archCargado && paused == false) {
if (sleep()) {
if(countPalabra < totalDePalabras){
if(palabras[countPalabra] == null){
return;
} else {
palabraActual = palabras[countPalabra];
}
countPalabra++;
}
}
}
}
void dropEvent(DropEvent theDropEvent) {
if (theDropEvent.isFile()) {
String fileName = theDropEvent.toString();
//println(fileName);
String[] textoLineas = loadStrings(fileName);
totalDePalabras = cuentaPalabras(textoLineas);
//println("total de palabras: " + contPal);
palabras = new String[totalDePalabras];
int iaux = 0; String saux = "";
for (int i = 0; i < textoLineas.length; i++) {
String[] lineaPalabras = textoLineas[i].split(" ");
for(int j = 0; j < lineaPalabras.length; j++){
saux = trim(lineaPalabras[j]);
//println(saux);
if(saux == ""){
continue;
} else {
palabras[iaux] = saux;
iaux++;
}
}
}
//println(palabras);
archCargado = true;
}
}
int cuentaPalabras(String[] lineas) {
int contadorPalabras = 0;
for (int i = 0; i < lineas.length; i++) {
String[] palabras = lineas[i].split(" ");
//println("countPalabra : " + countPalabra + ", palabras.length: " + palabras.length);
contadorPalabras += palabras.length;
}
return contadorPalabras;
}
void keyPressed() {
if (key == 'p') {
paused = !paused;
println("paused: " + paused);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment