Commit da1e5695 authored by Kevin Dang's avatar Kevin Dang

updated files - final version of tree

parent c342d258
......@@ -7,7 +7,6 @@
objects = {
/* Begin PBXBuildFile section */
0A521A451C675A9F004DC3ED /* Tree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0A521A441C675A9F004DC3ED /* Tree.cpp */; };
0A705FA21C558A1000F81E1B /* branch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0A705FA11C558A1000F81E1B /* branch.cpp */; };
E4328149138ABC9F0047C5CB /* openFrameworksDebug.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E4328148138ABC890047C5CB /* openFrameworksDebug.a */; };
E4B69E200A3A1BDC003C02F2 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B69E1D0A3A1BDC003C02F2 /* main.cpp */; };
......@@ -44,8 +43,6 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
0A521A431C675A97004DC3ED /* Tree.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Tree.h; sourceTree = "<group>"; };
0A521A441C675A9F004DC3ED /* Tree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Tree.cpp; sourceTree = "<group>"; };
0A705FA01C558A0500F81E1B /* branch.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = branch.h; sourceTree = "<group>"; };
0A705FA11C558A1000F81E1B /* branch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = branch.cpp; sourceTree = "<group>"; };
E4328143138ABC890047C5CB /* openFrameworksLib.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = openFrameworksLib.xcodeproj; path = ../../../libs/openFrameworksCompiled/project/osx/openFrameworksLib.xcodeproj; sourceTree = SOURCE_ROOT; };
......@@ -113,8 +110,6 @@
E4B69E1E0A3A1BDC003C02F2 /* ofApp.cpp */,
0A705FA01C558A0500F81E1B /* branch.h */,
0A705FA11C558A1000F81E1B /* branch.cpp */,
0A521A431C675A97004DC3ED /* Tree.h */,
0A521A441C675A9F004DC3ED /* Tree.cpp */,
);
path = src;
sourceTree = SOURCE_ROOT;
......@@ -216,7 +211,6 @@
buildActionMask = 2147483647;
files = (
0A705FA21C558A1000F81E1B /* branch.cpp in Sources */,
0A521A451C675A9F004DC3ED /* Tree.cpp in Sources */,
E4B69E200A3A1BDC003C02F2 /* main.cpp in Sources */,
E4B69E210A3A1BDC003C02F2 /* ofApp.cpp in Sources */,
);
......
//
// Tree.cpp
// Fractals
//
// Created by Kevin Dang on 07/02/2016.
//
//
#include <stdio.h>
#include "Tree.h"
Tree::Tree(int x_, int y_, int l_, int s_) {
x = x_;
y = y_;
len = ofMap(l_, 4, 120, 0.5, 40);
steps = s_;
}
void Tree::render() {
ofSetColor(255);
ofFill();
branch(x, y, -HALF_PI, len);
}
void Tree::branch(float x_, float y_, float a_, float s_) {
ofSetLineWidth(10);
float a = ofRandom(-PI/16, PI/16)+a_;
float nx = cos(a)*s_+x_;
float ny = sin(a)*s_+y_;
ofSetColor(255);
ofFill();
ofLine(x_, y_, nx, ny);
if (s_>16) {
branch(nx, ny, a_-PI/4, s_*ofRandom(0.6, 0.8));
branch(nx, ny, a_, s_*ofRandom(0.6, 0.8));
branch(nx, ny, a_+ofRandom(PI/4), s_*ofRandom(0.6, 0.8));
} else {
ofSetColor(0,20,0);
ofFill();
ofCircle(x_, y_, 20);
}
}
//
// Tree.h
// Fractals
//
// Created by Kevin Dang on 07/02/2016.
//
//
#ifndef Tree_h
#define Tree_h
#include "ofMain.h"
class Tree {
public:
float x, y;
float len;
float steps;
Tree(int x_, int y_, int l_, int s_);
void setup();
void render();
void branch(float, float, float, float);
};
#endif /* Tree_h */
......@@ -16,8 +16,6 @@ void Branch::setup() {
theta = 30.0;
rotate = 36.00;
branchValue = 180;
testX = 0;
testY = 0;
}
......@@ -43,7 +41,7 @@ float Branch::branch(float len) {
float strokeWeight = ofMap(len, 4, 120, 0.5, 40);
ofSetLineWidth((strokeWeight*.5));
ofLine(testX,testY,0,-len);
ofLine(0,0,0,-len);
ofTranslate(0, -len);
// shrink the length of each branch when it grows
......@@ -57,14 +55,15 @@ float Branch::branch(float len) {
ofRotate(theta+10);
branch(len);
ofPopMatrix();
ofSetColor(60);
ofPushMatrix();
ofRotate(-theta);
branch(len);
ofPopMatrix();
} else {
ofSetColor(0,100,0);
ofSetColor(160,0,0);
ofFill();
ofCircle(testX, testY, 2);
ofCircle(0, 0, ofRandom(2,5));
}
ofPopMatrix();
......
......@@ -19,8 +19,6 @@ public:
float theta, rotate;
bool mousePressed;
float branchValue;
float testX, testY;
};
......
......@@ -2,10 +2,8 @@
//--------------------------------------------------------------
void ofApp::setup(){
// branches.setup();
// testing = 0;
tree = new Tree(0, 0, 0, 0);
branches.setup();
wholeRotate = 0;
}
......@@ -17,20 +15,15 @@ void ofApp::update(){
//--------------------------------------------------------------
void ofApp::draw(){
// ofPushMatrix();
// ofTranslate(ofGetWindowWidth()/2, ofGetWindowHeight()-800);
// ofRotateY(testing);
ofPushMatrix();
ofTranslate(ofGetWindowWidth()/2, ofGetWindowHeight()-800);
ofRotateY(wholeRotate);
// branches.draw();
branches.draw();
// testing+=0.5;
// ofPopMatrix();
wholeRotate+=0.5;
ofPopMatrix();
// tree->render();
tree = new Tree(ofGetWidth()/2, ofGetHeight(), 480, 10);
tree->render();
}
......@@ -58,15 +51,12 @@ void ofApp::mouseDragged(int x, int y, int button){
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
// branches.mousePressed = true;
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
// branches.mousePressed = false;
// tree = new Tree(ofGetWidth()/2, ofGetHeight(), 480, 10);
// tree->render();
}
//--------------------------------------------------------------
......
......@@ -2,7 +2,6 @@
#include "ofMain.h"
#include "branch.h"
#include "Tree.h"
class ofApp : public ofBaseApp{
......@@ -26,9 +25,8 @@ class ofApp : public ofBaseApp{
void gotMessage(ofMessage msg);
Branch branches;
Tree* tree;
// float testing;
float wholeRotate;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment