Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Control area padding with pbox2D

$
0
0

Hello guys,

I'm making an application for people with a certain level of difficulty, to be able to do color recognition ...

I'm adapting a template that uses the bibliocate pbox2D.

It would be the following idea: When there is the click on the button that corresponds to the correct one that is above, I add objects (particles), so as to fill a space.

Would you like to control a certain area (volume) with pbox2D?

Below is the figure to better illustrate the situation, I made the "illusion" of some bowls, where to complete the "challenge", needs to fill all of them ...

I'm not going to post the code (at least for now), because it got a bit extensive, I'm using add images, sounds, etc ... Below code snippet that does "bowls effect" with pbox2D.

//The Nature of Code - http://www.shiffman.net/teaching/nature

class Surface {
  ArrayList<Vec2> surface;

  Surface() {
    surface = new ArrayList<Vec2>();

    ChainShape chain = new ChainShape();

    float theta = 0;
    for (float x = width+10; x > -10; x -= 5) {
      float y = map(cos(theta),-1,1,300,height-70);
      theta += 0.10;
      surface.add(new Vec2(x,y));
    }

    Vec2[] vertices = new Vec2[surface.size()];
    for (int i = 0; i < vertices.length; i++) {
      Vec2 edge = box2d.coordPixelsToWorld(surface.get(i));
      vertices[i] = edge;
    }

    chain.createChain(vertices,vertices.length);

    BodyDef bd = new BodyDef();
    bd.position.set(0.0f,0.0f);
    Body body = box2d.createBody(bd);
    body.createFixture(chain,1);
  }

  void display() {
    strokeWeight(2);
    stroke(0);
    noFill();
    beginShape();
    for (Vec2 v: surface) {
      vertex(v.x,v.y);
    }
    endShape();

    //para dar o efeito de "pés" para a "taça"
    fill(0);
    rect(30,height-70, 10, 70);
    rect(343,height-70, 10, 70);
    rect(657,height-70, 10, 70);
    rect(970,height-70, 10, 70);
    rect(width-5,height-75, 10, 75);

    //Para provocar a "ilusão" da visão de uma taça
    fill(255);
    noStroke();
    rect(165,250, 50, 70);
    rect(479,250, 50, 70);
    rect(795,250, 50, 70);
    rect(1109,250, 50, 70);
    fill(0);
    ellipse(168,319,5,5);
    ellipse(214,319,5,5);
    ellipse(481,319,5,5);
    ellipse(529,319,5,5);
    ellipse(796,319,5,5);
    ellipse(842,319,5,5);
    ellipse(1110,319,5,5);
    ellipse(1157,319,5,5);
  }
}

TelaCores

Thanks for listening...


Viewing all articles
Browse latest Browse all 2896

Trending Articles