Skip to content

Instantly share code, notes, and snippets.

@mnmly
Last active August 29, 2015 14:00
Show Gist options
  • Save mnmly/11236577 to your computer and use it in GitHub Desktop.
Save mnmly/11236577 to your computer and use it in GitHub Desktop.
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
ofBackground(255);
ofEnableSmoothing();
layoutPoints();
}
//--------------------------------------------------------------
void ofApp::update(){
for(int i = 0; i < points.size(); i++) {
float xOffset = 0.1 * cos(TWO_PI * i / (float)points.size());
float yOffset = -0.1 * sin(TWO_PI * i / (float)points.size());
if(toggle) {
ofPoint p = points[i];
p.x += xOffset;
p.y += yOffset;
} else {
ofPoint &p = points[i];
p.x += xOffset;
p.y += yOffset;
}
ofPoint *pp = pointerPoints[i];
pp->x += xOffset;
pp->y += yOffset;
}
}
//--------------------------------------------------------------
void ofApp::draw(){
drawInstruction();
ofFill();
ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2);
ofSetColor(115, 19, 255);
// Draw points
for(int i = 0; i < points.size(); i++) {
float x, y;
if(toggle) {
ofPoint p = points[i];
x = p.x;
y = p.y;
} else {
ofPoint &p = points[i];
x = p.x;
y = p.y;
}
ofCircle(x, y, 10);
}
// Draw points stored as pointers
ofSetColor(19, 209, 255);
for(int i = 0; i < pointerPoints.size(); i++) {
ofPoint *pp = pointerPoints[i];
ofRect(pp->x - 5, pp->y - 5, 10, 10);
}
}
void ofApp::drawInstruction() {
ofSetColor(30, 30, 30);
string message = "Press T to toggle manipulating reference or copy:\n\nCurrently manipulating: ";
message += (toggle ? "\"COPY\"" : "\"REFERENCE\"");
ofDrawBitmapString(message, ofPoint(40, 40));
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
if('t' == key) toggle = !toggle;
}
void ofApp::layoutPoints() {
int row = 10;
int col = 10;
int padding = 30;
toggle = false;
for(int i = 0; i < row; i++) {
float y = (i - row / 2.0) * padding;
for(int j = 0; j < col; j++) {
float x = (j - col / 2.0) * padding;
// Make normal ofPoint
ofPoint p(x, y);
points.push_back(p);
// Make ofPoint pointer
ofPoint *pp = new ofPoint(x, y);
pointerPoints.push_back(pp);
}
}
}
#pragma once
#include "ofMain.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void layoutPoints();
void drawInstruction();
void keyPressed(int key);
vector < ofPoint > points;
vector < ofPoint* > pointerPoints;
bool toggle;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment