#include "ofApp.h"
void ofApp::setup() {
ofBackgroundHex(0xc5c9b2);
bTimerReached = false;
startTime = ofGetElapsedTimeMillis();
endTime = (int)ofRandom(1000, 5000);
}
void ofApp::update() {
}
void ofApp::draw(){
float barWidth = 500;
float timer = ofGetElapsedTimeMillis() - startTime;
if(timer >= endTime && !bTimerReached) {
bTimerReached = true;
ofMessage msg("Timer Reached");
ofSendMessage(msg);
}
ofSetColor(100);
ofDrawRectangle((ofGetWidth()-barWidth)/2, ofGetHeight()/2, barWidth, 30);
float pct = ofMap(timer, 0.0, endTime, 0.0, 1.0, true);
ofSetHexColor(0xf02589);
ofDrawRectangle((ofGetWidth()-barWidth)/2, ofGetHeight()/2, barWidth*pct, 30);
ofSetColor(20);
ofDrawBitmapString(ofToString(pct*100, 0)+"%", ((ofGetWidth()-barWidth)/2)+barWidth+10, (ofGetHeight()/2)+20);
if(bTimerReached) {
ofSetColor(20);
ofDrawBitmapString("Timer Reached!", (ofGetWidth()-100)/2, (ofGetHeight()/2)+70);
}
string info = "FPS: "+ofToString(ofGetFrameRate(),0)+"\n";
info += "Start Time: "+ofToString(startTime, 1)+"\n";
info += "End Time: "+ofToString(endTime/1000.0, 1)+" seconds\n";
info += "Timer: "+ofToString(timer/1000.0, 1)+" seconds\n";
info += "Percentage: "+ofToString(pct*100, 1)+"%\n";
info += "\nPress ' ' to get a new random end time\n";
ofSetColor(0);
ofDrawBitmapString(info, 20, 20);
}
void ofApp::keyPressed(int key) {
if(key == ' ') {
bTimerReached = false;
startTime = ofGetElapsedTimeMillis();
endTime = (int)ofRandom(1000, 5000);
}
}
void ofApp::mousePressed(int x, int y, int button) {
startTime = ofGetElapsedTimeMillis();
endTime = (int)ofRandom(100, 5000);
}
void ofApp::gotMessage(ofMessage msg){
cout << "Got the message: " + msg.message << endl;
}
void ofApp::keyReleased(int key){
}
void ofApp::mouseMoved(int x, int y){
}
void ofApp::mouseDragged(int x, int y, int button){
}
void ofApp::mouseReleased(int x, int y, int button){
}
void ofApp::mouseEntered(int x, int y){
}
void ofApp::mouseExited(int x, int y){
}
void ofApp::windowResized(int w, int h){
}
void ofApp::dragEvent(ofDragInfo dragInfo){
}
Comments