Skip to content

Instantly share code, notes, and snippets.

@TooManyBees
Last active January 18, 2020 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TooManyBees/f44ae4cf0f1937b58b8f931e7fe9d805 to your computer and use it in GitHub Desktop.
Save TooManyBees/f44ae4cf0f1937b58b8f931e7fe9d805 to your computer and use it in GitHub Desktop.
openFrameworks wires
#include "ofApp.h"
void lineThroughPoint(const glm::vec2 &i, float slope, glm::vec2 &p1, glm::vec2 &p2) {
float x1 = i.x - i.y / slope;
float x2 = i.x + (ofGetHeight() - i.y) / slope;
p1.x = x1; p1.y = 0;
p2.x = x2; p2.y = ofGetHeight();
}
void drawRandomLine(const glm::vec2 &focus) {
glm::vec2 p(ofRandomWidth(), ofRandomHeight());
glm::vec2 slope = glm::normalize(p - focus);
{ float temp = slope.x; slope.x = -slope.y; slope.y = temp; }
float add = ofRandomf() * 0.8;
float newSlope = (slope.y + add) / (slope.x + add);
glm::vec2 p1, p2;
lineThroughPoint(p, newSlope, p1, p2);
ofDrawLine(p1, p2);
}
void drawWiresAround(glm::vec2 focus, size_t n) {
for (size_t i = 0; i < n; i++) {
drawRandomLine(focus);
}
}
//--------------------------------------------------------------
void ofApp::draw() {
ofBackgroundGradient(ofColor(200, 120, 0), ofColor::black, OF_GRADIENT_CIRCULAR);
glm::vec2 focus(ofGetMouseX(), ofGetMouseY());
drawWiresAround(focus, 2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment