Created
December 6, 2011 04:49
-
-
Save kuzyn/1436797 to your computer and use it in GitHub Desktop.
s.t.e.v.e.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//*** | |
//Class that load and read instructions | |
//** | |
class Instructions extends Thread { | |
// -----properties | |
String fileName; | |
int nbLines; | |
String[] instrLines; | |
boolean running; | |
int wait; | |
String id; | |
int count; | |
// ----constructors | |
public Instructions(int w, String s) { | |
wait = w; | |
running = false; | |
id = s; | |
count = 0; | |
} | |
// Overriding "start()" //threading part taken from processing's wiki | |
void start () { | |
// Set running equal to true | |
running = true; | |
// Print messages | |
println("Starting thread (will execute every " + wait + " milliseconds.)"); | |
// Do whatever start does in Thread, don't forget this! | |
super.start(); | |
} | |
// We must implement run, this gets triggered by start() | |
void run () { | |
while (running && count < 10) { | |
println(id + ": " + count); | |
count++; | |
// Ok, let's wait for however long we should wait | |
try { | |
sleep((long)(wait)); | |
} | |
catch (Exception e) { | |
} | |
} | |
System.out.println(id + " thread is done!"); // The thread is done when we get to the end of run() | |
} | |
// Our method that quits the thread | |
void quit() { | |
System.out.println("Quitting."); | |
running = false; // Setting running to false ends the loop in run() | |
// IUn case the thread is waiting. . . | |
interrupt(); | |
} | |
public void read(String fName) { | |
instrLines = loadStrings(fName); | |
nbLines = instrLines.length ; | |
} | |
public void write() { | |
for (int x = 0; x<= nbLines; x++) { | |
steveVoice.speak("This is line" + (x+1)); | |
delay(2000); | |
steveVoice.speak(instrLines[x]); | |
delay(1000); | |
if ((x)%3 == 2) { | |
steveVoice.speak("Pass the instructions to the next organic processing unit"); | |
text("testtestets", 222,222); | |
delay(5000); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PFont normalFont; | |
int fontSize = 16; | |
int timeStart = millis(); | |
color backColor = #1C0A01; | |
color textColor = #93360A; | |
String textInput = " "; | |
boolean waitInput = false; // | |
boolean oneSec = false; //switch on/off at every second | |
boolean readNow = false; | |
boolean newFact = false; | |
int secCounter = 0; | |
int lineNumber = 0; | |
int currentLineX = 110; | |
int currentLineY = 120; | |
int loadCounter = 0; | |
int ranLines = 0; | |
String loadText = "Loading"; | |
void setup() { | |
background(0); | |
size(800, 600); | |
textSize(fontSize); | |
normalFont = loadFont("Monospaced.plain-48.vlw"); | |
noStroke(); | |
ClearScreen(); | |
} | |
void ClearScreen() { | |
fill(backColor); | |
quad(100, 100, 100, 500, 700, 500, 700, 100); | |
//println("ClearScreen()"); | |
} | |
void Loading() { | |
int lposX = width/2; | |
int lposY = height/2; | |
textAlign(CENTER); | |
while (secCounter - loadCounter == 1) | |
{ | |
ClearScreen(); | |
println(loadText); | |
fill(textColor); | |
text(loadText, lposX, lposY); | |
loadText = loadText + "."; | |
loadCounter = secCounter; | |
if (loadText.length()==11) | |
{ | |
newFact = !newFact; | |
String[] steveFacts = loadStrings("data/facts.txt"); | |
ranLines = int(random(steveFacts.length)); | |
print(newFact); | |
loadText = "Loading"; | |
} | |
} | |
} | |
void newFact() { | |
String[] steveFacts = loadStrings("data/facts.txt"); | |
if (newFact == true) { | |
fill(textColor); | |
text(steveFacts[ranLines], width/2, height/2+(fontSize*2)); | |
} | |
} | |
void Timer() { | |
for (int x = 1000; (millis()-timeStart) > x; timeStart = millis()) | |
{ | |
oneSec = !oneSec; | |
secCounter++; | |
println(secCounter); | |
} | |
} | |
void draw() { | |
Timer(); | |
Loading(); | |
newFact(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cimport guru.ttslib.*; | |
TTS steveVoice; | |
PFont normalFont; | |
int fontSize = 16; | |
int timeStart = millis(); | |
color backColor = #1C0A01; | |
color textColor = #93360A; | |
String textInput = " "; | |
boolean waitInput = false; // | |
boolean oneSec = false; //switch on/off at every second | |
boolean readNow = false; | |
int secCounter = 0; | |
int lineNumber = 0; | |
int currentLineX = 110; | |
int currentLineY = 120; | |
int loadCounter = 0; | |
Instructions newSet; | |
Instructions newJokes; | |
String loadText = "Loading"; | |
void setup() { | |
steveVoice = new TTS(); | |
background(0); | |
size(800, 600); | |
textSize(fontSize); | |
normalFont = loadFont("Monospaced.plain-48.vlw"); | |
noStroke(); | |
ClearScreen(); | |
newSet = new Instructions(1000, "a"); | |
newSet.read("data/instructionsBYTESformated.txt"); | |
newJokes = new Instructions(1000, "b"); | |
newJokes.read("data/steve.txt"); | |
} | |
void draw() { | |
Timer(); | |
Welcome(); | |
if (readNow) { | |
readInstructions(); | |
} | |
} | |
void ClearScreen() { | |
fill(backColor); | |
quad(100, 100, 100, 500, 700, 500, 700, 100); | |
//println("ClearScreen()"); | |
} | |
void Loading() { | |
int lposX = width/2; | |
int lposY = height/2; | |
textAlign(CENTER); | |
while (secCounter - loadCounter == 1) | |
{ | |
ClearScreen(); | |
println(loadText); | |
fill(textColor); | |
text(loadText, lposX, lposY); | |
loadText = loadText + "."; | |
loadCounter = secCounter; | |
if (loadText.length()==11) | |
{ | |
loadText = "Loading"; | |
} | |
} | |
} | |
void readInstructions() { | |
newSet.write(); | |
} | |
void Welcome() { | |
fill(textColor); | |
String lines[] = loadStrings("data/logo.txt"); | |
if (oneSec == false && lineNumber < lines.length) { | |
text(lines[lineNumber], currentLineX, currentLineY+lineNumber*fontSize); | |
lineNumber++; | |
} | |
if (secCounter == 10) { | |
ClearScreen(); | |
lineNumber = 0; | |
fill(textColor); | |
textAlign(LEFT); | |
text("#Congratulation, you bought a cutting edge, organic image processor! You've just entered a world of infinite possibilities, what are you going to do with all that power?\n#Press the enter key to unleach the power of S.T.E.V.E.", 100, 100, 500, 500); | |
delay(2000); | |
newSet.write(); | |
lineNumber = lines.length; | |
} | |
} | |
void Timer() { | |
for (int x = 1000; (millis()-timeStart) > x; timeStart = millis()) | |
{ | |
oneSec = !oneSec; | |
secCounter++; | |
println(secCounter); | |
} | |
} | |
void keyTyped() { | |
if (waitInput == false) { | |
if (key == BACKSPACE) { | |
if (textInput.length() > 0) { | |
textInput = textInput.substring(0, textInput.length() - 1); | |
} | |
else { | |
textInput += key; | |
} | |
} | |
print(textInput); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment