How do I convert processing code so that it'd work on leapmotion?

I’m super new to processing and my prof is just as clueless as I am.

ArrayList<Flower> flowers;

void setup() {
  size(1080, 720);
  background(190,220,226);
  frameRate(30);
  flowers = new ArrayList<Flower>();
}
  //the mathematical formulas for the radius and parametric eq of the object were taken
  //from "Learning Processing" by Daniel Shiffman, and his youtube videos
void drawSpiral(float xc, float yc, float a) {
  pushMatrix();
  pushStyle();
  translate(xc, yc);   
  rotate(PI + a);
  noFill();
  beginShape();
  //this changes the size of the vine offshoot
  float maxt = random(10, 15);
  float maxr = random(20, 70);
  float sign = (random(1) < 0.5) ? -1 : +1;  
  float x0 = maxr * cos(sign);
  float y0 = maxr * sin(sign);
  for (float t = 1; t < maxt; t += 0.5) {
    float r = maxr/t;
    float x = r  * cos(sign * t) - x0; //this defines the x position to where the mouse is
    float y = r  * sin(sign * t) - y0; //this defines the y position to where the mouse is
    vertex(x, y);
  //this area changes the colour of the offshoot vines
  float red = Math.round((Math.random()*0+1));
  float green = Math.round((Math.random()*170+1));
  float blue = Math.round((Math.random()*0+1));
  stroke(red, green, blue);
  }
  endShape();
  noStroke();
  popStyle();
  popMatrix();
}

void draw() {
    line(pmouseX, pmouseY, mouseX, mouseY);
    strokeWeight(random(2, 7));
  //this area changes the colour of the line
  float r = Math.round((Math.random()*0+1));
  float g = Math.round((Math.random()*170+1));
  float b = Math.round((Math.random()*0+1));
  stroke(r, g, b);
    if (random(1) < 0.05) {
      
      PVector dir = new PVector(mouseX - pmouseX, mouseY - pmouseY);
      float a = dir.heading();
      drawSpiral(mouseX, mouseY, a);
    }
    ////
      if (mousePressed) {
    flowers.add(new Flower(mouseX, mouseY, 0, 40));
  }

  for (int i = 0; i < flowers.size(); i++) {
    Flower flower = flowers.get(i);
    flower.update();
    flower.present();
  }
}

class Flower
{
  float x, y, radius, radiusEnd;
  public Flower(float x, float y, float radiusStart, float radiusEnd) {
    this.x = x;
    this.y = y;
    this.radius = radiusStart;
    this.radiusEnd = radiusEnd;
  }

  void update() {
    radius = min(radius + 8, radiusEnd);
  }

  void present() {

    pushMatrix();
    translate(x, y);
    float r = Math.round((Math.random()*0+1));
    float g = Math.round((Math.random()*170+1));
    float b = Math.round((Math.random()*0+1));
    fill(255, 255, 255);
    //stroke(255, 255, 255, 200);

    beginShape();
    int n = 6; 
    for (int i = 0; i < n; i++) {
      float a = map(i, 0, n, 0, TWO_PI);
      float a1 = map(i + 1, 0, n, 0, TWO_PI);    
      float x1 = radius * cos(a);
      float y1 = radius * sin(a); 
      float x2 = radius * cos(a1);
      float y2 = radius * sin(a1);  
      vertex(0, 0);
      bezierVertex(x1, y1, x2, y2, 0, 0);
    }
    endShape();
    popMatrix();
  }
  }
1 Like

Hi @cesca,
What are you trying to archive with this code? Its important to give us context for understand your objetives and try to help you.

About the leapmotion thing, take a look at this:

1 Like

and regarding you code,
it is nice and runs here, and i like the idea.

but as @zenemig asked you already, your question is not understood.
-a- the leapmotion reference?

  • Processing version: 3.2.3

-b- convert ?from?to?