initial: set up the environment, added some bootstrapping code, mostly sketched

This commit is contained in:
2017-11-27 12:37:41 +01:00
commit e85e453f2f
2 changed files with 89 additions and 0 deletions

3
README.md Normal file
View File

@@ -0,0 +1,3 @@
# ring
A generatively designed ring for the woman I love. For a momentous occasion.

86
ring/ring.pde Normal file
View File

@@ -0,0 +1,86 @@
class Leaf {
PVector pos;
Leaf() {
pos = PVector.random2D();
}
}
class Branch {
PVector pos;
Branch(PVector pos) {
this.pos = pos;
}
Branch(Branch b) {
this.pos = b.pos;
}
}
class Tree {
ArrayList<Branch> branches = new ArrayList<>();
ArrayList<Leaf> leaves = new ArrayList<>();
Tree() {
for (int i = 0; i < 2000; i++) leaves.add(new Leaf());
Branch root = new Branch(new PVector(width/2, height/2));
branches.add(root);
Branch current = new Branch(root);
while(!closeEnough(current)) {
Branch trunk = new Branch(current);
branches.add(trunk);
current = trunk;
}
}
boolean closeEnough(Branch b) {
for (Leaf l : leaves) {
float d = PVector.dist(b.pos, l.pos);
if (d < max_dist) return true;
}
return false;
}
void show() {
}
void grow() {
Branch closest = null;
PVector closestDir = null;
float record = -1;
for (Branch b : branches) {
PVector dir = PVector.sub(l.pos, b.pos);
float d = dir.mag();
if (d < min_dist) {
l.reached();
closest = null;
break;
} else if (closest == null && d <= max_dist) {
closest = b;
closestDir = dir;
record = d;
}
}
}
}
Tree tree;
float min_dist = 5;
float max_dist = 50;
void setup() {
size(600, 600);
frameRate(5);
tree = new Tree();
}
void draw() {
background(40);
tree.show();
tree.grow();
}