Back to photostream

1466980990465

// testing how does code look like

// in flickr

import peasy.*;

 

PeasyCam cam;

 

ArrayList a = new ArrayList();

ArrayList b = new ArrayList();

 

PShape shp;

 

void setup() {

fullScreen(P3D);

cam = new PeasyCam(this, 100);

cam.setMinimumDistance(50);

cam.setMaximumDistance(500);

 

for (int i=0; i<15; i++) {

PVector v = PVector.fromAngle(TAU * i/15.0);

v.mult(random(100, 150));

v.z = 100;

a.add(v);

}

 

for (int j=0; j<30; j++) {

PVector v = PVector.fromAngle(TAU * j/30.0);

v.mult(random(100, 150));

v.z = 200;

b.add(v);

}

 

shp = createShape();

shp.beginShape(TRIANGLES);

shp.fill(#FF0000);

for (int j=0; j<b.size(); j++) {

PVector va = getCloserV(a, b, j, j+1);

PVector vb = getV(b, j);

PVector vc = getV(b, j+1);

addTriangle(shp, va, vb, vc);

}

shp.fill(#00FF00);

for (int j=0; j<a.size(); j++) {

PVector va = getCloserV(b, a, j, j+1);

PVector vb = getV(a, j);

PVector vc = getV(a, j+1);

addTriangle(shp, va, vb, vc);

}

shp.endShape();

}

void addTriangle(PShape s, PVector va, PVector vb, PVector vc) {

s.vertex(va.x, va.y, va.z);

s.vertex(vb.x, vb.y, vb.z);

s.vertex(vc.x, vc.y, vc.z);

}

PVector getV(ArrayList points, int id) {

return points.get(id % points.size());

}

PVector getCloserV(ArrayList points, ArrayList samplePoints, int idA, int idB) {

PVector vA = getV(samplePoints, idA);

PVector vB = getV(samplePoints, idB);

PVector mid = PVector.lerp(vA, vB, 0.5);

float minDist = Float.MAX_VALUE;

PVector result = null;

for(PVector p : points) {

float d = mid.dist(p);

if(d < minDist) {

minDist = d;

result = p;

}

}

return result;

}

 

void draw() {

background(0);

//translate(width/2, height/2);

lights();

shape(shp);

}

109 views
0 faves
0 comments
Uploaded on August 25, 2016
Taken on August 25, 2016