Skip to content

Instantly share code, notes, and snippets.

@ofZach
Last active July 26, 2016 17:56
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 ofZach/88abc3aed0462121279913e87401b19c to your computer and use it in GitHub Desktop.
Save ofZach/88abc3aed0462121279913e87401b19c to your computer and use it in GitHub Desktop.
many lines from wall to wall
#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