Skip to content

Instantly share code, notes, and snippets.

@andrew-dash
Created September 28, 2014 20:25
Show Gist options
  • Select an option

  • Save andrew-dash/1980e17adcded527872e to your computer and use it in GitHub Desktop.

Select an option

Save andrew-dash/1980e17adcded527872e to your computer and use it in GitHub Desktop.
Week 2 OF Graphics Example
/*
*
* interactive art & creative coding
* ofSketch class demo
* Week 2
*
*/
// variable declaration
int x;
int myVariable;
int speed;
int increment;
// colors for balloon
int r;
int g;
int b;
void setup() {
x = 250;
speed = 60;
increment = 0;
ofSetCircleResolution(100);
ofSetWindowShape(800, 800);
ofEnableAlphaBlending();
ofBackground(255,0,80);
ofSetFrameRate(speed);
ofSetWindowTitle("Look at my Balloon!");
// generate a random starting color for the balloon
r = ofRandom(127,255);
g = ofRandom(127,255);
b = ofRandom(127,255);
}
void draw() {
// check to see if the text went off screen
if (increment > ofGetWindowWidth() ){
increment = 0;
}
// pseudo mountains
ofNoFill();
ofSetColor(0,255,0);
ofTriangle(0, 800, 200, 600, 400, 800);
ofTriangle(100, 800, 300, 600, 500, 800);
ofTriangle(400, 800, 600, 600, 800, 800);
ofFill();
// drawing a square purple cloud
ofSetColor(0,0,255,100);
ofRect(50,50,600,600);
// drawing a vertical line for my balloon string
ofSetColor(0,255,0);
ofLine(mouseX, 100, mouseX, 400);
// now i have a balloon!
ofSetColor(r,g,b);
ofEllipse(mouseX,140,100,120);
// move text across the screen
increment++;
ofSetColor(255);
ofDrawBitmapString("This is my cool balloon", increment, mouseY);
// ofLogNotice("This is a random color") << thisColor;
}
// use key presses to generate new balloon colors
void keyPressed(int key)
{
if('r' == key) {
// generate a random red value
r = ofRandom(127,255);
} else if('g' == key) {
// generate a random red value
g = ofRandom(127,255);
} else if('b' == key) {
// generate a random red value
b = ofRandom(127,255);
} else if(' ' == key)
{
ofToggleFullscreen();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment