Curves

anar.ch_img_studio.02_00013.jpg

Modules

A basic module, based on some external Prameters.

Obj createModule(Param x, Param y,Param h,float lengthA, Param lenghtB, int numOfSides, Param rotation){
  Obj myModule = new Obj();    
  
  Face star = new Star(new Param(lengthA),lenghtB,new Param(numOfSides));
  star.translate(x,y);
 
  Obj pyr = new Pyramid(star,h);
  myModule.add(pyr);
 
  Transform allign = new Transform(star.pt((int)random(star.numOfPts())),star.pt((int)random(star.numOfPts())));
  allign.rotateZ(rotation);
  
  Face starRefelx = new Face(star,allign);
  
  myModule.add(starRefelx);
    
  return myModule;
}
 

Create a grid with different modules

void initForm(){
  
  myObj = new Obj();
  
  int nGridX = 6;
  int nGridY = 6;
  
  Param h = new Param(30,0,300);
  Param r = new Param(1,-PI*4,PI*4);
  Param L = new Param(50,0,100);
  Param s = new Param(20,0,100);
  
  myScene.slidersReset();
  myScene.slidersAdd(h);
  myScene.slidersAdd(r);
  myScene.slidersAdd(L);
  myScene.slidersAdd(s);
  
  for(int i=0; i<nGridX; i++)
    for(int j=0; j<nGridY; j++){       
      Param x = s.multiply(nGridX*(i-nGridX/2f));
      Param y = s.multiply(nGridY*(j-nGridY/2f));
      
      Obj tmpModule = createModule(x,y,h,random(90)+10,L,(int)random(10)+3,r);
      
      myObj.add(tmpModule);
    }
      
  myObj.fill(255,100);
}
 

anar.ch_img_studio.02_00009.jpg

Curves Construction

import processing.opengl.*;
import oog.*;
 
 
 
 
Oog myScene;
Obj myObj = new Obj();
 
 
void setup(){
    size(800,400,OPENGL);
  myScene = new Oog(this);
  myScene.drawAxis();
  initForm();
}
 
void initForm(){
  myObj = createModule();
}
 
Obj createModule(){
  //Initialize a local object
  Obj module = new Obj();
  
  //First construction: a basic line
  Pts construction = new Pts();
  
  construction.add(0,0,0);
  construction.add(30,20,0);
  construction.add(60,-20,0);
  construction.add(90,0,0);
  construction.add(120,0,40);
  construction.add(150,0,0);
  construction.add(180,0,0);
  construction.stroke(155,0,0);
  
  //From this first set of points, create a curve of degree 4
  CSpline curve = new CSpline(construction,4);
  curve.stroke(255,155,155);
  
  //Constrain a point on this curve for t=0.1
  Pt c = new PtCurve(curve,0.1f);
  //Track parameters of point C
  Sliders cOnCurve = new Sliders(c);    
  myScene.slidersAdd(cOnCurve.get(cOnCurve.size()-1));    
  
  //Create a new line with non uniform distribution of points
  Pts curveWithPoints = new Pts();
  float i = 0;
  
  while(i<1)
  {
    curveWithPoints.add(new PtCurve(curve,i));
    i += random(0.1f);
  }
  
  curveWithPoints.translate(0,10,0);
  curveWithPoints.drawPoints();    
 
  //Create set of Points from an uniform distribution of points
  Pts curveWithPointsUniform = curve.getPts(30);
  curveWithPointsUniform.translate(0,30,0);
  curveWithPointsUniform.drawPoints();
  
  //Add Everything to our object
  module.add(curve);
  module.add(construction);
  module.add(curveWithPoints);
  module.add(curveWithPointsUniform);
  module.add(c);
  
  myScene.setCenter(construction);
  
  return module;
}
 
 
void draw(){
  background(155);
  myObj.draw();
}
 

anar.ch_img_studio.02_00010.jpg

Curve: Linking Points

import processing.opengl.*;
import oog.*;
 
 
 
 
Oog myScene;
Obj myObj = new Obj();
 
 
void setup(){
  size(800,400,OPENGL);
  myScene = new Oog(this);
  myScene.drawAxis();
  initForm();
}
 
void initForm(){
 
  //First construction: a basic line
  Pts ctrlPts = new Pts();
 
  ctrlPts.add(0,0,0);
  ctrlPts.add(30,20,0);
  ctrlPts.add(60,-20,0);
  ctrlPts.add(90,0,0);
  ctrlPts.add(120,0,40);
  ctrlPts.add(150,0,0);
  ctrlPts.add(180,0,0);
  ctrlPts.stroke(155,0,0);   
 
  ctrlPts.translate(0,30,0);
 
  //To track the position of the point on the curve
  Param t = new Param(0.1,0,1);
 
  //Add this first module
  Obj moduleA = createModule(ctrlPts,t);
  myObj.add(moduleA);
 
  //Create new controlPoints one from a symmetry
  Pts ctrlPtsSym = new Pts(ctrlPts, new MirrorY());
 
  //Create a new curve based on the new controlPoints
  Obj moduleB = createModule(ctrlPtsSym,t);
  myObj.add(moduleB);
 
  //Link the two moving points together
  Pts betweenCurves = new Pts();
  betweenCurves.add(moduleA.pt(0));
  betweenCurves.add(moduleB.pt(0));
  myObj.add(betweenCurves);
 
  myScene.sliders(moduleA);
  myScene.setCenter(ctrlPts);
}
 
Obj createModule(Pts construction, Param t){
  //Initialize a local object
  Obj module = new Obj();
 
  //From this first set of points, create a curve of degree 4
  CSpline curve = new CSpline(construction,4);
  curve.stroke(255,155,155);
 
  //Constrain a point on this curve for t=0.1
  Pt c = new PtCurve(curve,t);
  //Track parameters of point C
  Sliders cOnCurve = new Sliders(c);    
  //myScene.slidersAdd(cOnCurve.get(cOnCurve.size()-1));        
 
  //Add Everything to our local object
  module.add(construction);
  module.add(curve);
  module.add(c);
 
  myScene.setCenter(construction);
 
  return module;
}
 
 
void draw(){
  background(155);
  myObj.draw();
}

anar.ch_img_studio.02_00011.jpg

Curve: CreateFaces

import processing.opengl.*;
import oog.*;
 
 
 
 
Oog myScene;
Obj myObj = new Obj();
 
 
void setup(){
    size(800,400,OPENGL);
  myScene = new Oog(this);
  myScene.drawAxis();
  initForm();
}
 
void initForm(){
  
  //First construction: a basic line
  Pts ctrlPts = new Pts();
  
  ctrlPts.add(0,0,0);
  ctrlPts.add(30,20,0);
  ctrlPts.add(60,-20,0);
  ctrlPts.add(90,0,0);
  ctrlPts.add(120,0,40);
  ctrlPts.add(150,0,0);
  ctrlPts.add(180,0,0);
  ctrlPts.stroke(155,0,0);   
  
  ctrlPts.translate(0,60,0);
  
  //Add this first module
  Pts moduleA = createModule(ctrlPts);
  myObj.add(moduleA);
  
  //Create new controlPoints one from a symmetry
  Pts ctrlPtsSym = new Pts(ctrlPts, new MirrorY());
  
  //Create a new curve based on the new controlPoints
  Pts moduleB = createModule(ctrlPtsSym);
  myObj.add(moduleB);
  
  //Create Faces
  for(int i=1; i<moduleA.numOfPts(); i++)
  {
    Face f = new Face();
    
    f.add(moduleA.pt(i-1));
    f.add(moduleB.pt(i-1));
    f.add(moduleB.pt(i));
    f.add(moduleA.pt(i));
    
    myObj.add(f);
  }
 
  myScene.sliders(ctrlPts);
  myScene.setCenter(myObj);
}
 
Pts createModule(Pts construction){
 
  //From this first set of points, create a curve of degree 4
  CSpline curve = new CSpline(construction,4);
  
  //Extract a serie of points from the curve
  Pts curveWithPointsUniform = curve.getPts(30);    
  
  return curveWithPointsUniform;
}
 
 
void draw(){
  background(155);
  myObj.draw();
}

anar.ch_img_studio.02_00012.jpg

Basic Grid of Lines

Obj createGrid(int n, int m){
  Obj output = new Obj();
 
  for (int i = 0; i<n; i++)
    for (int j = 0; j<m; j++){
      // Create a list of point
      // This is our Vertical lines
      Pts vertical = new Pts();
 
      // Create a first point on the floor
      Pt ori = Pt.create(i*30,j*60);
      vertical.add(ori);
 
      // Derive a second point from the previous position
      TranslateZ tz = new TranslateZ(random(50)+30);
      if( (i*n+j)%12==0)
        myScene.slidersAdd(tz);
 
      Pt up = Pt.create(ori,tz);
      vertical.add(up);
 
      // Store the lines in our output
      output.add(vertical);
    }
 
  return output;
}
 

anar.ch_img_studio.02_00008.jpg

Lines in X from a grid

Obj createCtrlInX(int n, int m, Obj grid){
  // Link the upper points together
  Obj allCtrlLineX = new Obj();
 
  for (int i = 0; i<n; i++){
    Pts ctrlLineX = new Pts();
    for (int j = 0; j<m; j++)
      ctrlLineX.add(grid.line(i+ (j*n)).pt(1));
 
    ctrlLineX.stroke(155,0,0);
    allCtrlLineX.add(ctrlLineX);
  }
 
  return allCtrlLineX;
}
 

anar.ch_img_studio.02_00007.jpg

Convert a set of lines into curves

Obj ptsSetToCurves(Obj ctrlX, int nPts){
  // Link the upper points together
  Obj curves = new Obj();
 
  for (int i = 0; i<ctrlX.numOfLines(); i++)
    curves.add(createCurve(ctrlX.line(i),nPts));
 
  return curves;
}
 
 
 
Pts createCurve(Pts construction, int nPts){
 
  // From this first set of points, create a curve of degree 4
  CSpline curve = new CSpline(construction,4);
 
  // Extract a serie of points from the curve
  Pts curveWithPointsUniform = curve.getPts(nPts);
  curveWithPointsUniform.stroke(155,155,255);
 
  return curveWithPointsUniform;
}
 

anar.ch_img_studio.02_00006.jpg

Extract points in Y

Obj createCtrlInY(Obj grid, int nPts){
  // Link the upper points together
  Obj allCtrlLineY = new Obj();
 
  for (int i = 0; i<grid.line(0).numOfPts(); i++){
    Pts ctrlLineY = new Pts();
    for (int j = 0; j<grid.numOfLines(); j++)
      ctrlLineY.add(grid.line(j).pt(i));
 
    ctrlLineY.stroke(200,0,0);
    allCtrlLineY.add(ctrlLineY);
  }
 
  return allCtrlLineY;
}

anar.ch_img_studio.02_00003.jpg

Create curves in Y

Reusing the same function

Obj ptsSetToCurves(Obj ctrlX, int nPts){
  // Link the upper points together
  Obj curves = new Obj();
 
  for (int i = 0; i<ctrlX.numOfLines(); i++)
    curves.add(createCurve(ctrlX.line(i),nPts));
 
  return curves;
}
 

anar.ch_img_studio.02_00004.jpg

Create the Faces

Obj createFacesFromAGrid(Obj grid){
  Obj output = new Obj();
  
  for (int i = 1; i<grid.numOfLines(); i++)
    for (int j = 1; j<grid.line(i).numOfPts(); j++)
    {
      Face f = new Face();
      
      f.add(grid.line(i-1).pt(j-1));
      f.add(grid.line(i-1).pt(j));
      f.add(grid.line(i).pt(j));
      f.add(grid.line(i).pt(j-1));
      
      output.add(f);
    }
 
  
  return output;
}
 

anar.ch_img_studio.02_00002.jpg

anar.ch_img_studio.02_00001.jpg

anar.ch_img_studio.02_00000.jpg

Complete Code

import processing.opengl.*;
import oog.*;
 
Oog myScene;
Obj myObj = new Obj();
 
void setup(){
    size(800,400,OPENGL);
  myScene = new Oog(this);
  myScene.drawAxis();
  initForm();
}
 
void initForm(){
 
  int n = 6; // number of elements in X
  int m = 6; // number of elements in Y
 
  Param axonometric = new Param(0,0,50);
  TranslateZ tz = new TranslateZ(axonometric);
 
  Obj grid = createGrid(n,m);
  myObj.add(grid);
 
  Obj ctrlX = createCtrlInX(n,m,grid);
  ctrlX.apply(tz);
  myObj.add(ctrlX);
 
  Obj curvesX = ptsSetToCurves(ctrlX,50);
  curvesX.apply(tz);
  curvesX.apply(tz);
  myObj.add(curvesX);
 
  Obj ctrlY = createCtrlInY(curvesX,50);
  ctrlY.apply(tz);
  ctrlY.apply(tz);
  ctrlY.apply(tz);
  myObj.add(ctrlY);
 
  Obj curvesY = ptsSetToCurves(ctrlY,50);
  curvesY.apply(tz);
  curvesY.apply(tz);
  curvesY.apply(tz);
  curvesY.apply(tz);
  myObj.add(curvesY);
  
  
  Obj faces = createFacesFromAGrid(curvesY);
  faces.apply(tz);
  faces.apply(tz);
  faces.apply(tz);
  faces.apply(tz);  
  faces.apply(tz); 
  myObj.add(faces);
 
  // myScene.sliders(myObj)
  myScene.slidersAdd(tz);
  myScene.setCenter(myObj);
}
 
 
 
Obj createGrid(int n, int m){
  Obj output = new Obj();
 
  for (int i = 0; i<n; i++)
    for (int j = 0; j<m; j++){
      // Create a list of point
      // This is our Vertical lines
      Pts vertical = new Pts();
 
      // Create a first point on the floor
      Pt ori = Pt.create(i*30,j*60);
      vertical.add(ori);
 
      // Derive a second point from the previous position
      TranslateZ tz = new TranslateZ(random(50)+30);
      if( (i*n+j)%12==0)
        myScene.slidersAdd(tz);
 
      Pt up = Pt.create(ori,tz);
      vertical.add(up);
 
      // Store the lines in our output
      output.add(vertical);
    }
 
  return output;
}
 
 
Obj createCtrlInX(int n, int m, Obj grid){
  // Link the upper points together
  Obj allCtrlLineX = new Obj();
 
  for (int i = 0; i<n; i++){
    Pts ctrlLineX = new Pts();
    for (int j = 0; j<m; j++)
      ctrlLineX.add(grid.line(i+ (j*n)).pt(1));
 
    ctrlLineX.stroke(155,0,0);
    allCtrlLineX.add(ctrlLineX);
  }
 
  return allCtrlLineX;
}
 
 
Obj ptsSetToCurves(Obj ctrlX, int nPts){
  // Link the upper points together
  Obj curves = new Obj();
 
  for (int i = 0; i<ctrlX.numOfLines(); i++)
    curves.add(createCurve(ctrlX.line(i),nPts));
 
  return curves;
}
 
 
 
Pts createCurve(Pts construction, int nPts){
 
  // From this first set of points, create a curve of degree 4
  CSpline curve = new CSpline(construction,4);
 
  // Extract a serie of points from the curve
  Pts curveWithPointsUniform = curve.getPts(nPts);
  curveWithPointsUniform.stroke(155,155,255);
 
  return curveWithPointsUniform;
}
 
 
Obj createCtrlInY(Obj grid, int nPts){
  // Link the upper points together
  Obj allCtrlLineY = new Obj();
 
  for (int i = 0; i<grid.line(0).numOfPts(); i++){
    Pts ctrlLineY = new Pts();
    for (int j = 0; j<grid.numOfLines(); j++)
      ctrlLineY.add(grid.line(j).pt(i));
 
    ctrlLineY.stroke(200,0,0);
    allCtrlLineY.add(ctrlLineY);
  }
 
  return allCtrlLineY;
}
 
 
Obj createFacesFromAGrid(Obj grid){
  Obj output = new Obj();
  
  for (int i = 1; i<grid.numOfLines(); i++)
    for (int j = 1; j<grid.line(i).numOfPts(); j++)
    {
      Face f = new Face();
      
      f.add(grid.line(i-1).pt(j-1));
      f.add(grid.line(i-1).pt(j));
      f.add(grid.line(i).pt(j));
      f.add(grid.line(i).pt(j-1));
      
      output.add(f);
    }
 
  
  return output;
}
 
 
void draw(){
  background(155);
  myObj.draw();
}