void init_circles() {
for (int i=0; i<numcircles; i++) {
circles[i] = new Circle(20, (i+1)*0.8, (i+1)*20);
}
}
void complete_graph_between_circles() {
Circle c1=circles[0], c2;
PVector p1, p2;
for (int c=1; c<numcircles; c++) { // per tutti i cerchi prendine due
c1 = circles[c-1];
c2 = circles[c];
for (int i=0; i<c1.numpoints; i++) {
for (int j=0; j<c2.numpoints; j++) { // per tutti i punti di questi confronta quelli del primo con quelli del secondo
p1 = c1.points[i];
p2 = c2.points[j];
//p2 = c2.points[i];
float distance = PVector.dist(p1, p2);
stroke(0, 0, 0, map(distance, 0, height, 50, 0));
line(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z);
} // j
} // i
} // c
}
class Circle {
float radius = 0;
int numpoints = 20;
float height = 50;
float velocity = 2;
PVector center = new PVector();
PVector points[] = new PVector[numpoints];
Circle(int numpoints, float velocity, float radius) {
this.velocity = velocity;
this.radius = radius;
this.numpoints = numpoints;
points = new PVector[this.numpoints];
for (int i=0; i<this.numpoints; i++) {
points[i] = new PVector();
}
}
void update() {
center.y = sin(theta+velocity) * this.height;
}
void draw() {
float a = 0;
float delta = TWO_PI/(numpoints-1);
float x, y, z;
beginShape();
for (int i=0; i<numpoints; i++) {
x = cos(a)*radius + center.x;
y = center.y;
z = sin(a)*radius + center.z;
points[i].x = x;
points[i].y = y;
points[i].z = z;
vertex( x, y, z );
a += delta;
}
endShape();
}
}
import processing.opengl.*;
import javax.media.opengl.GL;
import peasy.*;
import controlP5.*;
ControlP5 controlP5;
PMatrix3D currCameraMatrix;
PGraphics3D g3;
PeasyCam cam;
GL gl;
int numcircles = 25;
Circle[] circles = new Circle[numcircles];
float theta = 0, dt = 0.1;
float ripples = 0.2, height_ripples = 2;
void setup() {
size(800, 600, OPENGL);
init_circles();
init_gl();
g3 = (PGraphics3D)g;
cam = new PeasyCam(this, 1200);
controlP5 = new ControlP5(this);
controlP5.setAutoDraw(false);
controlP5.addSlider("dt", 0, 0.6,0.1, 10,10, 100,30);
controlP5.addSlider("ripples", 0, 1, 0.1, 10,40, 100,30);
controlP5.addSlider("height_ripples",0, 20, 2, 10,70, 100,30);
}
void init_gl() {
// init gl for alpha lines rendering
// see http://www.opengl.org/resources/code/samples/sig99/advanced99/notes/node120.html
gl=((PGraphicsOpenGL)g).gl;
hint(DISABLE_DEPTH_TEST);
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
gl.glEnable(GL.GL_LINE_SMOOTH);
gl.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
//gl.glDepthMask(false);
}
void keyPressed() {
//saveFrame(frameCount+".png");
}
void draw() {
// don't use peasycam when moving controlP5 slider
if (controlP5.window(this).isMouseOver()) {
cam.setActive(false);
} else {
cam.setActive(true);
}
background(255);
translate(0,-circles[numcircles-1].center.y, 0);
noFill();
stroke(0, 100);
for (int i=0; i<numcircles; i++) {
circles[i].velocity = (i+1)*ripples;
circles[i].height = (numcircles-i)*height_ripples;
if (!keyPressed) circles[i].update();
circles[i].draw();
}
complete_graph_between_circles();
gui();
theta += dt; //map(mouseY, 0, height, 0, 0.4);
}
void gui() {
currCameraMatrix = new PMatrix3D(g3.camera);
camera();
controlP5.draw();
g3.camera = currCameraMatrix;
}
Just another simple wave simulator.
Render is some cool and weird net between circles inspired http://vimeo.com/24133373
sorry, it is in opengl