We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › OPENGL Attractor System.
Page Index Toggle Pages: 1
OPENGL Attractor System. (Read 751 times)
OPENGL Attractor System.
Jan 21st, 2009, 4:31pm
 
Hi,
   I am trying to model an attractor set(google:"strange attractor" or "clifford attractor") in processing.  I am relatively new to the environment but I've been programming for a while and am familiar with the syntax from Wiring/Arduino.  I have run into a stumbling block when I try and render my set in 3d.  Is there some prerequisite function I am missing?

Code:

import processing.opengl.*;


float ang;
int objNo = 1024;
float a = -1.4;
float b = 1.6;
float c = 1.0;
float d = 0.7;
float e = -1.3;
float f = 0.7;
int n;
float[]x = new float[objNo];
float[]y = new float[objNo];
float[]z = new float[objNo];
float[][]xyz = {x,y,z};
double bigX;
double bigY;
double bigZ;

void setup(){
size(300, 300,OPENGL);
xyz[0][0] = 0;
xyz[1][0] = 0;
xyz[2][0] = 0;
//populate arrray//
for (int i=0; i<xyz[0].length; i++){
n = (i+1)%objNo;


//xyz[0][n]//
bigX = (Math.sin(a*xyz[1][i]))+ (c*(Math.cos(a*xyz[0][i])));
//xyz[1][n]//
bigY = (Math.sin(b*xyz[0][i]))+ (d*(Math.cos(b*xyz[1][i])));
//xyz[2][n]//
bigZ = (Math.sin(e*xyz[1][i]))+ (f*(Math.cos(f*xyz[1][i])));//
xyz[0][n] = (float)bigX;
xyz[1][n] = (float)bigY;
xyz[2][n] = (float)bigZ;
}}


void draw(){
background(0);
stroke(255);
// pointLight(51, 102, 255, 65, 60, 100);
// pointLight(200, 40, 60, -65, -60, -150);
//ambientLight(70, 70, 10);
// translate(width/2, height/2, -200 + mouseX * 0.65);
// background(0);//
// rotateY(radians(ang));
// rotateX(radians(ang));

// ang++;


makePoints(xyz);}




void makePoints(float[][]pts){
float thisX;
float thisY;
float thisZ;
beginShape(POINTS);

for (int i = 0;i<pts[0].length; i++){
thisX=pts[0][i];
thisY=pts[1][i];
thisZ=pts[2][i];
strokeWeight(1);

vertex(thisX*100,thisY*100,thisZ*100-300);

}
}
Re: OPENGL Attractor System.
Reply #1 - Jan 21st, 2009, 6:38pm
 
Nevermind, Had to make (LINES) instead of (POINTS):
Cleaned up a bit, increase objNo for better topography:

Code:

import processing.opengl.*;


float ang;
int objNo = 1024;
float a = -1.4;
float b = 1.6;
float c = 1.0;
float d = 0.7;
float e = -1.3;
float f = 0.7;
int n;
float[]x = new float[objNo];
float[]y = new float[objNo];
float[]z = new float[objNo];
float[][]xyz = {x,y,z};
double bigX;
double bigY;
double bigZ;

void setup(){
size(500, 500,OPENGL);
xyz[0][0] = 0;
xyz[1][0] = 0;
xyz[2][0] = 0;
//populate arrray//
for (int i=0; i<xyz[0].length; i++){
n = (i+1)%objNo;


//xyz[0][n]//
bigX = (Math.sin(a*xyz[1][i]))+ (c*(Math.cos(a*xyz[0][i])));
//xyz[1][n]//
bigY = (Math.sin(b*xyz[0][i]))+ (d*(Math.cos(b*xyz[1][i])));
//xyz[2][n]//
bigZ = (Math.sin(e*xyz[1][i]))+ (f*(Math.cos(f*xyz[1][i])));//
xyz[0][n] = (float)bigX;
xyz[1][n] = (float)bigY;
xyz[2][n] = (float)bigZ;

}}


void draw(){


ambientLight(255,255,255,width/3,height/3,200);
translate(width/2, height/2);

rotateY(radians(ang));
rotateX(radians(ang/2));




makePoints();
ang++;}




void makePoints(){
int thisX;
int thisY;
int thisZ;
stroke(120,35,0);
background(0);
strokeWeight(5);

beginShape(LINES);

for (int i = 0;i<xyz[0].length; i++){
thisX=(int)(xyz[0][i]*(width/4));
thisY=(int)(xyz[1][i]*(width/4));
thisZ=(int)(xyz[2][i]*(width/4));


vertex(thisX,thisY,thisZ);
vertex(thisX+3,thisY,thisZ);


}
endShape();
}
Page Index Toggle Pages: 1