Commit c342d258 authored by Kevin Dang's avatar Kevin Dang

new file updates

parent 3b352aae
//
// 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 */
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