Skip to content

Instantly share code, notes, and snippets.

@ignisan
Created May 24, 2016 13:29
Show Gist options
  • Save ignisan/38740368df49af5499e140e2bf04e088 to your computer and use it in GitHub Desktop.
Save ignisan/38740368df49af5499e140e2bf04e088 to your computer and use it in GitHub Desktop.
#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());
}
#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){
}
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);
};
#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() {
}
#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