Nick Inzucchi – 13-9-65

by nick @ 8:02 pm 21 January 2012


 

#include "testApp.h"
 
int gap = 30;	// Ev!l globals
int noise = 4;
int nLines = 8;
int nPoints = 8;
int nCircles = 8;
 
//--------------------------------------------------------------
void testApp::setup(){
	ofBackground(255,255,255);
 
	ofNoFill();			// Setup Drawing
	ofSetColor(0,0,0);
	ofSetLineWidth(2);
}
 
//--------------------------------------------------------------
void testApp::draw(){
	drawLines();			// Draw each component
	drawStripes();
	drawCircles();
 
	ofSaveScreen(ofToString(ofGetFrameNum()));
	ofSleepMillis(2000);		// Save screen / rest
}
 
void testApp::drawLines(){	
	int w = ofGetWidth() - 2 * gap;		// Frame size
	int h = ofGetHeight() - 2 * gap;
 
	int hSpace = w / ( nPoints - 1 );	// Dist between lines / vertices
	int vSpace = h / ( nLines + 1 );
 
	for( int i = 0; i < nLines; i++ ){	// Calc vertical divisions
		vertGrid[i] = vSpace * i + gap + vSpace + ofRandom( -vSpace / noise, vSpace / noise );
	}
	for( int i = 0; i < nPoints; i++ ){	// Calc horizontal divisions
		horizGrid[i] = hSpace * i + gap + ofRandom( -hSpace / noise, hSpace / noise );
	}
	horizGrid[0] = gap;			// Move L/R vertices to edges
	horizGrid[nPoints - 1] = w + gap;
 
	for( int i = 0; i < nLines; i++ ){	// Create vertex array for drawing
		for( int j = 0; j < nPoints; j++ ){		
			lines[i][j].x = horizGrid[j];
			lines[i][j].y = vertGrid[i] + ofRandom( -vSpace / noise, vSpace / noise );
		}
	}
 
	for( int i = 0; i < nLines; i++ ){	// Draw lines
		ofBeginShape();
		for( int j = 0; j < nPoints; j++ ){
			ofVertex( lines[i][j].x, lines[i][j].y );
		}
		ofEndShape();
	}
 
	ofRect(gap, gap, ofGetWidth() - 2 * gap, ofGetHeight() - 2 * gap );	// Draw Frame
}
 
void testApp::drawStripes(){
	for( int i = 0; i < nLines; i++ ){
		for( int j = 0; j < nPoints - 1; j++ ){
			int type = ofRandom(0,2);		// Flip a coin
 
			if (type){				// Draw stripes if true
				int stripes = ofRandom(10,20);
				int crossed = ofRandom(0,2);	// Flip a coin straight/crossed
 
				ofVec2f leftUp = lines[i][j];	// Each block of stripes depends on 4 vertices
				ofVec2f rightUp = lines[i][j+1];
				ofVec2f leftDown = lines[i+1][j];
				ofVec2f rightDown = lines[i+1][j+1];
 
				for( int k = 0; k < stripes; k++ ){
					ofVec2f lineStart;	// Draw a block of stripes
					ofVec2f lineEnd;
 
					lineStart.x = ofRandom( leftUp.x, rightUp.x );						
					lineEnd.x = (crossed) ? ofRandom( leftUp.x, rightUp.x ) : lineStart.x;
 
					float slopeUp = (rightUp.y - leftUp.y) / (rightUp.x - leftUp.x);
					float slopeDown = (rightDown.y - leftDown.y) / (rightDown.x - leftDown.x);
 
					lineStart.y = leftUp.y + ( ( lineStart.x - leftUp.x ) * slopeUp );
					lineEnd.y = leftDown.y + ( ( lineEnd.x - leftUp.x ) * slopeDown );
 
					if (i == nLines - 1){	// Account for final line
						lineEnd.y = ofGetHeight() - gap;
					}
					ofLine(lineStart.x, lineStart.y, lineEnd.x, lineEnd.y);
				}
			}
		}
	}
}
 
void testApp::drawCircles(){
	for( int i = 0; i < nCircles; i++ ){	   	// Draw circles
		float r = ofRandom( 5, 50 );		// Randomize size
		ofCircle( ofRandom( gap + r, ofGetWidth() - gap - r ), ofRandom( gap + r, ofGetHeight() - gap - r), r);
	}
}

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2023 Interactive Art and Computational Design, Spring 2012 | powered by WordPress with Barecity