Last active
July 26, 2016 17:56
-
-
Save ofZach/88abc3aed0462121279913e87401b19c to your computer and use it in GitHub Desktop.
many lines from wall to wall
This file contains hidden or 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" | |
//-------------------------------------------------------------- | |
void ofApp::setup(){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::update(){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::draw(){ | |
ofBackground(0); | |
// make a polyline which is the screen dimensions | |
ofPolyline screen; | |
screen.addVertex(ofPoint(0,0)); | |
screen.addVertex(ofPoint(1024,0)); | |
screen.addVertex(ofPoint(1024, 1024)); | |
screen.addVertex(ofPoint(0, 1024)); | |
screen.setClosed(true); | |
float f = ofGetElapsedTimef(); | |
ofPoint anglePt = ofPoint(cos(f), sin(f)); | |
ofSetColor(255,255,255,20); | |
for (int i = 0; i < 20000; i++){ | |
int randomWall = ofRandom(0,4); | |
int randomOtherWall = (int) (randomWall + ofRandom(1,3)) % 4; | |
float pctA = ofRandom(0,1); | |
float pctB = ofRandom(0,1); | |
ofPoint a = screen[randomWall] * (1-pctA) + screen[(randomWall + 1) % 4] * (pctA); | |
ofPoint b = screen[randomOtherWall] * (1-pctB) + screen[(randomOtherWall + 1) % 4] * (pctB); | |
ofPoint intersects; | |
float dist = ofMap(sin(f), -1, 1, 0, 512); | |
bool bIntersects = ofLineSegmentIntersection(a, b, ofPoint(512, 512) - dist*anglePt, ofPoint(512,512) + dist*anglePt, intersects); | |
if (bIntersects){ | |
ofDrawLine(a,b); | |
} | |
} | |
} | |
//-------------------------------------------------------------- | |
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){ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment