Created
May 24, 2016 13:29
-
-
Save ignisan/38740368df49af5499e140e2bf04e088 to your computer and use it in GitHub Desktop.
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
#include "ofMain.h" | |
#include "ofApp.h" | |
//======================================================================== | |
int main( ){ | |
ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context | |
// this kicks off the running of my app | |
// can be OF_WINDOW or OF_FULLSCREEN | |
// pass in width and height too: | |
ofRunApp(new ofApp()); | |
} |
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
#include "ofApp.h" | |
#include "Square.h" | |
//-------------------------------------------------------------- | |
void ofApp::setup(){ | |
const int marginx=80; | |
const int blocksw = ofGetWidth()-marginx*2; | |
const int offsetx = ofGetWidth()-blocksw-marginx; | |
const int size = blocksw/W; | |
const int blocksh = size*H; | |
const int offsety = (ofGetHeight()-blocksh)/2; | |
for(int i=0;i<H;++i) { | |
for(int j=0;j<W;++j) { | |
const int left = j*size + offsetx; | |
const int top = i*size + offsety; | |
const ofColor color(ofRandom(255),ofRandom(255),ofRandom(255)); | |
Square square; | |
square.setup(left,top,size,size,color); | |
squares.emplace_back(square); | |
} | |
} | |
} | |
//-------------------------------------------------------------- | |
void ofApp::update(){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::draw(){ | |
ofBackground(ofColor(10,10,10)); | |
for(auto& square: squares) { | |
square.draw(); | |
} | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyPressed(int key){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyReleased(int key){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseMoved(int x, int y ){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseDragged(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mousePressed(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::gotMessage(ofMessage msg){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::dragEvent(ofDragInfo dragInfo){ | |
} |
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
l#pragma once | |
#include "ofMain.h" | |
#include "Square.h" | |
#include <vector> | |
class ofApp : public ofBaseApp{ | |
static const int W = 10; | |
static const int H = 6; | |
std::vector<Square> squares; | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
void keyPressed(int key); | |
void keyReleased(int key); | |
void mouseMoved(int x, int y ); | |
void mouseDragged(int x, int y, int button); | |
void mousePressed(int x, int y, int button); | |
void mouseReleased(int x, int y, int button); | |
void mouseEntered(int x, int y); | |
void mouseExited(int x, int y); | |
void windowResized(int w, int h); | |
void dragEvent(ofDragInfo dragInfo); | |
void gotMessage(ofMessage msg); | |
}; |
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
#include "Square.h" | |
void Square::setup(int left,int top,int width,int height,ofColor color) | |
{ | |
this->left = left; | |
this->top = top; | |
this->width = width; | |
this->height = height; | |
this->color = color; | |
} | |
void Square::draw() { | |
const int lw = 2; // linewidth | |
ofPushStyle(); | |
ofSetColor(ofColor(50,50,50)); | |
ofDrawRectangle(left,top,width,height); | |
ofSetColor(color); | |
ofDrawRectangle(left+lw,top+lw,width-lw*2,height-lw*2); | |
ofPopStyle(); | |
} | |
void Square::clear() { | |
} |
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
#pragma once | |
#include "ofMain.h" | |
class Square { | |
public: | |
void setup(int left,int top,int width,int height,ofColor color); | |
void draw(); | |
void clear(); | |
private: | |
int left,top,width,height; | |
ofColor color; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment