FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Information Visualization
(Moderators: forkinsocket, REAS)
   simple 2d mesh
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: simple 2d mesh  (Read 2248 times)
kantaria


simple 2d mesh
« on: Sep 13th, 2004, 8:49pm »

hi  
 
it is hard for me to imagine what TRIANGLE_STRIP
really does. does it connect the current point  
with the following two?  
 
i want to create a simple mesh which later on  
should be controllable to visualize a neuronal  
network. has anybody done that so far? i did not
find anything althought i saw already things like
meshes contolled by different frequencies.  
thanks a lot for help. . .
 
k
 
heres the code to show what im searching for:
 
 
int APPLET_WIDTH = 800;
int APPLET_HEIGHT = 600;
 
int beginWireX = 10;
int endWireX = APPLET_WIDTH-10;
int resWireX = 50;
 
int beginWireY = 10;
int endWireY = APPLET_HEIGHT-10;
int resWireY = 50;
 
int j=0;
int x = beginWireX;
int y = beginWireY;
 
float [][]pList;
 
void setup(){
  size(APPLET_WIDTH , APPLET_HEIGHT);
  background(55);
  stroke(255);
  pList = new float[5][5];
  noFill();
  //generating an 2dim array representing four rows each containing five numbers ;
  for(int i=1; i<=pList.length; i++){
    for(int j=1; j<=pList[0].length; j++){
 pList[i-1][j-1] = j;
 
    }
  }
  //print(pList[1][4]);
}
 
void loop(){
  //clear();
  translate(width/4, height/3,0);
  scale(.5);
  rotateX(1);
  beginShape(TRIANGLE_STRIP);
  for(int i = beginWireY; i<endWireY; i+=resWireY){
    for(int j = beginWireX; j<endWireX; j+=resWireX){
 vertex(j, i);
 vertex(j, i+resWireY);
    }
  }
  endShape();
   
}
 
 
_C


Re: simple 2d mesh
« Reply #1 on: Sep 16th, 2004, 2:22pm »

ok, now heres the code which does the job.
greets
_C
 
 
int APPLET_WIDTH = 800;
int APPLET_HEIGHT= 450;
color BG_COLOR;
 
Mesh m;
 
void setup(){
  BG_COLOR = color(99,98,97);
  size(APPLET_WIDTH, APPLET_HEIGHT);
  background(BG_COLOR);
  m=new Mesh();
}
 
void loop(){
  m.drawMesh();
}
 
class P3d{
  float x, y, z;
  P3d(float _x, float _y, float _z){
    x=_x; y=_y; z=_z;
  }
  P3d(P3d p){
    x=p.x; y=p.y; z=p.z;
  }
}
 
class PPoints{
  P3d [][]PPointPos;
  int PInitX, PInitY, PInitZ;
  int PWidth, PHeight;
  int PResX, PResY;
 
  PPoints(int _PInitX, int _PInitY, int _PWidth, int _PHeight, int _PResX, int _PResY){
    PInitX=_PInitX; PInitY=_PInitY; //PInitZ=_PInitZ;
    PWidth=_PWidth; PHeight=_PHeight;
    PResX=_PResX; PResY=_PResY;
 
    PPointPos=new P3d[PHeight/PResY][PWidth/PResX] ; //this is a matrix building lines and rows that will be filled with P3ds;
    update();
  }
 
  void update(){
    calcPositions();
  }
 
  void calcPositions(){
    for(int j=0; j<PHeight/PResY; j++){  //fill the array with "width/res points per row";
 for(int i=0; i<PWidth/PResX; i++){
   PPointPos[j][i]=new P3d(i*PResX+PInitX,j*PResY+PInitY,0);
 
 }
    }
  }
 
}
 
class Mesh{
  PPoints meshPoints;
 
  Mesh(){
    meshPoints = new PPoints(40, 40, 400, 400, 4, 4); //creating a mesh at 40,40/size of 400,400/cellsize of 40,40;
    //printMeshPoints();
  }
 
  void printMeshPoints(){
    for(int i=0; i<meshPoints.PPointPos.length; i++){
 for(int j=0; j<meshPoints.PPointPos[0].length; j++){
   println("row: "+i+" position: "+j+" x:"+meshPoints.PPointPos[i][j].x+" y:"+meshPoints.PPointPos[i][j].y);
 }
    }
  }
 
  void drawMesh(){
    noFill();
    stroke(255);
    for(int r=0; r<meshPoints.PPointPos.length-1; r++){ //from row zero upwars till the last line;
 beginShape(TRIANGLE_STRIP); //AH - just write this after calling the jump-to-next-line-command, so it will start a new strip-line without connecting it with the last line.  
 for(int j=0; j<meshPoints.PPointPos[r].length; j++){
   vertex(meshPoints.PPointPos[r][j].x, meshPoints.PPointPos[r][j].y, meshPoints.PPointPos[r][j].z);
   vertex(meshPoints.PPointPos[r+1][j].x, meshPoints.PPointPos[r+1][j].y, meshPoints.PPointPos[r+1][j].z);
   endShape();
 }
    }
  }
   
}
 
 
Markavian

Markavian+iTX WWW
Re: simple 2d mesh
« Reply #2 on: Sep 28th, 2004, 12:13am »

Ok, so you made the mesh.. tested it seems ok.. what were ya gonna do with it?
 
Pages: 1 

« Previous topic | Next topic »