Skip to content

Commit

Permalink
from charlies algo2013
Browse files Browse the repository at this point in the history
  • Loading branch information
firmread committed Nov 23, 2015
1 parent 90baaf1 commit dc055ab
Show file tree
Hide file tree
Showing 29 changed files with 761 additions and 1 deletion.
Empty file.
2 changes: 2 additions & 0 deletions chp08-fractals-01_Recursion/icon.rc
@@ -0,0 +1,2 @@
//TODO: figure out how to do debug and release icons
MAINICON ICON "../../../libs/openFrameworksCompiled/project/win_cb/icon.ico"
13 changes: 13 additions & 0 deletions chp08-fractals-01_Recursion/src/main.cpp
@@ -0,0 +1,13 @@
#include "ofMain.h"
#include "testApp.h"

//========================================================================
int main( ){
ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context

// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp(new testApp());

}
84 changes: 84 additions & 0 deletions chp08-fractals-01_Recursion/src/testApp.cpp
@@ -0,0 +1,84 @@
#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup(){
ofBackground( 0 );
ofSetColor( 255 );


}

void testApp::drawDiamond(float x, float y, float size ){
ofSetRectMode( OF_RECTMODE_CENTER );

if( size > 16 ){
drawDiamond( x + size/2, y, size/2 );
drawDiamond( x - size/2, y, size/2 );

drawDiamond( x, y + size/2, size/2 );
drawDiamond( x, y - size/2, size/2 );
}

ofPushMatrix();{
ofTranslate( x, y);
ofRotate( 45 );
ofRect( 0, 0, size, size );
}ofPopMatrix();

}

//--------------------------------------------------------------
void testApp::update(){

}

//--------------------------------------------------------------
void testApp::draw(){
ofNoFill();
drawDiamond( ofGetWindowWidth()/2, ofGetWindowHeight()/2, ofGetWindowWidth()/2 );
}

//--------------------------------------------------------------
void testApp::keyPressed(int key){

}

//--------------------------------------------------------------
void testApp::keyReleased(int key){

}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){

}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){

}
23 changes: 23 additions & 0 deletions chp08-fractals-01_Recursion/src/testApp.h
@@ -0,0 +1,23 @@
#pragma once

#include "ofMain.h"

class testApp : public ofBaseApp{

public:
void setup();
void update();
void draw();

void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);

void drawDiamond( float x, float y, float size );
};
Empty file.
2 changes: 2 additions & 0 deletions chp08-fractals-02_Koch/icon.rc
@@ -0,0 +1,2 @@
//TODO: figure out how to do debug and release icons
MAINICON ICON "../../../libs/openFrameworksCompiled/project/win_cb/icon.ico"
47 changes: 47 additions & 0 deletions chp08-fractals-02_Koch/src/KochLine.cpp
@@ -0,0 +1,47 @@
//
// KochLine.cpp
// Koch
//
// Created by Charlie Whitney on 11/18/13.
//
//

#include "KochLine.h"

KochLine::KochLine( ofVec2f _start, ofVec2f _end ){
start = _start;
end = _end;
}

void KochLine::draw() {
ofLine( start, end );
}

float KochLine::getLength() {
return start.distance( end );
}

ofVec2f KochLine::a(){
return start;
}

ofVec2f KochLine::b(){
ofVec2f dir = (end - start) * 0.333333333;
return (start + dir);
}

ofVec2f KochLine::c(){
ofVec2f dir = (end - start) * 0.333333333;
dir.rotate( -60 );

return b() + dir;
}

ofVec2f KochLine::d(){
ofVec2f dir = (end - start) * 0.666666667;
return (start + dir);
}

ofVec2f KochLine::e(){
return end;
}
27 changes: 27 additions & 0 deletions chp08-fractals-02_Koch/src/KochLine.h
@@ -0,0 +1,27 @@
//
// KochLine.h
// Koch
//
// Created by Charlie Whitney on 11/18/13.
//
//

#pragma once

#include "ofMain.h"

class KochLine {
public:
KochLine( ofVec2f _start, ofVec2f _end );
void draw();

float getLength();

ofVec2f a();
ofVec2f b();
ofVec2f c();
ofVec2f d();
ofVec2f e();

ofVec2f start, end;
};
13 changes: 13 additions & 0 deletions chp08-fractals-02_Koch/src/main.cpp
@@ -0,0 +1,13 @@
#include "ofMain.h"
#include "testApp.h"

//========================================================================
int main( ){
ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context

// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp(new testApp());

}
95 changes: 95 additions & 0 deletions chp08-fractals-02_Koch/src/testApp.cpp
@@ -0,0 +1,95 @@
#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup(){
KochLine line( ofVec2f(0, 500), ofVec2f( ofGetWindowWidth(), 500) );

lineList.push_back( line );

ofBackground(0);
pct = 1.0;
}

//--------------------------------------------------------------
void testApp::update(){

}

void testApp::addGeneration() {
vector<KochLine> newLines;

for( int i=0; i<lineList.size(); i++ ){
ofVec2f a = lineList[i].a();
ofVec2f b = lineList[i].b();
ofVec2f c = lineList[i].c();
ofVec2f d = lineList[i].d();
ofVec2f e = lineList[i].e();

newLines.push_back( KochLine(a, b) );
newLines.push_back( KochLine(b, c) );
newLines.push_back( KochLine(c, d) );
newLines.push_back( KochLine(d, e) );
}

lineList = newLines;
}

//--------------------------------------------------------------
void testApp::draw(){
float coastLine = 0;

int pos = ceil( lineList.size() * pct );

for( int i=0; i<pos; i++ ){
lineList[i].draw();
coastLine += lineList[i].getLength();
}

ofDrawBitmapString("Dist: " + ofToString(coastLine), ofVec2f(10,10) );
}

//--------------------------------------------------------------
void testApp::keyPressed(int key){

}

//--------------------------------------------------------------
void testApp::keyReleased(int key){

}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
pct = (float)x / ofGetWindowWidth();
pct = ofClamp(pct, 0.0, 1.0);
}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
addGeneration();
}

//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){

}
27 changes: 27 additions & 0 deletions chp08-fractals-02_Koch/src/testApp.h
@@ -0,0 +1,27 @@
#pragma once

#include "ofMain.h"
#include "KochLine.h"

class testApp : public ofBaseApp{

public:
void setup();
void update();
void draw();

void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);

void addGeneration();

vector<KochLine> lineList;
float pct;
};
Empty file.
2 changes: 2 additions & 0 deletions chp08-fractals-03_Branching/icon.rc
@@ -0,0 +1,2 @@
//TODO: figure out how to do debug and release icons
MAINICON ICON "../../../libs/openFrameworksCompiled/project/win_cb/icon.ico"
13 changes: 13 additions & 0 deletions chp08-fractals-03_Branching/src/main.cpp
@@ -0,0 +1,13 @@
#include "ofMain.h"
#include "testApp.h"

//========================================================================
int main( ){
ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context

// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp(new testApp());

}

0 comments on commit dc055ab

Please sign in to comment.