Loading...
Logo
Processing Forum
p3tr4s's Profile
57 Posts
72 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    Hi,

    I am working with "Hemesh" Library intersection and substraction functions.

    I have applied substraction, calculating not one element with another, but one with many.
    Sadly, it works with substraction function, but for intersection, I miss something.

    The substracted part is in blue color, and intersected part should be in red (but it does not work, but I either do not get any errors)

    The code:


    1. import wblut.math.*;
    2. import wblut.processing.*;
    3. import wblut.core.*;
    4. import wblut.hemesh.*;
    5. import wblut.geom.*;
    6. import java.util.List;

    7. WB_Render render;

    8. void setup() {

    9.   size(1280, 720, OPENGL);
    10.   smooth();

    11.   //initialize WB_Render
    12.   render = new WB_Render(this);
    13. }//setup

    14. void draw() {
    15.   background(255);

    16.   //size of polygon, call it radius;
    17.   int dim = 200;

    18.   ArrayList <WB_Polygon2D> inputPolys = new ArrayList <WB_Polygon2D> ();
    19.   ArrayList <WB_Point2d> points = new ArrayList <WB_Point2d> ();

    20.   //Polygon a initialization (in this case triangle)
    21.   points.add(new WB_Point2d(width/2, height/3-dim));
    22.   points.add(new WB_Point2d(width/2+dim, height/2+dim/2));
    23.   points.add(new WB_Point2d(width/2-dim, height/2+dim/2));
    24.   inputPolys.add(new WB_Polygon2D (points));
    25.   ///////////////////////////////////////////////////

    26.   //clear points or bad things would happen
    27.   points.clear();

    28.   //Polygon b initialization (in this case triangle)
    29.   points.add( new WB_Point2d(mouseX, mouseY-dim) );
    30.   points.add( new WB_Point2d(mouseX+dim, mouseY+dim/2) );
    31.   points.add( new WB_Point2d(mouseX-dim, mouseY+dim/2) );
    32.   inputPolys.add(new WB_Polygon2D (points));
    33.   ///////////////////////////////////////////////////

    34.   points.clear();

    35.   //Polygon a initialization (in this case triangle)
    36.   points.add(new WB_Point2d(width/4, height/3-dim));
    37.   points.add(new WB_Point2d(width/5+dim, height/5+dim/2));
    38.   points.add(new WB_Point2d(width/5-dim, height/5+dim/2));
    39.   inputPolys.add(new WB_Polygon2D (points));
    40.   ///////////////////////////////////////////////////

    41.   points.clear();

    42.   //Polygon a initialization (in this case triangle)
    43.   points.add(new WB_Point2d(width/4, height/3+dim));
    44.   points.add(new WB_Point2d(width/5-dim, height/8+dim/2));
    45.   points.add(new WB_Point2d(width/8+dim, height/5+dim/2));
    46.   inputPolys.add(new WB_Polygon2D (points));
    47.   ////////////////////////////////////////////////////////////////////////substraction - blue color

    48.   List <WB_Polygon2D> subtractPolys = new ArrayList <WB_Polygon2D> ();

    49.   for (int i = 0; i < inputPolys.size(); i++) {
    50.     subtractPolys.addAll(subtractManyFromOne(inputPolys.get(i), inputPolys));
    51.   }
    52.   fill(0,0,255);
    53.   noStroke();
    54.   for (WB_Polygon2D p : subtractPolys) {
    55.     render.drawPolygon2D(p);
    56.   }

    57.   ///////////////////////////////////////////////////////////////////////////intersection - red color
    58.   List <WB_Polygon2D> intersectPolys = new ArrayList <WB_Polygon2D> ();

    59.   for (int i = 0; i < inputPolys.size(); i++) {
    60.     intersectPolys.addAll(intersectManyFromOne(inputPolys.get(i), inputPolys));
    61.   }
    62.   fill(255,0,0);
    63.   for (WB_Polygon2D i : intersectPolys) {
    64.     fill(0);
    65.     render.drawPolygon2D(i);
    66.   }

    67.   noFill();
    68.   stroke(0);
    69.   // for (WB_Polygon2D p : inputPolys) {
    70.   // render.drawPolygon2D(p);
    71.   // }
    72. }//draw


    73. List <WB_Polygon2D> subtractManyFromOne(WB_Polygon2D one, List <WB_Polygon2D> many) {
    74.   List <WB_Polygon2D> allFragments=new ArrayList <WB_Polygon2D> ();// this will collect all the pieces that remain from "one" after subtracting "many"
    75.   allFragments.add(one); //start with the source poly "one"
    76.   for (WB_Polygon2D other:many) {
    77.     if (other!=one) {//this way "one" can be part an element of "many" and you don't have to worry about self-subtracting...
    78.       // Subtracting a polygon can result in several fragments.To subtract another polygon you need to do that for all fragments. Giving you a new list of 
    79.       // fragments etc.
    80.       List <WB_Polygon2D> AllFragmentsMinusOther=new ArrayList <WB_Polygon2D> ();// this stores all new fragments
    81.       for (WB_Polygon2D fragment: allFragments) {
    82.         AllFragmentsMinusOther.addAll(WB_Polygon2D.subtract(fragment, other));
    83.       }
    84.       allFragments=AllFragmentsMinusOther;//for the next poly top subtract you need to start from the new list of fragments, etc.
    85.     }
    86.   }
    87.   return allFragments;
    88. }


    89. List <WB_Polygon2D> intersectManyFromOne(WB_Polygon2D one, List <WB_Polygon2D> many) {
    90.   
    91.   
    92.   List <WB_Polygon2D> allFragments=new ArrayList <WB_Polygon2D> ();// this will collect all the pieces that remain from "one" after intersecting "many"
    93.   allFragments.add(one); //start with the source poly "one"  
    94.   
    95.   for (WB_Polygon2D other:many) {
    96.    if (other!=one) {//this way "one" can be part an element of "many" and you don't have to worry about self-intersection...
    97.       // Intersecting a polygon can result in several fragments.To intersect another polygon you need to do that for all fragments. Giving you a new list of 
    98.       // fragments etc.
    99.       List <WB_Polygon2D> AllFragmentsMinusOther=new ArrayList <WB_Polygon2D> ();// this stores all new fragments
    100.       
    101.       
    102.       for (WB_Polygon2D fragment: allFragments) {
    103.         AllFragmentsMinusOther.addAll(WB_Polygon2D.intersection(fragment, other));
    104.       }
    105.       
    106.       
    107.       allFragments=AllFragmentsMinusOther;//for the next poly top intersect you need to start from the new list of fragments, etc.
    108.     }
    109.   }
    110.   return allFragments;
    111.   
    112.   
    113. }

    Earlier, Amnon Owed gave me this script with intersections: But is it possible to make the upper script work with intersection "one with many"?

    1.  for (int i = 0; i < inputPolys.size(); i++) {
    2.     WB_Polygon2D a = inputPolys.get(i);
    3.     for (int j = i+1; j < inputPolys.size(); j++) {
    4.       WB_Polygon2D b = inputPolys.get(j);


    5.       List <WB_Polygon2D> polys = WB_Polygon2D.intersection(a, b);

    6.       for (WB_Polygon2D p : polys) {
    7.         fill(0, 50);
    8.         render.drawPolygon2D(p);
    9.         fill(0);
    10.         render.drawPolygon2DVertices(p, 5);
    11.       }//for


    Hello,

    I would like to ask if you could give me a reference of processing code or library that works with intersection of polygons.

    The idea of the script is having multiple polygons intersecting with each other. 

    For example, there are two polygons. Usually you can draw one line between intersecting rectangles, between points A and B. Then I need to cut the part of polygon in the line AB and delete it.

    I uploaded dropbox idea sketch for it.  IDEA

    Could you give me ideas how to start thinking about this script development?

    Best,
    Petras.
    Hello,

    I am working with strings in a txt file.

    The code is simple:
    1. String [] stopWords;

    2. void setup() {

    3.   stopWords = loadStrings("stopwords.txt"); 

    4.   for (String stopWord : stopWords) {
    5.     println(stopWord);
    6.   }
    7. }
    When I "println(stopWord)"
    I get: a,able,about,across,after,all,almost,also,am...

    The txt file data is written in one line: a,able,about,across,after,all,almost,also,am...

    How to write data in a txt file to get the output of "println(stopWord)" not in a line, but in a list (without changing the processing code):
    a,
    able,
    about,
    across,
    ....

    The reason why I asking this, is I have a code which check the every word from another list and compares with "stopWord" string list:

    1. boolean isStopWord(String word){
    2.   for(String stopWord : stopWords){
    3.     println(stopWord);

    4.     if(word.equals(stopWord)){
    5.       return true;
    6.     }//if
    7.   }//for
    8.   return false;
    9. }//isStopWord()
    Thank you:)
    Hi,

    I have a small question with arrays. 
    I have 10 ellipses drawn in a circle. Each ellipse is connected by a string.

    How to write the last string in order to connect the last ellipse with the first one?

    Thank you in advance:)

    The code:

    1. ball[] balls;
    2. stick[] sticks;


    3. int stickLen = 80;
    4. int nBalls = 10;
    5. int nSticks = nBalls-1;

    6. void setup() {

    7.   size(1280, 720);
    8.   smooth();
    9.   frameRate(1);

    10.   balls = new ball[nBalls];
    11.   sticks = new stick[nSticks];

    12.   for (int i = 0; i < nBalls; i++) {

    13.     balls[i] = new ball(new PVector(sin(radians(i*36))*100+width/2, cos(radians(i*36))*100+height/2), 10);

    14.     if (i > 0) {
    15.       sticks[i-1] = new stick(balls[i-1], balls[i]);
    16.     }
    17.     
    18.     
    19.   }
    20. }

    21. void draw() {

    22.   background(255);

    23.   for (int i = 0; i < nSticks; i++) {


    24.     sticks[i].update();
    25.     sticks[i].display();
    26.   }
    27. }
    28. class ball {

    29.   color ballColor;
    30.   float radius;

    31.   PVector location;
    32.   PVector oldLocation;
    33.   PVector nudge;

    34.   ball(PVector loc, float r) {
    35.     location = loc;
    36.     radius = r;
    37.     ballColor = color(0);

    38.     oldLocation = location.get();
    39.     nudge = new PVector(random(1, 3), random(1, 3));
    40.     location.add(nudge);
    41.   }//ball()

    42.   void display() {

    43.     stroke(1);
    44.     noFill();
    45.     ellipse(location.x, location.y, 2*radius, 2*radius);
    46.   }

    47.   void move() {

    48.     PVector temp = location.get();
    49.     location.x += (location.x-oldLocation.x);
    50.     location.y += (location.y-oldLocation.y);
    51.     oldLocation.set(temp);

    52.     stroke(10);
    53.     line(location.x, location.y, oldLocation.x, oldLocation.y);

    54.     bounce();
    55.   }//move


    56.     void bounce() {

    57.     if (location.x > (width-radius)) {
    58.       location.x = width-radius;
    59.       oldLocation.x = location.x;
    60.       location.x -= nudge.x;
    61.     }

    62.     if (location.x < radius) {
    63.       location.x = radius;
    64.       oldLocation.x = location.x;
    65.       location.x += nudge.x;
    66.     }

    67.     if (location.y > (height-radius)) {
    68.       location.y = height-radius;
    69.       oldLocation.y = location.y;
    70.       location.y -= nudge.y;
    71.     }

    72.     if (location.y < radius) {
    73.       location.y = radius;
    74.       oldLocation.y = location.y;
    75.       location.y += nudge.y;
    76.     }
    77.   }
    78. }//end of class ball
    79. class stick {

    80.   ball b1, b2;
    81.   float r;

    82.   stick(ball b1, ball b2) {

    83.     this.b1 = b1;
    84.     this.b2 = b2;

    85.     //compute the length of the stick
    86.     //same as the intial distance between two balls

    87.     r = b1.location.dist(b2.location);
    88.   }

    89.   void display() {

    90.     b1.display();
    91.     b2.display();

    92.     stroke(255, 0, 0);
    93.     strokeWeight(5);
    94.     line(b1.location.x, b1.location.y, b2.location.x, b2.location.y);
    95.   }

    96.   void update() {
    97.     b1.move();  
    98.     b2.move();
    99.     constrainLength();
    100.   }

    101.   void constrainLength() {

    102.     float k = 0.1;
    103.     //delta = atstumas
    104.     //r = distance
    105.     PVector delta = PVector.sub(b2.location, b1.location);

    106.     float deltaLength = delta.mag();
    107.     float d = ( (deltaLength - r) / deltaLength);

    108.     b1.location.x += delta.x * k * d/2;
    109.     b1.location.y += delta.y * k * d/2;
    110.     b2.location.x -= delta.x * k * d/2;
    111.     b2.location.y -= delta.y * k * d/2;
    112.   }//constrainLength()
    113. }//end of stick
    Hi,

    I have another small issue with the code in eclipse. I just want to add  25 shapes in arrayList. This works also in processing but not in eclipse.

    I marked the line in red. According to eclipse I get error and nothing works...

    Could you help me please?

    Thank you.


    1. package tutorialpshapeoop2;

    2. import java.awt.Polygon;
    3. import java.util.ArrayList;
    4. import processing.core.PShape;
    5. import processing.core.PApplet;


    6. public class TutorialPShapeOOP2 extends PApplet {
    7. ArrayList<Polygon> polygons;

    8. public void setup() {
    9. size(640,360,OPENGL);
    10. smooth();
    11. polygons = new ArrayList<Polygon>();
    12. PShape star = createShape();
    13. star.fill(0,127);
    14. star.stroke(0);
    15. star.vertex(0, -50);
    16.    star.vertex(14, -20);
    17. star.vertex(47, -15);
    18. star.vertex(23, 7);
    19. star.vertex(29, 40);
    20. star.vertex(0, 25);
    21. star.vertex(-29, 40);
    22. star.vertex(-23, 7);
    23. star.vertex(-47, -15);
    24. star.vertex(-14, -20);
    25. star.end(CLOSE);
    26. for(int i = 0; i < 25; i++){
    27. polygons.add(new Polygon(star));
    28. //polygons.add(new Polygon(this,star)); //do not work either
    29. }
    30. }

    31. public void draw() {
    32. background(255);
    33. for(Polygon poly : polygons){
    34. poly.display();
    35. poly.move();
    36. }
    37. }
    38. }



    39. package tutorialpshapeoop2;

    40. import processing.core.PApplet;
    41. import processing.core.PShape;

    42. public class Polygon {
    43. PApplet parent;
    44. PShape s;
    45. float x,y;
    46. float speed;
    47. Polygon(PApplet p, PShape s_){
    48. parent = p;
    49. x = parent.random(parent.width);
    50. y = parent.random(-500,-100);
    51. s = s_;
    52. speed = parent.random(2,6);
    53. }
    54. void move(){
    55. y += speed;
    56. if(y > parent.height+100){
    57. y = -100;
    58. }
    59. }
    60. void display(){
    61. parent.pushMatrix();
    62. parent.translate(x,y);
    63. parent.shape(s);
    64. parent.popMatrix();
    65. }

    66. }


    Hello,

    I just want to solve:

    "PShape s" 

    The example file works in processing perfectly but not in proclipsing.

    Could you help me please?

    Here is the code:

    1. package tutorialpshape;

    2. import processing.core.PApplet;


    3. PShape s;

    4. public class TutorialPShape extends PApplet {

    5. public void setup() {
    6.  size(640, 360, P2D);
    7.  smooth();
    8.  // Make a shape
    9.  s = createShape();
    10.  s.fill(0);
    11.  s.stroke(255);
    12.  s.strokeWeight(2);
    13.  // Exterior part of shape
    14.  s.beginContour();
    15.  s.vertex(-100,-100);
    16.  s.vertex(100,-100);
    17.  s.vertex(100,100);
    18.  s.vertex(-100,100);
    19.  s.vertex(-100,-100);
    20.  s.endContour();
    21.  
    22.  // Interior part of shape
    23.  s.beginContour();
    24.  s.vertex(-10,-10);
    25.  s.vertex(10,-10);
    26.  s.vertex(10,10);
    27.  s.vertex(-10,10);
    28.  s.vertex(-10,-10);
    29.  s.endContour();
    30.  
    31.  // Finishing off shape
    32.  s.end();
    33. }

    34. public void draw() {
    35. background(52);
    36.  // Display shape
    37.  translate(width/2, height/2);
    38.  // Shapes can be rotated
    39.  s.rotate(0.01);
    40.  shape(s);
    41. }
    42. }
    Hi,

    I am trying to modify toxiclibs script polar lines

    I have two points:

    Red point - start;
    Blue point - end;

    The path of the point is linear function from red to blue point.

    What I am seeking to do is to move red point along the path, when the red point reaches the end it bounces back and goes back in the point till it reaches start point the bounces again.

    I know that there is possibility somehow to get the direction of this path.

    My question:

    How to find directionality or velocity vector from red to blue point?
    And how to define boundaries that the point would only bounce from red to blue point?
    Actually it is only simple movement called point on curve.

    Maybe there is another script, that simplifies what I seeking: simple linear curve and point on it, and according to draw function and moves along a curve the bounces back when it reaches the end points?

    1. import toxi.geom.*;


    2. Vec2D velocity;

    3. void setup() {
    4.   size(400, 400);
    5.   smooth();

    6.   velocity = new Vec2D(10, 10);
    7. }

    8. void draw() {
    9.   background(255);
    10.   translate(width/2, height/2);
    11.   stroke(255, 0, 0);
    12.   strokeWeight(2);

    13.   // start point at radius 10, 0 degrees
    14.   Vec2D a=new Vec2D(10, 0);

    15.   // end point at mouse position
    16.   Vec2D b=new Vec2D(350, 100).sub(width/2, height/2).toPolar();
    17.   // force at least 1 full turn to create spiral
    18.   b.y+=4*PI;



    19.   // draw a line from a -> b in CARTESIAN space
    20.   // transfer points into cartesian space
    21.   a.toCartesian();
    22.   b.toCartesian();
    23.   stroke(0, 0, 255);
    24.   // calculate intermediate points
    25.   for (int i=0,num=10; i<num; i++) {
    26.     // interpolation already happens in cartesian space
    27.     // no further conversion needed
    28.     Vec2D p=a.interpolateTo(b, (float)i/num);
    29.     point(p.x, p.y);


    30.     //ellipse movement start point 
    31.     ellipse(a.x, a.y, 10, 10); 
    32.     //ellipse movement end point 
    33.     if(i==9){
    34.     stroke(255,0,0); 
    35.     ellipse(p.x, p.y, 10, 10);
    36.     }
    37.   }
    38. }

    Hello,

    I am dealing with "ShifmannFlock3D library toxiclibs" script.

    I imported points:
    1. String points1[] = loadStrings("C:/Users/P3tr4s/Documents/PROGRAMMING/eclipse64/Plethora_agent_folow_curve_modify1/bin/data/bezier1.txt");
    2. String points1[] = loadStrings("C:/Users/P3tr4s/Documents/PROGRAMMING/eclipse64/Plethora_agent_folow_curve_modify1/bin/data/bezier1.txt");
    txt files links:


    Everything works fine.

    But I want somehow get access separately to a list of points1 and points2 to draw a line between point1 and point2.

    I know it this would be simple question for you. Please help me to draw a line between  these two strings.

    Here is the script:

    1. import processing.opengl.*;
    2. import toxi.processing.*;
    3. import toxi.geom.*;
    4. import toxi.geom.mesh.*;
    5. import toxi.math.*;
    6. import peasy.*;

    7. ArrayList<Vec3D> importPos = new ArrayList<Vec3D>();
    8. ArrayList<Vec3D> importPos2 = new ArrayList<Vec3D>();
    9. ArrayList<Vec3D> importPos3 = new ArrayList<Vec3D>();
    10. ArrayList<Vec3D> importPos4 = new ArrayList<Vec3D>();

    11. int DIM = 600;
    12. int NUM = 200;
    13. int NEIGHBOR_DIST = 50;
    14. int SEPARATION = 25;
    15. float BOID_SIZE = 5;

    16. Flock flock;
    17. Flock flock1;

    18. PeasyCam cam;


    19. ToxiclibsSupport gfx;

    20. void setup() {

    21.   size(1280, 800, OPENGL);
    22.   cam = new PeasyCam(this, 200, 500, 700, 400);


    23.   flock = new Flock();
    24.   smooth();

    25.   String points1[] = loadStrings("C:/Users/P3tr4s/Documents/PROGRAMMING/eclipse64/Plethora_agent_folow_curve_modify1/bin/data/bezier1.txt");

    26.   for (int i = 0; i < (points1.length); i++) {

    27.     String[] txtCoord = split(points1[i], ",");
    28.     float x = Float.parseFloat(txtCoord[0]);
    29.     float y = Float.parseFloat(txtCoord[1]);
    30.     float z = Float.parseFloat(txtCoord[2]);
    31.     Vec3D pos = new Vec3D(x, -y, z+300);
    32.     importPos.add(pos);
    33.   }

    34.   String points2[] = loadStrings("C:/Users/P3tr4s/Documents/PROGRAMMING/eclipse64/Plethora_agent_folow_curve_modify1/bin/data/bezier2.txt");

    35.   for (int i = 0; i < (points2.length); i++) {

    36.     String[] txtCoord = split(points2[i], ",");
    37.     float x = Float.parseFloat(txtCoord[0]);
    38.     float y = Float.parseFloat(txtCoord[1]);
    39.     float z = Float.parseFloat(txtCoord[2]);
    40.     Vec3D pos2 = new Vec3D(x, -y, z+300);
    41.     importPos2.add(pos2);
    42.   } 


    43.   //ARRAYLIST OF PARTICLES

    44.   for (int i = 0; i < importPos.size(); i++) {

    45.     Vec3D pos = importPos.get(i);
    46.     flock.addBoid(new Boid(new Vec3D(pos.x, pos.y, pos.z), .12, 0.002, NEIGHBOR_DIST, SEPARATION));
    47.   }

    48.   for (int i = 0; i < importPos2.size(); i++) {

    49.     Vec3D pos = importPos2.get(i);
    50.     flock.addBoid(new Boid(new Vec3D(pos.x, pos.y, pos.z), .12, 0.002, NEIGHBOR_DIST, SEPARATION));
    51.   }
    52. }

    53. void draw() {
    54.   background(0);


    55.   lights();
    56.   translate(width/2, height/2, 0);

    57.   noFill();
    58.   stroke(255, 50);
    59.   box(DIM*2);
    60.   fill(255);
    61.   noStroke();
    62.   flock.run();
    63. }











    64. // Boid class
    65. // Methods for Separation, Cohesion, Alignment added

    66. class Boid {

    67.   Vec3D loc;
    68.   Vec3D vel;
    69.   Vec3D acc;
    70.   float maxforce;
    71.   float maxspeed;

    72.   float neighborDist;
    73.   float desiredSeparation;

    74.   Boid(Vec3D l, float ms, float mf, float nd, float sep) {
    75.     loc=l;
    76.     acc = new Vec3D();
    77.     vel = Vec3D.randomVector();
    78.     maxspeed = ms;
    79.     maxforce = mf;
    80.     neighborDist=nd*nd;
    81.     desiredSeparation=sep;
    82.   }

    83.   void run(ArrayList boids) {
    84.     flock(boids);
    85.     update();
    86.     borders();
    87.     render();
    88.   }

    89.   // We accumulate a new acceleration each time based on three rules
    90.   void flock(ArrayList boids) {
    91.     Vec3D sep = separate(boids);   // Separation
    92.     Vec3D ali = align(boids);      // Alignment
    93.     Vec3D coh = cohesion(boids);   // Cohesion
    94.     // Arbitrarily weight these forces
    95.     sep.scaleSelf(1.5);
    96.     ali.scaleSelf(1.0);
    97.     coh.scaleSelf(1.0);
    98.     // Add the force vectors to acceleration
    99.     acc.addSelf(sep);
    100.     acc.addSelf(ali);
    101.     acc.addSelf(coh);
    102.   }

    103.   // Method to update location
    104.   void update() {
    105.     // Update velocity
    106.     vel.addSelf(acc);
    107.     // Limit speed
    108.     vel.limit(maxspeed);
    109.     loc.addSelf(vel);
    110.     // Reset accelertion to 0 each cycle
    111.     acc.clear();
    112.   }

    113.   void seek(Vec3D target) {
    114.     acc.addSelf(steer(target, false));
    115.   }

    116.   void arrive(Vec3D target) {
    117.     acc.addSelf(steer(target, true));
    118.   }


    119.   // A method that calculates a steering vector towards a target
    120.   // Takes a second argument, if true, it slows down as it approaches the target
    121.   Vec3D steer(Vec3D target, boolean slowdown) {
    122.     Vec3D steer;  // The steering vector
    123.     Vec3D desired = target.sub(loc);  // A vector pointing from the location to the target
    124.     float d = desired.magnitude(); // Distance from the target is the magnitude of the vector
    125.     // If the distance is greater than 0, calc steering (otherwise return zero vector)
    126.     if (d > 0) {
    127.       // Normalize desired
    128.       desired.normalize();
    129.       // Two options for desired vector magnitude (1 -- based on distance, 2 -- maxspeed)
    130.       if ((slowdown) && (d < 100.0f)) desired.scaleSelf(maxspeed*(d/100.0f)); // This damping is somewhat arbitrary
    131.       else desired.scaleSelf(maxspeed);
    132.       // Steering = Desired minus Velocity
    133.       steer = desired.sub(vel).limit(maxforce);  // Limit to maximum steering force
    134.     } 
    135.     else {
    136.       steer = new Vec3D();
    137.     }
    138.     return steer;
    139.   }

    140.   void render() {

    141.   stroke(255);
    142.   strokeWeight(1);
    143.   point(loc.x, loc.y, loc.z); 
    144.   
    145.   }
    146.   // Wraparound
    147.   void borders() {
    148.     if (loc.x < -DIM) loc.x = DIM;
    149.     if (loc.y < -DIM) loc.y = DIM;
    150.     if (loc.z < -DIM) loc.z = DIM;
    151.     if (loc.x > DIM) loc.x = -DIM;
    152.     if (loc.y > DIM) loc.y = -DIM;
    153.     if (loc.z > DIM) loc.z = -DIM;
    154.   }

    155.   // Separation
    156.   // Method checks for nearby boids and steers away
    157.   Vec3D separate (ArrayList boids) {
    158.     Vec3D steer = new Vec3D();
    159.     int count = 0;
    160.     // For every boid in the system, check if it's too close
    161.     for (int i = boids.size()-1 ; i >= 0 ; i--) {
    162.       Boid other = (Boid) boids.get(i);
    163.       if (this != other) {
    164.         float d = loc.distanceTo(other.loc);
    165.         // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself)
    166.         if (d < desiredSeparation) {
    167.           // Calculate vector pointing away from neighbor
    168.           Vec3D diff = loc.sub(other.loc);
    169.           diff.normalizeTo(1.0/d);
    170.           steer.addSelf(diff);
    171.           count++;
    172.         }
    173.       }
    174.     }
    175.     // Average -- divide by how many
    176.     if (count > 0) {
    177.       steer.scaleSelf(1.0/count);
    178.     }

    179.     // As long as the vector is greater than 0
    180.     if (steer.magSquared() > 0) {
    181.       // Implement Reynolds: Steering = Desired - Velocity
    182.       steer.normalizeTo(maxspeed);
    183.       steer.subSelf(vel);
    184.       steer.limit(maxforce);
    185.     }
    186.     return steer;
    187.   }

    188.   // Alignment
    189.   // For every nearby boid in the system, calculate the average velocity
    190.   Vec3D align (ArrayList boids) {
    191.     Vec3D steer = new Vec3D();
    192.     int count = 0;
    193.     for (int i = boids.size()-1 ; i >= 0 ; i--) {
    194.       Boid other = (Boid) boids.get(i);
    195.       if (this != other) {
    196.         if (loc.distanceToSquared(other.loc) < neighborDist) {
    197.           steer.addSelf(other.vel);
    198.           count++;
    199.         }
    200.       }
    201.     }
    202.     if (count > 0) {
    203.       steer.scaleSelf(1.0/count);
    204.     }

    205.     // As long as the vector is greater than 0
    206.     if (steer.magSquared() > 0) {
    207.       // Implement Reynolds: Steering = Desired - Velocity
    208.       steer.normalizeTo(maxspeed);
    209.       steer.subSelf(vel);
    210.       steer.limit(maxforce);
    211.     }
    212.     return steer;
    213.   }

    214.   // Cohesion
    215.   // For the average location (i.e. center) of all nearby boids, calculate steering vector towards that location
    216.   Vec3D cohesion (ArrayList boids) {
    217.     Vec3D sum = new Vec3D();   // Start with empty vector to accumulate all locations
    218.     int count = 0;
    219.     for (int i = boids.size()-1 ; i >= 0 ; i--) {
    220.       Boid other = (Boid) boids.get(i);
    221.       if (this != other) {
    222.         if (loc.distanceToSquared(other.loc) < neighborDist) {
    223.           sum.addSelf(other.loc); // Add location
    224.           count++;
    225.           
    226.           

    227.           
    228.           
    229.         }
    230.       }
    231.     }
    232.     if (count > 0) {
    233.       sum.scaleSelf(1.0/count);
    234.       return steer(sum, false);  // Steer towards the location
    235.     }
    236.     return sum;
    237.   }
    238. }




    239. class Flock {
    240.   ArrayList boids; // An arraylist for all the boids

    241.     Flock() {
    242.     boids = new ArrayList(); // Initialize the arraylist
    243.   }

    244.   void run() {
    245.     for (int i = boids.size()-1 ; i >= 0 ; i--) {
    246.       Boid b = (Boid) boids.get(i);  
    247.       b.run(boids);  // Passing the entire list of boids to each boid individually
    248.        
    249.     }
    250.    
    251.   }

    252.   void addBoid(Boid b) {
    253.     boids.add(b);
    254.   }
    255. }


    Hi,

    Could you help me correcting syntax errors, when I rewrote processing sketch in eclipse.
    Errors are very little, and time to time repeats... It would be enormous help for me for future scripts. Thanks:)

    I will upload print-screens  what was wrong in eclipse:

    Here there is the script th eclipse rewritten, but it I do not know how to fix it:
    It is made by D.Shiffman. - toxiclibs --> attraction point;
    1. package layering;

      import peasy.PeasyCam;
      import processing.core.PApplet;
      import toxi.physics.VerletPhysics;
      import toxi.geom.*;
      import toxi.physics.behaviors.*;
      import toxi.physics.*;


      public class Layering extends PApplet {
      boolean dxfExport;
      boolean record;
      VerletPhysics physics;
      Cluster cluster;
      PeasyCam cam;
      int def;
      int abc;
      int sceneWidth = 1280;
      int sceneHeight = 800;

      public void setup() {
      size(sceneWidth, sceneHeight,OPENGL);
      cam = new PeasyCam(this, 200, 500, 700, 400);
       physics=new VerletPhysics();
       physics.setDrag(0.05f);
       physics.setWorldBounds(new AABB(new Vec3D(sceneWidth/2, sceneHeight/2, 0), new Vec3D(sceneWidth/2, sceneHeight/2, 600)));
       cluster = new Cluster(this, 10, 0.0000000000000000001f, sceneWidth/40, sceneHeight/40);
       
      }

      public void draw() {
        
        background(255);
        physics.update();
        cluster.display();
        cluster.showConnections();
      }
      }


      package layering;

      import java.util.ArrayList;

      import toxi.geom.Vec3D;
      import toxi.physics.VerletParticle;

      public class Cluster {
      Layering e;
      ArrayList <Particle> particles;
      ArrayList <Attractor> attractors = new ArrayList <Attractor>();
      float diameter;
      float springRadius = 30;
      float springForce;
      int gridDimensionX;
      int gridDimensionY;
      float pv = 20;
      Cluster(Layering _e, float d, float sf, int gridDimX, int gridDimY){
      e = _e;
      particles = new ArrayList();
      diameter = d;
      springForce = sf;
      gridDimensionX = gridDimX;
      gridDimensionY = gridDimY;
      int w = e.width/gridDimX;
      int h = e.height/gridDimY;
      //ArrayList of particles
      for (int y = 0; y < gridDimY; y++) {
      for (int x = 0; x < gridDimX; x++) {
      particles.add(new Particle(new Vec3D(  (x+0.5f)*w, (y+0.5f)*h, 0 )));
      }
      }
      attractors.add( new Attractor(new Vec3D(e.width/2,e.height/2,0), e.random(-.1f,.1f)));
      //ArrayList of springs physics
      for (int i = 0; i < particles.size()-1; i++){
      VerletParticle ni = particles.get(i);
      for (int j = i+1; j < particles.size(); j++){
      VerletParticle nj = particles.get(j);
      if (e.dist(ni.x, ni.y, nj.x, nj.y) < springRadius) {
      }
      }
      }
      }
      void display(){
      for (Attractor a : attractors) {
      a.display();
      for (Particle p : particles) {
      p.display();
      a.lock();
      }
      }
      }
      void showConnections() {
      for (int i = 0; i < particles.size()-1; i++){
      VerletParticle pi = (VerletParticle) particles.get(i);
      for (int j = i+1; j < particles.size(); j++) {
      VerletParticle pj = (VerletParticle) particles.get(j);
      if (e.dist(pi.x, pi.y, pj.x, pj.y)<25 && e.dist(pi.x, pi.y, pj.x, pj.y)>19 ) {
      e.stroke(10);
      e.fill(255);
      e.beginShape();
               
      e.vertex(pi.x, pi.y );
      e.vertex(pj.x, pj.y );
      e.vertex(pj.x, pj.y,pv );
      e.vertex(pi.x, pi.y ,pv);

      e.endShape(e.CLOSE);
              
      }
      }
      }
      }

      }







      package layering;

      import toxi.geom.Vec3D;
      import toxi.physics.VerletParticle;
      import toxi.physics.behaviors.AttractionBehavior;



      public class Particle extends VerletParticle {
      Layering e;
      float n = 5;
      float pv;
      float r;
      Particle (Layering _e, Vec3D loc) {
      e = _e;
      super(loc);
      r = 5;
      physics.addParticle(this);
      physics.addBehavior(new AttractionBehavior(this,r*8,-0.01f));
      }
      void display(){
      Vec3D vel = getVelocity().getNormalizedTo(r*2);
      e.strokeWeight(0.5f);
      e.ellipse(x, y, r*2, r*2);
      }
      }




      package layering;

      import toxi.geom.Vec3D;
      import toxi.physics.VerletParticle;
      import toxi.physics.behaviors.AttractionBehavior;

      public class Attractor {


      Layering e;
      float r;
      float force;
      Attractor(Layering _e, Vec3D loc, float f){
      e = _e;
      super(loc);
      force = f;
      r = 10;
      physics.addParticle(this);
      physics.addBehavior(new AttractionBehavior(this,400,f));
      }
      void display (){
      e.noStroke();
      e.fill (10,200,200);
      ellipse(x,y,r*2,r*2);
      e.fill(0);
      }
      }





    Hello,

    I would like to ask your help converting processing sketch to eclipse.

    I am new to eclipse, I know how to implement class to get all the functionality from the main tab from Chose Sanchez tutorials.

    For learning purposes, day to day I try to rewrite other people sketches.

    But, when I try to rewrite sketches I usually get errors. Errors comes not from my writing mistakes but from difference in  know, that there is difference with syntax between these 2 applications. 

    Please help me make this sketch work in eclipse; 
    This would be enormous help for me for now and future. I really want to learn eclipse... 

    Thank you very much.

    Down here is processing sketch, and below it is eclipse sketch that does not work.

    Processing:
    1. int number_of_particles;
    2. line[] lines;
    3. collision collision;


    4. void setup() {
    5.   size(1280,720,OPENGL);
    6.   frameRate(20);
    7.   background(0);
    8.   number_of_particles = 6;
    9.   lines = new line[number_of_particles];
    10.   for( int x=0; x < number_of_particles; x++) {
    11.     lines[x] = new line();
    12.     lines[x].spawn_random();
    13.   }
    14.   collision = new collision(lines);
    15. }
    16. void draw() {

    17.   
    18.   for( int x=0; x < number_of_particles; x++) {
    19.     line temp_line = lines[x].draw();
    20.     if( temp_line != null) {
    21.       lines = (line[]) append(lines,temp_line);
    22.       collision.add_line(lines[number_of_particles]);
    23.       number_of_particles ++;
    24.     }
    25.   }

    26.   collision.of_lines();
    27.  
    28. }

    29. float[] collision_line_line(float p1_x, float p1_y, float p2_x, float p2_y, float p3_x, float p3_y, float p4_x, float p4_y) {
    30.   float xD1,yD1,xD2,yD2,xD3,yD3;
    31.   float dot,deg,len1,len2;
    32.   float segmentLen1,segmentLen2;
    33.   float ua,ub,div;

    34.   // calculate differences
    35.   xD1=p2_x-p1_x;
    36.   xD2=p4_x-p3_x;
    37.   yD1=p2_y-p1_y;
    38.   yD2=p4_y-p3_y;
    39.   xD3=p1_x-p3_x;
    40.   yD3=p1_y-p3_y;  

    41.   // calculate the lengths of the two lines
    42.   len1=sqrt(xD1*xD1+yD1*yD1);
    43.   len2=sqrt(xD2*xD2+yD2*yD2);

    44.   // calculate angle between the two lines.
    45.   dot=(xD1*xD2+yD1*yD2); // dot product
    46.   deg=dot/(len1*len2);

    47.   // if abs(angle)==1 then the lines are parallell,
    48.   // so no intersection is possible
    49.   if(abs(deg)==1) return null;

    50.   // find intersection Pt between two lines
    51.   float pt_x;
    52.   float pt_y;
    53.  // Point pt=new Point(0,0);
    54.   div=yD2*xD1-xD2*yD1;
    55.   ua=(xD2*yD3-yD2*xD3)/div;
    56.   ub=(xD1*yD3-yD1*xD3)/div;
    57.   pt_x=p1_x+ua*xD1;
    58.   pt_y=p1_y+ua*yD1;

    59.   // calculate the combined length of the two segments
    60.   // between Pt-p1 and Pt-p2
    61.   xD1=pt_x-p1_x;
    62.   xD2=pt_x-p2_x;
    63.   yD1=pt_y-p1_y;
    64.   yD2=pt_y-p2_y;
    65.   segmentLen1=sqrt(xD1*xD1+yD1*yD1)+sqrt(xD2*xD2+yD2*yD2);

    66.   // calculate the combined length of the two segments
    67.   // between Pt-p3 and Pt-p4
    68.   xD1=pt_x-p3_x;
    69.   xD2=pt_x-p4_x;
    70.   yD1=pt_y-p3_y;
    71.   yD2=pt_y-p4_y;
    72.   segmentLen2=sqrt(xD1*xD1+yD1*yD1)+sqrt(xD2*xD2+yD2*yD2);

    73.   // if the lengths of both sets of segments are the same as
    74.   // the lenghts of the two lines the point is actually
    75.   // on the line segment.

    76.   // if the point isn't on the line, return null
    77.   if(abs(len1-segmentLen1)>0.1 || abs(len2-segmentLen2)>0.1)
    78.     return null;

    79.   // return the valid intersection

    80.   float[] output = new float[2];

    81.   output[0] = pt_x;
    82.   output[1] = pt_y;

    83.   return output;
    84. }
    85. class collision {


    86.   line[] lines= new line[0];

    87.   int total;

    88.   collision(line[] lines) {
    89.     this.lines = lines;
    90.     total = lines.length;
    91.   }

    92.   void add_line(line new_line) {
    93.     lines = (line[]) append(lines,new_line);
    94.     total++;
    95.   }

    96.   float[] temp = new float[2];

    97.   void of_lines() {


    98.     for( int x=0; x< total; x++) {

    99.       if(    (lines[x].end.x <0)||(lines[x].end.x>width)   ||   (lines[x].end.y <0)||(lines[x].end.y>height)         ) {
    100.         lines[x].collision = true;
    101.       }

    102.       for( int y=0; y< total; y++) {

    103.         if( ! lines[x].collision) {

    104.           if (x != y) {
    105.             temp =collision_line_line(lines[x].start.x,lines[x].start.y,lines[x].end.x,lines[x].end.y,lines[y].start.x,lines[y].start.y,lines[y].end.x,lines[y].end.y);

    106.             if( temp != null) {

    107.               if( ( abs(temp[0])-abs(lines[x].end.x)  < 5) && (abs(temp[1])-abs(lines[x].end.y) <5 )) {
    108.                 lines[x].collision();
    109.               }
    110.             }
    111.           }
    112.         }
    113.       }
    114.     }
    115.   }
    116. }
    117. class line {

    118.   PVector start = new PVector(); 
    119.   PVector end   = new PVector(); 

    120.   float velocity;
    121.   int way;

    122.   int spawn_base=4;
    123.   int spawn_rate=spawn_base;
    124.   int children_counter;
    125.   int children_max= 5;
    126.   float heading;
    127.   line child_line;

    128.   line() {
    129.     velocity = 2;
    130.   }

    131.   void spawn_random() {

    132.     start.x =  random(0, width);
    133.     start.y =  random(0, height);

    134.     end.x   =  start.x+random(-1, 1) ;
    135.     end.y   =  start.y+random(-1, 1) ;

    136.     heading = get_heading();
    137.   }


    138.   void spawn_location(float x, float y, float heading) {

    139.     way = round(random(-1, 1));

    140.     heading = heading+HALF_PI*way;


    141.     if (heading > TWO_PI) {
    142.       heading-=TWO_PI;
    143.     }

    144.     if (heading < -TWO_PI) {
    145.       heading+=TWO_PI;
    146.     }

    147.     this.heading=heading;


    148.     start.x = x + cos( heading)*velocity;
    149.     start.y = y + sin( heading)*velocity;

    150.     end.x =  start.x + cos( heading)*velocity;
    151.     end.y =  start.y + sin( heading)*velocity;
    152.   }




    153.   boolean spawn_timer() {

    154.     if (children_counter < children_max) {
    155.       if ( spawn_rate == 0 ) {
    156.         spawn_base *=spawn_base;
    157.         spawn_rate= spawn_base;
    158.         children_counter++;  
    159.         return true;
    160.       }
    161.       spawn_rate--;
    162.     }
    163.     return false;
    164.   }

    165.    line child_line() {

    166.     if ( (!collision)  && (spawn_timer()) ) {
    167.       child_line = new line();
    168.       child_line.spawn_location(end.x, end.y, heading);
    169.       return child_line;
    170.     }
    171.     else {
    172.       return null;
    173.     }
    174.   }

    175.   line draw() {
    176.     if ( ! collision) {

    177.       stroke(255);

    178.       line(start.x, start.y, end.x, end.y);
    179.       grow();
    180.       return child_line();
    181.     }
    182.     line(start.x, start.y, end.x, end.y);
    183.     return null;
    184.   }


    185.   float get_heading() {
    186.     return atan2(  start.y - end.y, start.x - end.x);
    187.   }

    188.   void grow() {

    189.     end.x +=  cos(heading)* (velocity);
    190.     end.y +=  sin(heading)* (velocity);
    191.   }

    192.   boolean  collision = false;

    193.   void collision() {
    194.     collision = true;
    195.   }
    196. }

    Eclipse code:


    1. package lines;

    2. import processing.core.PApplet;


    3. public class Lines extends PApplet {
    4. int number_of_particles = 6;
    5. Line[] lines;
    6. collision collission;
    7. public void setup() {
    8. size(1280,720,P3D);
    9. background(0);
    10. smooth();
    11. lines = new Line[number_of_particles];
    12. for (int x = 0; x < number_of_particles; x++) {
    13. lines[x] = new Line();
    14. lines[x].spawn_random();
    15. }
    16. collission = new collision(lines);
    17. }

    18. public void draw() {
    19. for(int x = 0; x < number_of_particles; x++){
    20. Line temp_line = lines[x].draw();
    21. if ( temp_line != null) {
    22. lines = (Line[]) append(lines,temp_line);
    23. collision.add_line(lines[number_of_particles]);
    24. number_of_particles ++; /////////////////////////////  del to stringa?
    25. }
    26. }
    27. collsion.of_lines();
    28. }
    29. float[] collision_line_line(float p1_x, float p1_y, float p2_x, float p2_y, float p3_x, float p3_y, float p4_x, float p4_y){
    30. float xD1,yD1,xD2,yD2,xD3,yD3;
    31. float dot,deg,len1,len2;
    32. float segmentLen1,segmentLen2;
    33. float ua,ub,div;
    34.  // calculate differences
    35.  xD1=p2_x-p1_x;
    36.  xD2=p4_x-p3_x;
    37.  yD1=p2_y-p1_y;
    38.  yD2=p4_y-p3_y;
    39.  xD3=p1_x-p3_x;
    40.  yD3=p1_y-p3_y; 
    41.  
    42.  //calculate the lengths of the two lines
    43.  len1 = sqrt(xD1*xD1+yD1*yD1);
    44.  len2 = sqrt(xD2*xD2+yD2*yD2);
    45.  
    46.  //calculate angle between the two lines
    47.  dot=(xD1*xD2+yD1*yD2); // dot product
    48.  deg=dot/(len1*len2);
    49.  
    50.  // if abs(angle) == 1 then the lines are parallell,
    51.  // if no -> intersection is possible
    52.  
    53.  if(abs(deg)==1) return null;
    54.  
    55.  //find intersection Pt between two lines;
    56.  float pt_x;
    57.  float pt_y;
    58.  
    59.  div=yD2*xD1-xD2*yD1;
    60.  ua=(xD2*yD3-yD2*xD3)/div;
    61.  ub=(xD1*yD3-yD1*xD3)/div;
    62.  pt_x=p1_x+ua*xD1;
    63.  pt_y=p1_y+ua*yD1;
    64.  
    65.  //calculate the combined length of the two segments: Pt-p1 and Pt-p2
    66.  xD1=pt_x-p1_x;
    67.  xD2=pt_x-p2_x;
    68.  yD1=pt_y-p1_y;
    69.  yD2=pt_y-p2_y;
    70.  segmentLen1=sqrt(xD1*xD1+yD1*yD1)+sqrt(xD2*xD2+yD2*yD2);
    71. //calculate the combined length of the two segments: Pt-p1 and Pt-p2
    72.  xD1=pt_x-p3_x;
    73.  xD2=pt_x-p4_x;
    74.  yD1=pt_y-p3_y;
    75.  yD2=pt_y-p4_y;
    76.  segmentLen2=sqrt(xD1*xD1+yD1*yD1)+sqrt(xD2*xD2+yD2*yD2);
    77.  
    78.  // if the lengths of both sets of segments are the same as
    79.  // the lengths of the two lines the point is actually
    80.  // on the line segment
    81.  
    82.  //if the points is not on the line, return null
    83.  
    84.  if(abs(len1-segmentLen1)>0.01 || abs(len2-segmentLen2)>0.01)
    85.    return null;
    86.  
    87.  //return the valid intersection
    88.  
    89.  float[] output = new float[2];
    90.  
    91.  output[0] = pt_x;
    92.  output[1] = pt_y;
    93.  
    94.  return output;  
    95. }
    96. }
    class Line:
    1. package lines;

    2. import processing.core.PVector;

    3. public class Line {

    4. Lines e;
    5. PVector start = new PVector();
    6. PVector end = new PVector();
    7. float velocity;
    8. int way;
    9.     int spawn_base=4;
    10.     int spawn_rate=spawn_base;
    11.     int children_counter;
    12.     int children_max= 5;
    13.     float heading;
    14.     Line child_line;
    15.     
    16. Line(Lines _e){
    17. e = _e;
    18. velocity = 2;
    19. }
    20. void spawn_random(){
    21. start.x = e.random(0,e.width);
    22. start.y = e.random(0,e.height);
    23. end.x = start.x+e.random(-1,1);
    24. end.y = start.y+e.random(-1,1);
    25. heading = get_heading();  
    26. }
    27. void spawn_location(float x, float y, float heading){
    28. way = e.round(e.random(-1,1));
    29. heading = e.heading+e.HALF_PI*way;
    30. if (heading>e.TWO_PI){
    31. heading-=e.TWO_PI;
    32. }
    33. if (heading<-e.TWO_PI){
    34. heading+=e.TWO_PI;
    35. }
    36. this.heading = heading;
    37. start.x = x + e.cos( heading)*velocity;
    38. start.y = y + e.sin( heading)*velocity;

    39. end.x =  start.x + e.cos( heading)*velocity;
    40. end.y =  start.y + e.sin( heading)*velocity;
    41. }
    42. boolean spawn_timer() {
    43. if(children_counter < children_max){
    44. if(spawn_rate == 0){
    45. spawn_base *= spawn_base;
    46. spawn_rate = spawn_base;
    47. children_counter++;
    48. return true;
    49. }
    50. spawn_rate--;
    51. }
    52. return false;
    53. }
    54. Line child_line() {

    55.    if ( (!collision)  && (spawn_timer()) ) {
    56.      child_line = new Line();
    57.      child_line.spawn_location(end.x, end.y, heading);
    58.      return child_line;
    59.    }
    60.    else {
    61.      return null;
    62.    }
    63.  }
    64.  
    65. Line draw() {
    66.    if ( ! collision) {

    67.      e.stroke(255);

    68.      Line(start.x, start.y, end.x, end.y);
    69.      grow();
    70.      return child_line();
    71.    }
    72.    Line(start.x, start.y, end.x, end.y);
    73.    return null;
    74.  }


    75.  float get_heading() {
    76.    return e.atan2(  start.y - end.y, start.x - end.x);
    77.  }

    78.  void grow() {

    79.    end.x +=  e.cos(heading)* (velocity);
    80.    end.y +=  e.sin(heading)* (velocity);
    81.  }

    82.  boolean  collision = false;

    83.  void collision() {
    84.    collision = true;
    85.  }
    86. }
    class collide:


    1. class collision {


    2.   line[] lines= new line[0];

    3.   int total;

    4.   collision(line[] lines) {
    5.     this.lines = lines;
    6.     total = lines.length;
    7.   }

    8.   void add_line(line new_line) {
    9.     lines = (line[]) append(lines,new_line);
    10.     total++;
    11.   }

    12.   float[] temp = new float[2];

    13.   void of_lines() {


    14.     for( int x=0; x< total; x++) {

    15.       if(    (lines[x].end.x <0)||(lines[x].end.x>width)   ||   (lines[x].end.y <0)||(lines[x].end.y>height)         ) {
    16.         lines[x].collision = true;
    17.       }

    18.       for( int y=0; y< total; y++) {

    19.         if( ! lines[x].collision) {

    20.           if (x != y) {
    21.             temp =collision_line_line(lines[x].start.x,lines[x].start.y,lines[x].end.x,lines[x].end.y,lines[y].start.x,lines[y].start.y,lines[y].end.x,lines[y].end.y);

    22.             if( temp != null) {

    23.               if( ( abs(temp[0])-abs(lines[x].end.x)  < 5) && (abs(temp[1])-abs(lines[x].end.y) <5 )) {
    24.                 lines[x].collision();
    25.               }
    26.             }
    27.           }
    28.         }
    29.       }
    30.     }
    31.   }
    32. }

    Thank you.
    Hi,

    How to import txt data into Proclipsing.

    For now, I used this in processing, but the bold line do not work in Eclipse:

    1.  String[] CH = loadStrings("C:/Users/P3tr4s/Documents/PROGRAMMING/eclipse64/Plethora_agent_folow_curve/bin/data/points.txt"); 
    2.    for (int i = 0; i<CH.length; i++) {
    3.     float[] C = float(split(CH[i], "," ));
    4.       attractors.add( new Attractor(new Vec3D(C[0]*2,C[1]*2, 0), 0.005));
    5.     ellipse(C[0]*2,C[1]*2,10,10);
    6.  }

    How to import .txt data into Proclipsing in a right way?

    Thank you:) 



    Hello,

    What command I should use if I want to import txt file in proclipsing?

    I have a txt file in a fixed directory.

    In Processing I was using 
    1. importSprings("/data/fromRhino/springs.txt");
    But this does not work in Eclipse.
    How to solve this problem?

    Hi,

    I am working in Eclipse using proclipsing.

    I have an error on Iterator. Eclipse do not give any solutions. My script works fine on Processing but on Eclipse Iterator does nots work?
    Could you help me please?

    1. void run(){
    2. Iterator<Particle> it = particles.iterator();
    3. while (it.hasNext()){
    4. Particle p = it.next();
    5. p.display();
    6. if(p.isDead()){
    7. it.remove();
    8. }
    9. }
    10. }

    11. }
    Hi,

    What is going on with sunflow render after first frame?
    Firstly, I have to say that everything with the library is ok, and everything is working.

    Smth is not good with the sunflow camera.
    After the first frame, second frame is zoomed in. When I tried to zoom out processing camera, I got the same results.
    The scene is just simple rotating camera.

    Maybe there is a problem that the camera is being rotated every frame?

    1. import java.awt.Color;
    2. import sunflowapiapi.P5SunflowAPIAPI;
    3. import org.sunflow.math.Point3;
    4. import org.sunflow.math.Vector3;

    5. import punktiert.physics.*;
    6. import punktiert.math.Vec;

    7. import processing.opengl.*;
    8. import processing.dxf.*;

    9. import peasy.PeasyCam;
    10. PeasyCam cam;
    11. float distance = 800;
    12. VPhysics physics;
    13. VPhysics physicsDrive;

    14. //object for loading Pictures
    15. PImage map;

    16. //declaring lists for storing specific elements
    17. ArrayList<Point> points;
    18. ArrayList<ArrayList> shapes;
    19. ArrayList<Nail> nails;
    20. ArrayList<Point> movers;
    21. ArrayList<BAttraction> attrs;
    22. ArrayList<ArrayList> meshList;
    23. float angle = 0;
    24. //strength of imported attractors
    25. float attrStrength = 0.005;

    26. //use underlying map
    27. boolean useMap =false;



    28. int sceneWidth = (int)(1280*1.5);
    29. int sceneHeight = (int)(720*1.5);
    30. P5SunflowAPIAPI sunflow ;
    31. ////////////////////////////////////////////////////////////

    32. public void setup() {
    33.   size(sceneWidth, sceneHeight, "sunflowapiapi.P5SunflowAPIAPI");//"sunflowapiapi.P5SunflowAPIAPI"
    34.   sunflow = (P5SunflowAPIAPI) g;
    35.   sunflow.setAmbientOcclusionShader();

    36.   smooth();
    37.   //set up camera (PApplet, distance)
    38.   perspective(PI/3.0, width/height, 1, 100000);
    39.   // inizialize physics engine
    40.   physics = new VPhysics(0);
    41.   physicsDrive = new VPhysics(500);
    42.   physicsDrive.setfriction(.1);

    43.   //initialize lists
    44.   attrs = new ArrayList<BAttraction>();
    45.   nails = new ArrayList<Nail>();
    46.   movers = new ArrayList<Point>();
    47.   points = new ArrayList<Point>();
    48.   shapes = new ArrayList<ArrayList>();

    49.   //import objects from text-files
    50.   importMovers("/data/fromRhino/movers.txt");
    51.   importNails("/data/fromRhino/nails.txt");
    52.   importShapes("/data/fromRhino/shapes.txt");
    53.   importSprings("/data/fromRhino/springsInternal.txt");
    54.   importSprings("/data/fromRhino/springsExternal.txt");
    55.   meshList = importMesh("/data/fromRhino/mesh.txt");

    56.   BAttraction attr = new BAttraction(new Vec(0, 0, 200), 800, .1);
    57.   physicsDrive.addBehavior(attr);

    58.   sunflow = (P5SunflowAPIAPI) g;
    59.   sunflow.setWidth(sceneWidth); 
    60.   sunflow.setHeight(sceneHeight);
    61. }

    62. ////////////////////////////////////////////////////////////

    63. public void draw() {
    64.   background(225);
    65.   lights();
    66.   float x = cos(0.025*frameCount/10) * distance;
    67.   float y = -distance;
    68.   float z = sin(0.025*frameCount/10) * distance;
    69.   camera(x, y, z, -110, 0, 0, 0, 1, 0);
    70.   rotateX(PI/2);
    71.   fill(220);
    72.   ////////////////////////////////////////////////////////////
    73.   //update physics engine/ simulation
    74.   if (pause) {
    75.     physics.update();
    76.     physicsDrive.update();
    77.   }
    78.   ////////////////////////////////////////////////////////////
    79.   if (export == true) beginRaw(DXF, "/export/"+day()+hour()+minute()+"_#####.dxf");
    80.   ////////////////////////////////////////////////////////////
    81.   fill(220);
    82.   noStroke();
    83.   if (!showDelaunay) {
    84.     drawShapes();
    85.   } 
    86.   else {
    87.     drawNet();
    88.   }
    89.   ////////////////////////////////////////////////////////////
    90.   if (showNails) {
    91.     for (Nail n : nails) {
    92.       n.display();
    93.     }
    94.   }
    95.   ////////////////////////////////////////////////////////////
    96.   if (showAttrs) {
    97.     stroke(200, 50);
    98.     for (BAttraction a : attrs) {
    99.       strokeWeight(a.getRadius()*2);
    100.       Vec pos = a.getAttractor();
    101.       point(pos.x, pos.y, pos.z);
    102.     }
    103.   }
    104.   ////////////////////////////////////////////////////////////
    105.   if (showSprings) {
    106.     stroke(100);
    107.     strokeWeight(1);
    108.     for (VSpring s : physics.springs) {
    109.       line(s.a.x, s.a.y, s.a.z, s.b.x, s.b.y, s.b.z);
    110.     }
    111.   }

    112.   for (int i =0;i<movers.size();i++) {
    113.     Point m = (Point) movers.get(i);
    114.     VParticle nail = (VParticle) physicsDrive.particles.get(i);

    115.     Vec vel = m.getVelocity();
    116.     Vec newPos = nail.copy();
    117.     m.set(newPos);
    118.     m.setPreviousPosition(m.sub(0, 0, 250));
    119.     m.lock();
    120.   }
    121.   ////////////////////////////////////////////////////////////
    122.   if (showMovers) {
    123.     for (VParticle m : physicsDrive.particles) {
    124.       // strokeWeight(m.getRadius()*.5);
    125.       fill(0, 200, 0, 100);
    126.       //point(m.x, m.y, m.z);
    127.       ellipse(m.x, m.y, m.getRadius()*2, m.getRadius()*2);
    128.     }
    129.     strokeWeight(1);
    130.     for (VSpring s : physicsDrive.springs) {
    131.       line(s.a.x, s.a.y, s.a.z, s.b.x, s.b.y, s.b.z);
    132.     }
    133.   }

    134.   ////////////////////////////////////////////////////////////
    135.   if (export == true) {
    136.     endRaw();
    137.     export = false;
    138.     println("savedDXF: "+day()+hour()+minute()+"_#####.dxf");
    139.   }
    140.   fill(100);
    141.   fill(100);
    142.   beginShape();
    143.   vertex(-10000000, -10000000, -50);
    144.   vertex(10000000, -1000000, -50);
    145.   vertex(10000000, 10000000, -50);
    146.   vertex(-10000000, 10000000, -50);
    147.   endShape(CLOSE);
    148.   fill(220);
    149.   ////////////////////////////////////////////////////////////
    150.   //with this you can record every frame a pic and combine it later with tools/moviemaker
    151.   //saveFrame("pics01/pics01_#####.png");
    152.   if (frameCount%1==0) {
    153.     sunflow.setPathTracingGIEngine(16);
    154.     sunflow.render(false, sketchPath + "/"+frameCount+".png");
    155.   }
    156. }


    Hi,

    What I am trying to do  is to connect every grid0 particle with every grid1 particle.
    For now, I managed to connect only one particle from grid0 with grid1.
    Could you help me please?

    I think, I need to get into VParticleGrid class, function  "createGrid", in double for() loop in order to access particles from a grid.

    Current place of the connection:
    1. VParticleGrid grid0 = new VParticleGrid(physics, amountX, amountY, strength, a0, b0, c0, d0);
    2.   VParticleGrid grid1 = new VParticleGrid(physics, amountX, amountY, strength, a1, b1, c1, d1);

    3.   VParticle p0 = grid0.above;
    4.   VParticle p1 = grid1.above;

    5.   VSpring s = new VSpring(p0, p1, p0.sub(p1).mag(), strength/10);
    6.   physics.addSpring(s);
    Whole script:

    1. import peasy.PeasyCam;
    2. import punktiert.math.Vec;
    3. import punktiert.physics.*;


    4. // physics system for the mesh
    5. VPhysicsSimple physics;
    6. // physics for the constraints
    7. VPhysicsSimple physicsConstraints;

    8. PeasyCam cam;

    9. boolean pause = true;


    10. public void setup() {
    11.   size(1280, 720, P3D);

    12.   cam = new PeasyCam(this, 600);

    13.   physics = new VPhysicsSimple();
    14.   BConstantForce force = new BConstantForce(0, 0, .1f);
    15.   physics.addBehavior(force);

    16.   physicsConstraints = new VPhysicsSimple();
    17.   physicsConstraints.addBehavior(new BAttraction(new Vec(), 1000, .2f));

    18.   // create a mesh
    19.   float amountX = 5;
    20.   float amountY = 40;
    21.   float strength = 1f;



    22.   float offset = 1 * 50;

    23.   // lock all the Constraints (otherwise the springforce will alter the
    24.   // position
    25.   VParticle a0 = new VParticle(-width * .5f, -height * .5f-0, 0).lock();
    26.   VParticle b0 = new VParticle(width * .5f, -height * .5f-0, 0).lock();
    27.   VParticle c0 = new VParticle(width * .5f, height * .5f+0, 0).lock();
    28.   VParticle d0 = new VParticle(-width * .5f, height * .5f+0, 0).lock();

    29.   VParticle a1 = new VParticle(-width * .5f, -height * .5f-offset, offset).lock();
    30.   VParticle b1 = new VParticle(width * .5f, -height * .5f-offset, offset).lock();
    31.   VParticle c1 = new VParticle(width * .5f, height * .5f+offset, offset).lock();
    32.   VParticle d1 = new VParticle(-width * .5f, height * .5f+offset, offset).lock();

    33.   // add the Particles as Constraints to the mesh physics
    34.   physics.addConstraint(a0);
    35.   physics.addConstraint(b0);
    36.   physics.addConstraint(c0);
    37.   physics.addConstraint(d0);

    38.   physics.addConstraint(a1);
    39.   physics.addConstraint(b1);
    40.   physics.addConstraint(c1);
    41.   physics.addConstraint(d1);

    42.   //VParticleGrid(VPhysics physics, float amountX, float amountY, float strength, Vec a, Vec b, Vec c, Vec d) 
    43.   VParticleGrid grid0 = new VParticleGrid(physics, amountX, amountY, strength, a0, b0, c0, d0);
    44.   VParticleGrid grid1 = new VParticleGrid(physics, amountX, amountY, strength, a1, b1, c1, d1);

    45.   VParticle p0 = grid0.above;
    46.   VParticle p1 = grid1.above;

    47.   VSpring s = new VSpring(p0, p1, p0.sub(p1).mag(), strength/10);
    48.   physics.addSpring(s);
    49. }

    50. public void draw() {
    51.   background(240);

    52.   if (!pause) {
    53.     physics.update();
    54.     for (VParticle c : physicsConstraints.particles) {
    55.       c.unlock();
    56.     }
    57.     physicsConstraints.update();
    58.     for (VParticle c : physicsConstraints.particles) {
    59.       c.lock();
    60.     }
    61.   }

    62.   stroke(0, 0, 200);
    63.   noFill();
    64.   strokeWeight(4);
    65.   for (VParticle p : physics.constraints) {
    66.     //ellipse(p.x, p.y, p.radius*2, p.radius*2);
    67.     point(p.x, p.y, p.z);
    68.   }

    69.   stroke(100);
    70.   strokeWeight(1);
    71.   for (VSpring s : physics.springs) {
    72.  line(s.a.x,s.a.y,s.a.z,s.b.x,s.b.y,s.b.z);
    73.          
    74.   }
    75. }


    76. public void keyPressed() {
    77.   if (key == ' ')
    78.     pause = !pause;
    79. }
    80. class VParticleGrid {

    81.   VPhysicsSimple physics;

    82.   ArrayList<VParticle> particles;

    83.   Vec a, b, c, d;
    84. VParticle previous;
    85. VParticle above;
    86. VParticle p;

    87.   VParticleGrid(VPhysicsSimple physics, float amountX, float amountY, float strength, Vec a, Vec b, Vec c, Vec d) {

    88.     this.physics = physics;

    89.     this.a = a;
    90.     this.b = b;
    91.     this.c = c;
    92.     this.d = d;

    93.     particles = new ArrayList<VParticle>();

    94.     createGrid(amountX, amountY, strength);
    95.   }


    96.   void createGrid(float amountX, float amountY, float strength) {

    97.     for (int i = 0; i <= amountY; i++) {

    98.       Vec a0 = a.interpolateTo(d, i / amountY);
    99.       Vec b0 = b.interpolateTo(c, i / amountY);

    100.       for (int j = 0; j <= amountX; j++) {

    101.         Vec pos = a0.interpolateTo(b0, j / amountX);
    102.        p = null;
    103.         if (random(1) < .0f) { // movers
    104.           p = new VParticle(pos, 1, random(10, 30)).lock();
    105.           p.addBehavior(new BCollision());
    106.           physics.addConstraint(p);
    107.           physicsConstraints.addParticle(p);
    108.         } 
    109.         else {
    110.           p = physics.addParticle(new VParticle(pos));
    111.         }
    112.         particles.add(p);

    113.         if (j > 0) {
    114.            previous = physics.getParticle(particles.get(particles.size() - 2));
    115.           VSpring s = new VSpring(p, previous, p.sub(previous).mag(), strength);
    116.           physics.addSpring(s);
    117.         }
    118.         if (i > 0) {
    119.            above = physics.getParticle(particles.get(particles.size() - (int) amountX - 2));
    120.           VSpring s = new VSpring(p, above, p.sub(above).mag(), strength/10);
    121.           physics.addSpring(s);
    122.         }
    123.       }
    124.     }
    125.   }
    126. }
    Hi,

    Is it possible to have irregular shape boundary in toxiclibs + verletphysics?

    Now I have this line:

    1.  physics.setWorldBounds(new AABB(new Vec3D(300, 300, 600), new Vec3D(300, 300, 600)));

    But maybe there is a possibility no to have this kind rectangular boundary or cube.
    I would like to have polyline boundary (where each point is defined manually).

    May I have to use some sort of verlet particle string that would act in a similar way like a rectangle boundary?
    I do not actualy need a 3d boundary, but 2d polyline boundary would be ok for me.

    If it is some sort of verlet particle string, could you help me to write it?

    Thank you:)
    Hi,

    I am working with verletPhysics and toxi well known example - Shiffman_ForceDirectedGraph.
    In cluster class "showConnections" function springs and lines are drawn between particles.
    All possible springs and lines are drawn in this script.
    But for my reasons, I would like to have only one line and spring drawn from one particle.
    I tried to implement if statement, that says if distance is between smth and smth draw spring and connection.
    But by this if statement I get only interval where lines are drawn. For example, if there are particles that close to this valuse, there are drawn 1...3...5...8 springs and lines.

    If it at all possible, to say that one particle can have connection with only one particle?

    The script is possible to open from example files, but I will put it here too:

    1. import toxi.geom.*;
      import toxi.physics2d.*;
      import toxi.physics2d.behaviors.*;

      // Reference to physics world
      VerletPhysics2D physics;

      // A list of cluster objects
      ArrayList clusters;

      // Boolean that indicates whether we draw connections or not
      boolean showPhysics = true;
      boolean showParticles = true;

      // Font
      PFont f;

      void setup() {
        size(600,600);
        smooth();
        frameRate(30);
        f = createFont("Georgia",12,true);

        // Initialize the physics
        physics=new VerletPhysics2D();
        physics.setWorldBounds(new Rect(10,10,width-20,height-20));

        // Spawn a new random graph
        newGraph();

      }

      // Spawn a new random graph
      void newGraph() {

        // Clear physics
        physics.clear();

        // Create new ArrayList (clears old one)
        clusters = new ArrayList();

        // Create 8 random clusters
        for (int i = 0; i < 8; i++) {
          Vec2D center = new Vec2D(width/2,height/2);
          clusters.add(new Cluster((int) random(3,8),random(20,100),center));
        }

        //    All clusters connect to all clusters   
        for (int i = 0; i < clusters.size(); i++) {
          for (int j = i+1; j < clusters.size(); j++) {
            Cluster ci = (Cluster) clusters.get(i);
            Cluster cj = (Cluster) clusters.get(j);
            ci.connect(cj);
          }
        }

      }

      void draw() {

        // Update the physics world
        physics.update();

        background(255);

        // Display all points
        if (showParticles) {
          for (int i = 0; i < clusters.size(); i++) {
            Cluster c = (Cluster) clusters.get(i);
            c.display();
          }
        }

        // If we want to see the physics
        if (showPhysics) {
          for (int i = 0; i < clusters.size(); i++) {
            // Cluster internal connections
            Cluster ci = (Cluster) clusters.get(i);
            ci.showConnections();

            // Cluster connections to other clusters
            for (int j = i+1; j < clusters.size(); j++) {
              Cluster cj = (Cluster) clusters.get(j);
              ci.showConnections(cj);
            }
          }
        }

        // Instructions
        fill(0);
        textFont(f);
        text("'p' to display or hide particles\n'c' to display or hide connections\n'n' for new graph",10,20);
      }

      // Key press commands
      void keyPressed() {
        if (key == 'c') {
          showPhysics = !showPhysics;
          if (!showPhysics) showParticles = true;
        }
        else if (key == 'p') {
          showParticles = !showParticles;
          if (!showParticles) showPhysics = true;
        }
        else if (key == 'n') {
          newGraph();
        }
      }
    2. class Cluster {

        // A cluster is a grouping of nodes
        ArrayList nodes;

        float diameter;

        // We initialize a Cluster with a number of nodes, a diameter, and centerpoint
        Cluster(int n, float d, Vec2D center) {

          // Initialize the ArrayList
          nodes = new ArrayList();

          // Set the diameter
          diameter = d;

          // Create the nodes
          for (int i = 0; i < n; i++) {
            // We can't put them right on top of each other
            nodes.add(new Node(center.add(Vec2D.randomVector())));
          }

          // Connect all the nodes with a Spring
          for (int i = 1; i < nodes.size(); i++) {
            VerletParticle2D pi = (VerletParticle2D) nodes.get(i);
            for (int j = 0; j < i; j++) {
              VerletParticle2D pj = (VerletParticle2D) nodes.get(j);
              // A Spring needs two particles, a resting length, and a strength
              physics.addSpring(new VerletSpring2D(pi,pj,diameter,0.01));
            }
          }
        }

        void display() {
          // Show all the nodes
          for (int i = 0; i < nodes.size(); i++) {
            Node n = (Node) nodes.get(i);
            n.display();
          }
        }

        // This functons connects one cluster to another
        // Each point of one cluster connects to each point of the other cluster
        // The connection is a "VerletMinDistanceSpring"
        // A VerletMinDistanceSpring is a string which only enforces its rest length if the
        // current distance is less than its rest length. This is handy if you just want to
        // ensure objects are at least a certain distance from each other, but don't
        // care if it's bigger than the enforced minimum.
        void connect(Cluster other) {
          ArrayList otherNodes = other.getNodes();
          for (int i = 0; i < nodes.size(); i++) {
            VerletParticle2D pi = (VerletParticle2D) nodes.get(i);
            for (int j = 0; j < otherNodes.size(); j++) {
              VerletParticle2D pj = (VerletParticle2D) otherNodes.get(j);
              // Create the spring
              physics.addSpring(new VerletMinDistanceSpring2D(pi,pj,(diameter+other.diameter)*0.5,0.05));
            }
          }
        }


        // Draw all the internal connections
        void showConnections() {
          stroke(0,150);
          for (int i = 0; i < nodes.size(); i++) {
            VerletParticle2D pi = (VerletParticle2D) nodes.get(i);
            for (int j = i+1; j < nodes.size(); j++) {
              VerletParticle2D pj = (VerletParticle2D) nodes.get(j);
              line(pi.x,pi.y,pj.x,pj.y);
            }
          }
        }

        // Draw all the connections between this Cluster and another Cluster
        void showConnections(Cluster other) {
          stroke(0,50);
          ArrayList otherNodes = other.getNodes();
          for (int i = 0; i < nodes.size(); i++) {
            VerletParticle2D pi = (VerletParticle2D) nodes.get(i);
            for (int j = 0; j < otherNodes.size(); j++) {
              VerletParticle2D pj = (VerletParticle2D) otherNodes.get(j);
              line(pi.x,pi.y,pj.x,pj.y);
            }
          }
        }

        ArrayList getNodes() {
          return nodes;
        }
      }

    3. class Node extends VerletParticle2D {

        Node(Vec2D pos) {
          super(pos);
        }

        // All we're doing really is adding a display() function to a VerletParticle
        void display() {
          fill(0,150);
          stroke(0);
          ellipse(x,y,16,16);
        }
      }

    Hi,

    I have a strange problem. I am using "Sunflow" render and it renders files when geometry is not rotated with peasy cam.

    I added the script and all the files I am using. SKETCH FILES

    PLEASE HELP ME.

    Try to render geomtery when you open the script and other render when you rotate camera.
    To render you have to press "r".


    1. /*SunflowAPIAPI and OpenGL
      Press s to subdivide mesh, r to render through SunflowAPIAPI
      */
      import peasy.*;

      import processing.opengl.*;

      import toxi.geom.*;
      import toxi.geom.mesh.subdiv.*;
      import toxi.geom.mesh.*;
      import toxi.processing.*;

      import java.awt.Color;

      SunflowAPIAPI sunflow ;
      ToxiclibsSupport tox;
      PeasyCam cam;

      float[] vertices;
      int[] triangles;

      int rad=250;

      WETriangleMesh mesh;
      void setup() {
        size(700, 700, OPENGL);
        tox= new ToxiclibsSupport(this);
        cam= new PeasyCam(this, 500);

        buildMesh();
      }


      void draw() {
        background(255);
        fill(255);
        strokeWeight(0.5);
        stroke(0);
        lights();

        tox.mesh(mesh, true, 0);
      }

      void buildMesh() {
        mesh=new WETriangleMesh();
        toxi.geom.Sphere s;
        s=new toxi.geom.Sphere(rad);
        s.toMesh(mesh, 15);

      }

      void render() {   //converts the TriangleMesh to the arrays required by SunflowAPIAPI
        vertices = mesh.getUniqueVerticesAsArray();
        triangles = mesh.getFacesAsArray();
      }


      void keyPressed() {

        if(key=='s') {
          SubdivisionStrategy subdiv=new NormalDisplacementSubdivision(0.45f);
          mesh.subdivide(subdiv,10);
          println("done");
        }

        if(key=='r') {
          render();
          rayTrace();
        }
      }

      void rayTrace() {
        sunflow = new SunflowAPIAPI();
        sunflow.setWidth(width);
        sunflow.setHeight(height);

        sunflow.setPointLight("myPointLight", new Point3(0, 0, 0), new Color(255, 255, 255));

        float[] lookAt= cam.getLookAt();
        float[] pos=cam.getPosition();
        sunflow.setCameraTarget(lookAt[0], lookAt[1], lookAt[2]);
        sunflow.setCameraPosition(pos[0], pos[1], pos[2]);
        sunflow.setCameraUp(0, -1, 0);
        sunflow.setThinlensCamera("thinLensCamera", 50f, (float)width/height);

        sunflow.drawPlane("sky", new Point3(0,-rad*2,0), new Vector3(0,-1,0));
        sunflow.setAmbientOcclusionShader("occlusion", new Color(1f, 1f, 1f), new Color(0, 0, 0), 32, 500);
        sunflow.drawPlane("ground", new Point3(0,rad,0), new Vector3(0,1,0));

        sunflow.drawMesh("myMesh", vertices, triangles);

        sunflow.setPathTracingGIEngine(32);
        sunflow.render(false, sketchPath + "/"+frameCount+".png");
      }
    Hi,

    Is it possible to render processing sketch changing geometry with renderer that could at least give
    simple Global Ilumination effect like v-ray.

    Maybe I have somehow export changing geometry and put it to 3ds max or Maya?

    Is there a fast way to render geometry in a nice a way?

    I saw  octane render connected with processing.

    I really need a good advice from you how to render a sequence of changing geometry...

    Thank you in advance:)