Loading...
Logo
Processing Forum
nootropic.kint's Profile
29 Posts
63 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    Hi!

    I'm working on dynamic image masking with processing.js .
    In particular I'm using a triangle as a mask, and sometimes it is upward sometimes it is downward.
    Anyway, I'm storing a Triangle class with the coordinates in PVector so i can easily draw the mask in a PGraphics object.

    See the note at the end: this program in processing 1.5 IDE works without problem,with the correct masking, but in processing.js not working.
    I'm using processing.js v1.4.1

    Here is the code:

    1. PGraphics triangleMask;
    2. PImage _background;

    3. //------------------------------------------ Triangle
    4. class Triangle {
    5.   PVector a,b,c;
    6.   PVector aabb1, aabb2;

    7.   int x,y, id;

    8.   Triangle(int id, PVector a, PVector b, PVector c) {
    9.     this.id = id;
    10.     this.a = a;    this.b = b;    this.c = c;
    11.     computCentroid();
    12.     computeBoundingBox();
    13.   }

    14.   void computeBoundingBox() {
    15.       // ...
    16.   }

    17.   PVector computCentroid() {
    18.       // ....
    19.   }

    20.   void draw() {
    21.     
    22.     //--------------------------------------------------------------------------- CREATE MASK HERE
    23.     triangleMask = createGraphics(90, 90, JAVA2D); // I have tried also with P3D
    24.     triangleMask.beginDraw();
    25.     triangleMask.background(0);
    26.     
    27.     triangleMask.fill(255);
    28.     triangleMask.stroke(255);

    29.     triangleMask.beginShape();
    30.     triangleMask.vertex(a.x-aabb1.x, a.y-aabb1.y); //aabb1.x, aabb1.y, 
    31.     triangleMask.vertex(b.x-aabb1.x, b.y-aabb1.y);
    32.     triangleMask.vertex(c.x-aabb1.x, c.y-aabb1.y);
    33.     triangleMask.endShape(CLOSE);

    34.     triangleMask.endDraw();

    35.     PImage texture = createImage(90, 90, RGB);
    36.     texture.copy(
    37.       _background,
    38.       (int)aabb1.x, (int)aabb1.y, 90, 90, //aabb2.x, aabb2.y,
    39.       0,0, 90, 90);

    40.     //--------------------------------------------------------------------------- USE MASK HERE
    41.     texture.mask(triangleMask);    
    42.     image(texture, aabb1.x, aabb1.y);

    43.     noFill();
    44.     stroke(255,0,0);
    45.     beginShape();
    46.     vertex(a.x, a.y);
    47.     vertex(b.x, b.y);
    48.     vertex(c.x, c.y);
    49.     endShape(CLOSE);
    50.   }
    51. }
    NOTE: This code in Processing.org works as a charm. When i put it in an html page via processing the mask part is ignored: the part of _background copied is not a Triangle but a rectangle (the rect i copy without the mask).

    Hi!
    I've began to play with processin.js and I think it is quite nice for web, for me (and I play with processing from years) better then other 2d frameworks. I've tried to use it as java compiled into javscript and it is ok, and i've tried pure javascript, and it is a little bit verbose when you always has to call processing object (like _p.fill() instead of still fill()) but it is ok too.
    I'm a little bit attracted to plain javascript because I don't know the language very well and it could be challenging to learn.

    How do you use processing.js in production code?
    hi!
    I need some practical way to handle a drawing in both screen and some offscreen pgraphics with the same method.

    I have seen that the super cool P8gGraphicsSVG and the PDF exporter works nice with beginRecord/endRecord but not the normal PGraphics (that I need for showing the screenshot) with P2D.

    For now I have a dirty adapter class in which i have wrote some basic wrapper (i'm using only push/popMatrix, line, ellipse, transate, scale, fill and stroke). But I don't really like it.

    So i basically have something like this:

    1. Adapter a_screen = new Adapter(); 
    2. a_screen.setPApplet(this); // this is PApplet instance

    3. PGraphics offScreen = createGraphics(width, height, P2D);
    4. Adapter a_offScreen = new Adapter();
    5. screenshot.setPGraphics(offScreen);

    6. PGraphics pdf = createGraphics(width, height, PDF, "test.pdf");
    7. Adapter a_pdf = new Adapter();
    8. a_pdf.setPGraphics(pdf);

    9. drawImage(a_screen);
    10. drawImage(a_offScreen);
    11. drawImage(a_pdf);

    12. ...

    13. void drawImage(Adapter a) {
    14.     a.fill(...);
    15.     a.pushMatrix();
    16.     a.translate(...);
    17.     a.rect(...);
    18.     a.popMatrix();
    19. }
    but i'm having some problem (with translations and push/popmatrix i think) 
    EDIT: with P8gGraphicsSVG works perfectly



    I don't find some information about this so i thought to ask here..

    hi! i have just written this piece of code, mayebe here there is someone that can both optimize oder find this usefull

    1.     private Rect getBound(ArrayList<Vec2D> vertex2) {
    2. Comparator<Vec2D> x_order = new Comparator<Vec2D>() {
    3. @Override
    4. public int compare(Vec2D arg0, Vec2D arg1) {
    5. if (arg0.x() < arg1.x()) return 1;
    6. if (arg0.x() > arg1.x()) return -1;
    7. return 0;
    8. }
    9. };

    10. Comparator<Vec2D> y_order = new Comparator<Vec2D>() {
    11. @Override
    12. public int compare(Vec2D arg0, Vec2D arg1) {
    13. if (arg0.y() < arg1.y()) return 1;
    14. if (arg0.y() > arg1.y()) return -1;
    15. return 0;
    16. }
    17. };
    18. Collections.sort(vertex2, x_order);
    19. float maxx = vertex2.get(0).x;
    20. float minx = vertex2.get(vertex2.size()-1).x;
    21. Collections.sort(vertex2, y_order);
    22. float maxy = vertex2.get(0).y;
    23. float miny = vertex2.get(vertex2.size()-1).y;
    24. return new Rect(minx, miny, maxx-minx, maxy-miny);
    25. }
    hello, i'm doing a gui to reads some sensors from arduino, and i need a gui block for each sensor.
    the blocks are equal and so i can wrap them in a class.
    like this one:

    1. public class Sensor {
    2. private ControlP5 gui;
    3. private App parent; // App extends PApplet
    4. public Sensor(int id, App parent, ControlP5 gui) {
    5.     this.id = id;
    6.   this.gui = gui;
    7.     this.parent = parent;

    8.     gui.addNumberbox("min_in"+id);
    9. }

    10. public void set_min_in(float n) {
    11.    // bla bla
    12.  }
    13. }
    And in my App class (that extends PApplet) i have:
    1. public void min_in_0(float n) {sensors[0].set_min_in(n);}
    2. public void min_in_1(float n) {sensors[1].set_min_in(n);}
    3. public void min_in_2(float n) {sensors[2].set_min_in(n);}
    4. public void min_in_3(float n) {sensors[3].set_min_in(n);}
    that works but is not OOP at all...
    (and a little bit ugly..)

    i want something that as i click on the NumberBox of the sensor n.0 the callback call a function of the Sensor class instantiated in sensors[0] is called...

    i tried to play a little bit with "class Sensor implements CallbackListener" but i haven't find an easy and direct way to do that and.. what else?
    i've thought to make this with java reflection but i think it is a little bit  intricate for a similar project (it is only a gui for debug sensors and route messages from arduino to somewhere)..
    i've began to write this little project in processing.org just because it has to be small and easy/fast to write and processing.org is a great tool for fast prototype..

    some hints?
    hi, i'm just thinking about how to create a tile map with hemeshlib. now i'm using HEC_Box for creating single bricks. but if i try to smooth (with catmull clark for example) the whole obtained mesh i see that the bricks are separated. 

    i'm trying to join them in a close-unique mesh, but can't work it out.
    maybe removing duplicate vertex? with some kind of custom modifiers?

    i'm sure that there are thousand ways to do this with this supercool library.

    some help?
    here is the code:

    1. import processing.opengl.*;
    2. import wblut.geom.WB_Point;
    3. import wblut.hemesh.core.HE_Face;
    4. import wblut.hemesh.core.HE_Mesh;
    5. import wblut.hemesh.creators.HEC_Box;
    6. import wblut.hemesh.creators.HEC_Grid;
    7. import wblut.hemesh.subdividors.HES_CatmullClark;
    8. import wblut.processing.WB_Render;

    9. HE_Mesh mesh;
    10. WB_Render renderer;

    11. void setup() {

    12.   size(600, 600, P3D);
    13.   renderer = new WB_Render(this);

    14.   mesh = new HE_Mesh();
    15.   HEC_Grid creator = new HEC_Grid(3, 3, 10*3, 10*3);
    16.   HE_Mesh grid = creator.create();
    17.   mesh.add(grid);

    18.   float values[][] =                 // the height map
    19.   { 
    20.     { 1, 1, 1 } , 
    21.     { 1, 2, 1 } , 
    22.     { 1, 1, 1 }
    23.   };

    24.   HEC_Box cubeFactory = new HEC_Box().setWidth(10).setHeight(10);
    25.   Iterator<HE_Face> itr = grid.fItr();
    26.   for (int i = 0; i < 3; i++) {
    27.     for (int j = 0; j < 3; j++) {
    28.       float d = values[i][j] * 10;
    29.       cubeFactory.setDepth(d);
    30.       WB_Point p = itr.next().getFaceCenter();
    31.       p.z += d/2;
    32.       cubeFactory.setCenter(p);
    33.       mesh.add(cubeFactory.create());
    34.     }
    35.   }
    36.   
    37.   HES_CatmullClark catmull = new HES_CatmullClark()            // test if the bricks are joined in a unique mesh
    38.   .setKeepEdges(true)
    39.   .setKeepBoundary(true);
    40.   mesh.subdivide(catmull,1);
    41. }

    42. void draw() {

    43.   background(120);

    44.   lights();
    45.   translate(300, 300, 300);
    46.   rotateY(mouseX*1.0f/width*TWO_PI);
    47.   rotateX(mouseY*1.0f/height*TWO_PI);
    48.   fill(255);
    49.   noStroke();
    50.   renderer.drawFaces(mesh);
    51.   stroke(0);
    52.   renderer.drawEdges(mesh);
    53. }


    hi,
    i'm experiencing a weird problem. i've tried to isolate the code that produce the error and i didn't managed to so i'm going to post quite a lot of code.

    i think the problem is that i try to add controllersi (using the methods ControlP5.addToggle() in this example) during an event of the gui and this could bring to some errors in thread and some syncronizations fails..

    when i move the slider it should be add a toggle. it is added but with this run time error (silently catched by controlP5):

    java.util.ConcurrentModificationException
    at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
    at java.util.AbstractList$Itr.next(AbstractList.java:343)
    at controlP5.ControllerGroup.drawControllers(Unknown Source)
    at controlP5.ControllerGroup.draw(Unknown Source)
    at controlP5.ControlWindow.draw(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
    at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:662)

    commenting lines 55-60 the problem disappear.

    any ideas are appreciated!

    here is the the code:

    1. import controlP5.*;

    2. final int MAX_QUAD = 5;

    3. ControlP5 gui;

    4. int num_quad = 0;
    5. int earingLength = 300;

    6. int k = 0;

    7. ArrayList<Quad> quads = new ArrayList<Quad>();

    8. void setup() {
    9.   size(800, 600);
    10.   smooth(); 

    11.   gui = new ControlP5(this);

    12.   gui.addSlider("setNumQuad")
    13.     .setCaptionLabel("num quad")
    14.     .setPosition(10, 10)
    15.     .setSize(200, 20)
    16.     .setRange(0, MAX_QUAD)
    17.     .setNumberOfTickMarks(MAX_QUAD+1)
    18.     ;
    19. }

    20. void draw() {
    21.   background(100);

    22.   pushMatrix();
    23.   strokeWeight(3);
    24.   stroke(0);
    25.   noFill();
    26.   translate(width/2, height/2 - earingLength/2);

    27.   for (Quad q1 : quads) {
    28.     rect(-q1.edgeLength/2, q1.x, 
    29.          q1.edgeLength, q1.edgeLength);
    30.   }

    31.   popMatrix();
    32. }

    33. void setNumQuad(int n) {

    34.   //println("setNumQuad: "+n);
    35.   if (n==num_quad) {
    36.     // end recursion
    37.   } else if (n>num_quad) {
    38.     //println("add new quad");
    39.     k += 51;
    40.     quads.add(new Quad(k, 20));
    41.     Toggle t = gui.addToggle(""+num_quad)
    42.        .setCaptionLabel("")
    43.        .setPosition(10+num_quad*(200/MAX_QUAD), 40)
    44.        .setSize(10,10)
    45.        .setId(0);
    46.     ;
    47.     
    48.     num_quad++;
    49.     
    50.     setNumQuad(n);
    51.   } else if (n<num_quad) {
    52.     
    53.     k -= 51;
    54.     //println("remove "+n);
    55.     quads.remove(quads.size()-1);
    56.     num_quad--;
    57.     gui.remove(""+num_quad);
    58.        
    59.     setNumQuad(n);
    60.   }
    61.   //println(quads.size());
    62. }

    63. void controlEvent(ControlEvent theEvent) {

    64. }

    65. class Quad {
    66.   
    67.   float edgeLength;
    68.   float x;
    69.   
    70.   Quad(float x, float e) { 
    71.     this.edgeLength = e;
    72.     this.x = x;
    73.   } 
    74.  
    75.   float getDiagonal() {
    76.     return edgeLength; // foo
    77.   } 
    78.   
    79.   float getLastPoint() {
    80.     return x+edgeLength;
    81.   }
    82. }
    hi!
    i have generated some 3d polygons but now i want to cast them in a TriangleMesh to tap all capabilities of toxiclibs.
    how can i do?
    this is a little example:

    1. import toxi.geom.*;

    2. Vec3D pts[] = {
    3.   new Vec3D(1.0, 1.0, 1.0), new Vec3D(0.0, 0.618034, 1.618034), 
    4.   new Vec3D(1.0, 1.0, 1.0), new Vec3D(1.618034, 0.0, 0.618034), 
    5.   new Vec3D(1.0, 1.0, 1.0), new Vec3D(0.618034, 1.618034, 0.0), 
    6.   new Vec3D(1.0, 1.0, -1.0), new Vec3D(0.0, 0.618034, -1.618034), 
    7.   new Vec3D(1.0, 1.0, -1.0), new Vec3D(1.618034, 0.0, -0.618034), 
    8.   new Vec3D(1.0, 1.0, -1.0), new Vec3D(0.618034, 1.618034, 0.0), 
    9.   new Vec3D(1.0, -1.0, 1.0), new Vec3D(0.0, -0.618034, 1.618034), 
    10.   new Vec3D(1.0, -1.0, 1.0), new Vec3D(1.618034, 0.0, 0.618034), 
    11.   new Vec3D(1.0, -1.0, 1.0), new Vec3D(0.618034, -1.618034, 0.0), 
    12.   new Vec3D(1.0, -1.0, -1.0), new Vec3D(0.0, -0.618034, -1.618034), 
    13.   new Vec3D(1.0, -1.0, -1.0), new Vec3D(1.618034, 0.0, -0.618034), 
    14.   new Vec3D(1.0, -1.0, -1.0), new Vec3D(0.618034, -1.618034, 0.0), 
    15.   new Vec3D(-1.0, 1.0, 1.0), new Vec3D(0.0, 0.618034, 1.618034), 
    16.   new Vec3D(-1.0, 1.0, 1.0), new Vec3D(-1.618034, 0.0, 0.618034), 
    17.   new Vec3D(-1.0, 1.0, 1.0), new Vec3D(-0.618034, 1.618034, 0.0), 
    18.   new Vec3D(-1.0, 1.0, -1.0), new Vec3D(0.0, 0.618034, -1.618034), 
    19.   new Vec3D(-1.0, 1.0, -1.0), new Vec3D(-1.618034, 0.0, -0.618034), 
    20.   new Vec3D(-1.0, 1.0, -1.0), new Vec3D(-0.618034, 1.618034, 0.0), 
    21.   new Vec3D(-1.0, -1.0, 1.0), new Vec3D(0.0, -0.618034, 1.618034), 
    22.   new Vec3D(-1.0, -1.0, 1.0), new Vec3D(-1.618034, 0.0, 0.618034), 
    23.   new Vec3D(-1.0, -1.0, 1.0), new Vec3D(-0.618034, -1.618034, 0.0), 
    24.   new Vec3D(-1.0, -1.0, -1.0), new Vec3D(0.0, -0.618034, -1.618034), 
    25.   new Vec3D(-1.0, -1.0, -1.0), new Vec3D(-1.618034, 0.0, -0.618034), 
    26.   new Vec3D(-1.0, -1.0, -1.0), new Vec3D(-0.618034, -1.618034, 0.0), 
    27.   new Vec3D(0.0, 0.618034, 1.618034), new Vec3D(0.0, -0.618034, 1.618034), 
    28.   new Vec3D(0.0, 0.618034, -1.618034), new Vec3D(0.0, -0.618034, -1.618034), 
    29.   new Vec3D(1.618034, 0.0, 0.618034), new Vec3D(1.618034, 0.0, -0.618034), 
    30.   new Vec3D(-1.618034, 0.0, 0.618034), new Vec3D(-1.618034, 0.0, -0.618034), 
    31.   new Vec3D(0.618034, 1.618034, 0.0), new Vec3D(-0.618034, 1.618034, 0.0), 
    32.   new Vec3D(0.618034, -1.618034, 0.0), new Vec3D(-0.618034, -1.618034, 0.0),
    33. };

    34. void setup() {
    35.   size(400, 400, P3D);
    36. }

    37. void draw() {
    38.   background(255);
    39.   translate(width/2, height/2);
    40.   float rx = mouseY * 0.01f;
    41.   float ry = mouseX * 0.01f;
    42.   rotateX(rx);
    43.   rotateY(ry);

    44.   Vec3D v1, v2;

    45.   for (int i=0; i<pts.length-1; i+=2) {
    46.     v1 = pts[i];
    47.     v2 = pts[i+1];
    48.     line(v1.x*100, v1.y*100, v1.z*100, 
    49.     v2.x*100, v2.y*100, v2.z*100);
    50.   }
    51. }
    edit: mayebe is it possible with hemesh?
    hi
    i'm attempt to make an usual workflow for processing user: use some computational geometry library (in my case the supercool toxiclib) and then render with sunflow.
    i'm flirting with fractals in this period so my sketch is on koch3d fractal surface:

    i've done it with TriangleMesh toxic class and a KochSubdivideStrategy class that take 2 triangular faces (a quad), subdivide it in a 3x3 grid, extrude the center, and do it recursively. ok, it works.

    this is my result:


    now, each iteration i print out the number of vertices and this is what i get:

    140
    1726
    27968
    441867

    Exception in thread "Animation Thread" java.lang.OutOfMemoryError: Java heap space
    now.. i want to get only the structure - TriangleMesh object or List<Vec3D> - and not to render it (the render will be in sunflow and i don't care about how long it is and how much time it takes).

    i am almost totally empty of shading and gpu stuffs.. but..
    how can i get more resolution without java heap space exception?
    mayebe some gpu or shading stuff can help me?
    or what else?
    ok make fractals is a really heavy computations and it has exponential complexity but how can i achive some really really cool complex geometric mesh like this last piece (from  http://www.incendia.net/gallery/index.html)?


    after that i want to use some of subdividing strategy of the toxiclib core for deform a bit my koch3d so i need to ba back in java.. any ideas?
    hello i have an object (a mesh) and i want to orient it to be parallel to another terrain-mesh in a certain position (the position is a triangle).

    so, something like that:
    with given triangle in terrain,
    get R the rotation of this triangle
    rotate object of R.

    i don't know how to get R. I tried getting the triangle normal and obtain R computing the angles between the normal and axis. But i don't get the expected values.

    this code is a kind of unit test and i tried to keep it as easy as possible:
    1.             // get a complex terrain
    2.             TriangleMesh mesh = new TriangleMesh();
    3.             mesh.addFace(new Vec3D(0,0,0), new Vec3D(10,0,0), new Vec3D(10,10,0));
    4.             mesh.rotateX(PI/3);
    5.             mesh.rotateY(0);
    6.             mesh.rotateZ(0);
    7.       
    8.             // get the target position 
    9.             Face f = ((ArrayList<Face>)mesh.getFaces()).get(0);

    10.              // get the rotaion of this triangle
    11.             f.computeNormal();
    12.             Vec3D v = f.normal;
    13.             float angleX = (Vec3D.Axis.X.getVector().angleBetween(v));
    14.             float angleY = (Vec3D.Axis.Y.getVector().angleBetween(v));
    15.             float angleZ = (Vec3D.Axis.Z.getVector().angleBetween(v));

    16.             // EXPECTED VALUES: angleX=PI/3, angleY=0, angleZ=0
    17.             System.out.println(angleX);
    18.             System.out.println(angleY);
    19.             System.out.println(angleZ);
    hello,
    i'm writing here because i'm not sure where the problem is.

    i have just done a simple applet that save a pdf. i wrote it in eclipse.
    if i run inside eclipse everything is ok, and pdf is saved in /bin folder.
    then i have exported it as an applet using proclipsing
    in the end i signed the jar fil following the instructions on the wiki.

    no error is displayed, no pdf is saved.
    where can be the problem?

    hello, i'm trying to modify camera setting to make an object that change its dimension always in the center of the screen.
    my 3d object is dinamically changing its height and i want the camera to move far or near from it to make it always in the center.
    so if it is small.. my camera is near, if it is big the camera moves back.

    i'm using the formula:

    1. float distance = h / tan((fov)/2); 

    2. camera(width/2.0, height/2.0, distance, 
    3.          AABBcenter.x, AABBcenter.y, 0, 
    4.          0, 1, 0);



    where h is the height of the object, fov is the field of view (i used the standard one in processings.org, PI/3.0) and the gained distance is the distance the camera has to move along z-axis. the PVector AABBcenter object record the center of bounding box of my object.

    the formula is correct (i used it with panda3d render engine and it is ok), and the camera moves correctly and the object remains in the center.

    the problem is that the object seems to rotate!
    why??
    how can i avoid this?
    hi all

    i'm trying to implement this sketch by jared tarbell:  http://www.complexification.net/gallery/machines/boxFitting/
    but with different collision detection algorithm
     
    i've seen this collision tecniques in actionscript3:

    the key function is BitmapData.hitTest and i want to implement it in processing.. i've looked for some image subtraction in processing but without result and my implementation (nested for loop in x,y with PGraphics.get) is really too slow and my processing.org ide contue to crash..

    some advice?

    EDIT: i found the first error: i could check only perimeter not the whole rect!
    EDIT 2: the right code, it works mayebe it could be more optimezed!

    ps. this is my code:

    1. int stage = 600;
    2. int grow_limit = 50;

    3. PGraphics buffer = createGraphics(stage, stage, P2D); //createImage(stage, stage, ALPHA);

    4. ArrayList rects = new ArrayList();

    5. color bg = color(55,30,115);

    6. //------------------------------------------------------------------------------------- MAIN
    7. //------------------------------------------------------------------------------------- MAIN
    8. //------------------------------------------------------------------------------------- MAIN

    9. void setup() {

    10.   //size(*2stage, stage);
    11.   size(stage, stage);
    12.   background(bg);
    13.   smooth();

    14.   buffer.beginDraw();
    15.   buffer.background(0);
    16.   buffer.endDraw();

    17.   addRect();addRect();addRect();addRect();addRect();addRect();addRect();
    18. }


    19. void draw() {
    20.   
    21.   Rectangle r;

    22.   //println("rests: "+rects.size());

    23.   for (int i=0; i<rects.size(); i++) {
    24.     r = (Rectangle) rects.get(i);
    25.     boolean dead = r.grow();
    26.     if (dead) {
    27.       rects.remove(i);
    28.       addRect();
    29.     }
    30.   }
    31.   //image(buffer, stage, 0);
    32. }

    33. void addRect() {
    34.   int x = (int)random(stage);
    35.   int y = (int)random(stage);
    36.   addRect(x, y);
    37. }
    38. void addRect(int x, int y) {
    39.   //println("addRect "+rects.size());
    40.   rects.add(new Rectangle(x, y));
    41. }

    42. boolean hittest(Rectangle r) {
    43.   /** Return True if there is no collision. False otherways. **/

    44.   //println("hittest");

    45.   if (r.x+r.w > stage) return false;
    46.   if (r.y+r.h > stage) return false;

    47.   // check only the perimeter!!
    48.   int i=0, j=0;
    49.   j = r.y;

    50.   int flag = 0;

    51.   j = r.y -1;
    52.   for (i=r.x; i<(r.x+r.w); i++) flag += checkPixel(i, j);

    53.   j = r.y+r.h +1;
    54.   for (i=r.x; i<(r.x+r.w); i++) flag += checkPixel(i, j);

    55.   i = r.x -1;
    56.   for (j=r.y; j<(r.y+r.h); j++) flag += checkPixel(i, j);

    57.   i = r.x+r.w +1;
    58.   for (j=r.y; j<(r.y+r.h); j++) flag += checkPixel(i, j);

    59.   return flag==0;
    60. }

    61. int checkPixel(int i, int j) {
    62.   color black = color(0);
    63.   if ( buffer.get(i, j) == black) return 0;
    64.   else return 1;
    65. }

    66. //------------------------------------------------------------------------------------- RECTANGLE
    67. //------------------------------------------------------------------------------------- RECTANGLE
    68. //------------------------------------------------------------------------------------- RECTANGLE

    69. class Rectangle {
    70.   
    71.   int x, y, w, h;
    72.   boolean dead = false;
    73.   
    74.   float rotation = random(TWO_PI);
    75.   float delta = random(3,6);
    76.   
    77.   public Rectangle(int x, int y) {
    78.     println("Rectangle > .");
    79.     this.x = x;
    80.     this.y = y;
    81.     this.w = this.h = 2;
    82.   }

    83.   boolean grow() {
    84.     this.h+=1;
    85.     this.w+=1;

    86.     if ( hittest(this) ) {

    87.       if (h>grow_limit || w>grow_limit) dead = true;

    88.       this.draw();
    89.       buffer.beginDraw();
    90.       buffer.noStroke();
    91.       buffer.fill(100);
    92.       buffer.rect(x, y, w, h);
    93.       buffer.endDraw();
    94.     } 
    95.     else dead = true;
    96.     
    97.     return dead;
    98.   }
    99.   
    100.   void draw() {
    101.     
    102.     fill(bla);
    103.     stroke(blabla);
    104.     rect(x, y, w, h);
    105.   }
    106. }

    PS: ANY ADVICE OR ANY KIND OF CONSIDERATIONS ON THE CODE AND HOW TO DEBUG IT IS REALLY APPRECIATED
    hi guys
    i'm writing because i can't get the point.
    i am on ubuntu and i have processing 1.1, browsing web on chrome, but problem is present also in firefox

    on this page:
    i read: 

    OpenGL sketches run on the web starting with release 0113. (Bug 166)
     
    and i can easily visualize this page:

    i wrote a simple apps in processing.org using opengl renderer, but when export and open the applet there is only white page (in local, but uploading it on web with all consideration on this discussion  http://forum.processing.org/topic/implement-processing-applet-in-wordpress-com-blog it's the same).
    i've tried to sign applet (this care? i have no external resource) and google this problem but no solutions works for me.

    any suggestion is appreciated

    this is my applet:
    1. import processing.opengl.*;
    2. import javax.media.opengl.*;
    3. import peasy.*;

    4. PeasyCam cam;
    5. PFont font;
    6. VivianiCurve viviani;

    7. void setup() {
    8.   size(600,400, OPENGL);
    9.   //smooth();
    10.   
    11.   cam = new PeasyCam(this, 250);
    12.   font = loadFont("font.vlw");
    13.   textFont(font, 14);

    14.   viviani = new VivianiCurve(100);
    15. }

    16. void draw() {

    17.   background(230);  
    18.   noFill();
    19.   lights();

    20.   stroke(80);
    21.   fill(80);
    22.   cam.beginHUD();
    23.   text("Viviani's curve. move the mouse to change Frenet-frame position", 
    24.        20, 20);
    25.   cam.endHUD();

    26.   drawAxis();

    27.   stroke(80);
    28.   noFill();
    29.   drawCurve(viviani.getPoints());

    30.   drawFrenetFrame();
    31. }

    32. class Vec3D extends PVector { 

    33.   public Vec3D() {
    34.     super(0,0,0);  
    35.   }

    36.   public Vec3D(float x, float y, float z) {
    37.     super(x,y,z);
    38.   }

    39.   public Vec3D(PVector old) {
    40.     super(old.x, old.y, old.z);
    41.   }

    42.   public Vec3D cross(Vec3D p) {
    43.     Vec3D r = new Vec3D(super.cross(p));
    44.     return r;
    45.   }


    46.   public Vec3D normalized() {
    47.     float mag = (float) Math.sqrt(x * x + y * y + z * z);
    48.     if (mag > 0) {
    49.       mag = 1f / mag;
    50.       x *= mag;
    51.       y *= mag;
    52.       z *= mag;
    53.     }
    54.     return this;
    55.   }
    56.   
    57. }

    58. class VivianiCurve {

    59.   int curve_length = 100; // number of points that represent the curve
    60.   Vec3D points[];
    61.   float a = 50;

    62.   VivianiCurve(int l) {
    63.     curve_length = l;
    64.     points = new Vec3D[curve_length];
    65.     sample();
    66.   }

    67.   void sample() {
    68.     float theta = 0.1;
    69.     float p = 2.4;
    70.     float q = 1.6;
    71.     float dt = ((TWO_PI) / 100)*3;

    72.     for (int i=0; i<curve_length; i++) {
    73.       points[i] = sample(theta);
    74.       theta += dt; 
    75.     }
    76.   }
    77.   
    78.   float getPeriod()  {
    79.     return TWO_PI*3;
    80.   }

    81.   Vec3D sample(float theta) {
    82.     float x = a*(1+cos(theta));
    83.     float y = a*sin(theta);
    84.     float z = 2*a*sin( theta/2 );

    85.     return new Vec3D(x,y,z);
    86.   }

    87.   Vec3D[] getPoints() {
    88.     return points; 
    89.   } 

    90.   public Vec3D derivateI(float t) {
    91.     Vec3D r = new Vec3D();
    92.     r.x = - a * sin(t);
    93.     r.y =  cos(t);
    94.     r.z = a * cos( t/2 );
    95.     return r;
    96.   }

    97.   public Vec3D derivateII(float t) {
    98.     Vec3D r = new Vec3D();
    99.     r.x = cos(t);
    100.     r.y = - sin(t);
    101.     r.z = - sin( t/2 );
    102.     return r;
    103.   }

    104.   Vec3D getTangent(float t) {
    105.     Vec3D tangentVector = derivateI(t);
    106.     return tangentVector.normalized();
    107.   }

    108.   Vec3D getNormal(float t) {
    109.     return getBinormal(t).cross(getTangent(t)).normalized();
    110.   }

    111.   Vec3D getBinormal(float t) {
    112.     Vec3D derivataI = derivateI(t);
    113.     Vec3D derivataII = derivateII(t);
    114.     Vec3D binormalVector = derivataI.cross(derivataII);
    115.     return binormalVector.normalized();
    116.   }  
    117. }

    118. void drawFrenetFrame() {
    119.   float t = map(mouseX, 0, width, 0, viviani.getPeriod());
    120.   Vec3D point = viviani.sample(t);
    121.   
    122.   Vec3D temp = viviani.getTangent(t);
    123.   drawVector(point.x, point.y, point.z, point.x+temp.x*10, point.y+temp.y*10, point.z+temp.z*10);
    124.   
    125.   temp = viviani.getBinormal(t);
    126.   drawVector(point.x, point.y, point.z, point.x+temp.x*10, point.y+temp.y*10, point.z+temp.z*10);
    127.   
    128.   temp = viviani.getNormal(t);
    129.   drawVector(point.x, point.y, point.z, point.x+temp.x*10, point.y+temp.y*10, point.z+temp.z*10);
    130. }

    131. void drawAxis() {
    132.   stroke(150);
    133.   drawVector(0,0,0, 10, 0, 0);
    134.   stroke(150);
    135.   beginShape();
    136.   drawVector(0,0,0, 0, 10, 0);
    137.   endShape();  
    138.   stroke(150);
    139.   beginShape();
    140.   drawVector(0,0,0, 0, 0, 10);  
    141.   endShape();
    142. }

    143. void drawVector(float v1x, float v1y, float v1z,float v2x, float v2y, float v2z) {
    144.   beginShape();
    145.   vertex(v1x,v1y,v1z);
    146.   vertex(v2x,v2y,v2z);
    147.   endShape();
    148. }

    149. void drawCurve(Vec3D points[]) {
    150.   beginShape();
    151.   for(int i=0; i<points.length; i++) {
    152.     vertex(points[i].x, points[i].y, points[i].z);

    153.   }

    154.   endShape();
    155. }
    i don't understan why it is not a perfect circle!!

    1. float inner_radius = 80f, outer_radius = 160f;
    2. int numpoint = 30;

    3. void setup() {
    4.   size(500, 500); 
    5.   smooth();
    6. }

    7. void draw() {
    8.   background(0);
    9.   translate(width/2, height/2);

    10.   float  k = 6;
    11.   float c[], s[];
    12.   float theta=0, dt;


    13.   noFill();
    14.   stroke(200);

    15.   c = new float[numpoint];
    16.   s = new float[numpoint];

    17.   stroke(200);
    18.   noFill();
    19.   dt=TWO_PI/(k*(numpoint));

    20.   for(int spicchi=0; spicchi<k; spicchi++) {  

    21.     println( degrees(theta) );

    22.     for(int i=0; i<numpoint; i++) {  
    23.       c[i] = cos(theta);  
    24.       s[i] = sin(theta);

    25.       theta += dt;
    26.     }

    27.     beginShape();

    28.     for(int i=0; i<numpoint; i++) {  
    29.       vertex(c[i]*inner_radius, s[i]*inner_radius);
    30.     }
    31.     for(int i=numpoint-1; i>0; i--) {  
    32.       vertex(c[i]*outer_radius, s[i]*outer_radius);
    33.     }
    34.     vertex(c[0]*inner_radius, s[0]*inner_radius);
    35.     endShape();
    36.   }
    37.   println( degrees(theta) );
    38.   noLoop();
    39. }
    hi!
    i've been a nice prototype in processing with a bit of 3d surfaces and now i have to integrate all that code in a JOGL project and i'm not an opengl guy. i've played all night with glLight but i can't porting this ultra simple code:

    1. lights();
    2. fill(200);
    i get some abient light and some directional light but they are not so simle&nice as the processing sketch.

    some advice?
    i guys i've tried to implement a simple particle system
    i've got a Circle class with location, position and acceleration PVector

    and this method:
    1.   void gravity() {
    2.     for(int i=0; i<particles.length; i++) {
    3.       Circle body = particles[i];
    4.       
    5.       PVector attractor = new PVector(mouseX, mouseY);      //center of attraction
    6.       PVector between  = PVector.sub( attractor, body.location); //distance vector
    7.       float   distBetween = between.mag();  //distance value
    8.       if(distBetween>=60) { // ###
    9.          distBetween=60;
    10.       }
    11.       between.normalize(); // why?? because i have subtracted?
    12.       float force = (50 * body.radius ) / (distBetween*distBetween); // newton gravity formula
    13.       between.mult(force); // why not normilizing again?
    14.       body.velocity.add(between);
    15.     }
    16.   }
    i don't understand why to normalize, 
    and i'm gaining - dont know why - a "spring" linke movement:
    particles get mouseX and mouseY coordination but oltrepass it and come back in a circular way,
    and sometimes (there are ranodm initial velocity) orbit around it
    .. but i'm adding gravity vector on velocity, not accellaration (as in spring formula!)
    i thought that if gravity is too strong is bad, and so i put the if condition (###):
    no more absurde velocity but if i left particles goes on for minutes the never achive mouseX,mouseY..
    hi
    i found this library:

    it seems awesome!
    but.. not going now.
    i'm on processing 1.1
    and with java 1.5

    what can it be??
    by the way, that sunflow seems to be no more developed, last news is in 2008

    there are other ways to make render like that?
    it seems to be a wrapper for a supercool renderer engine..
    there are alternatives?

    1. java.lang.NoSuchMethodException: hipstersinc.P5Sunflow.<init>()
    2. at java.lang.Class.getConstructor0(Class.java:2678)
    3. at java.lang.Class.getConstructor(Class.java:1629)
    4. at processing.core.PApplet.makeGraphics(PApplet.java:1315)
    5. at processing.core.PApplet.size(PApplet.java:1142)
    6. at processing.core.PApplet.size(PApplet.java:1102)
    7. at sketch_nov30a.setup(sketch_nov30a.java:81)
    8. at processing.core.PApplet.handleDraw(PApplet.java:1571)
    9. at processing.core.PApplet.run(PApplet.java:1496)
    10. at java.lang.Thread.run(Thread.java:613)
    11. processing.app.debug.RunnerException: RuntimeException: hipstersinc.P5Sunflow needs to be updated for the current release of Processing.
    12. at processing.app.Sketch.placeException(Sketch.java:1565)
    13. at processing.app.debug.Runner.findException(Runner.java:568)
    14. at processing.app.debug.Runner.reportException(Runner.java:543)
    15. at processing.app.debug.Runner.exception(Runner.java:498)
    16. at processing.app.debug.EventThread.exceptionEvent(EventThread.java:367)
    17. at processing.app.debug.EventThread.handleEvent(EventThread.java:255)
    18. at processing.app.debug.EventThread.run(EventThread.java:89)
    19. Exception in thread "Animation Thread" java.lang.RuntimeException: hipstersinc.P5Sunflow needs to be updated for the current release of Processing.
    20. at processing.core.PApplet.makeGraphics(PApplet.java:1368)
    21. at processing.core.PApplet.size(PApplet.java:1142)
    22. at processing.core.PApplet.size(PApplet.java:1102)
    23. at sketch_nov30a.setup(sketch_nov30a.java:81)
    24. at processing.core.PApplet.handleDraw(PApplet.java:1571)
    25. at processing.core.PApplet.run(PApplet.java:1496)
    at java.lang.Thread.run(Thread.java:613)

    hi guys
    i was playing with a frind with some supersimple 2d graphics
    i'm on imac with mac os-x 10.5.8

    every time i run this sketched i get this error:

    Invalid memory access of location 0xb0fb6e8b eip=0x94ba7931

    this is the bad code,
    i'm not an hard coder but it doesn't look like a great memory waster

    1. int circle_radius = 5;
    2. int c = 255;

    3. float speed = 0, spring = 0.4, resistence = 0.08;
    4. float delta = 1;

    5. float rot = 0;

    6. void setup() {
    7.   size(800,800);
    8.   smooth();
    9. }

    10. void draw() {
    11.   background(0);

    12.   translate(width/2, height/2);
    13.   rotate(rot); 

    14.   float angle = 0;

    15.   float sin_angle = 0;
    16.   for (int i=600; i>0; i-=circle_radius) {
    17.     sin_angle = wave_function(angle);

    18.     fill(c);
    19.     c = switchColor(c);
    20.     ellipse(sin_angle,sin_angle, i, i);

    21.     angle += delta;
    22.   }

    23.   delta = spring(delta, 0);
    24.   rot+=0.08;
    25.   //delta = map(mouseX, 0, width, 0, 1);
    26. }

    27. float wave_function(float angle) {
    28.   return sin(angle)* 4;
    29.   //return noise(angle)*4;
    30. }

    31. float spring(float x, float target) {
    32.   speed += (target - x) * spring;
    33.   speed *= resistence;
    34.   x += speed;

    35.   println(x);
    36.   if(x<=0.01)x = 0;

    37.   return x;
    38. }

    39. int switchColor(int c) {
    40.   c = (c==255) ? (0) : (255);
    41.   return c;
    42. }

    43. void mousePressed() {
    44.   //spring = random(0.8);
    45.   //resistence = random(0.8);
    46.   delta = 1;

    47.   println(spring);
    48.   println(resistence);
    49. }
    hi
    i have two parallel rectangles (so no rotation) and i want to find all shapes formed by intersection.

    this is an example:

                        
    1. 1----------2
    2. | |
    3. | 5----9----6
    4. | | | |
    5. 3----10----4 |
    6. | |
    7. | |
    8. 7---------8


    first rectangle: 1,2,3,4
    second: 5,6,7,8
    intersection points: 9,10 (getted by brute force intersecting all segment of first rect with each other of second one.. there is a better way?)

    desired output:
    1,2,9,5,10,3
    5,9,10,4
    9,6,8,7,10,4

    i hope you understand, sorry for my bad english
    hi
    i want to flip horizzontally a PGraphcs object,
    in JAVA2D renderer
    1. scale(-1,0) 
    get this error:


    java[1011] <Error>: CGPointApplyInverseAffineTransform: singular matrix.
    what can i do?

    hi guys
    i'm rendering some wireframes objects and i want to apply a glow effects to it.

    like this: 

    what i've understand:
    render not in normal mode but inside a texture,
    copy my texture and blur the copy
    get another copy to get the bloom mask (i've not fully understand what this is)
    merge the 3 texture obtained to get final effect (with opengl blend mode i think)

    i'm looking for a good way to do this with no external library (like glgraphics or pixelnerve)