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

**URL:** <https://discourse.processing.org/t/how-do-i-convert-processing-code-so-that-itd-work-on-leapmotion/10281>\
**Category:** Coding Questions\
**Created:** [April 15, 2019, 12:34am UTC](https://discourse.processing.org/t/how-do-i-convert-processing-code-so-that-itd-work-on-leapmotion/10281 "2019-04-15T00:34:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cesca](https://avatars.discourse-cdn.com/v4/letter/c/ee7513/32.png) [@cesca](https://discourse.processing.org/u/cesca)\
**Post date:** [April 15, 2019, 12:34am UTC](https://discourse.processing.org/t/how-do-i-convert-processing-code-so-that-itd-work-on-leapmotion/10281/1 "2019-04-15T00:34:29Z")

</div>

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

```auto
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();
  }
  }

```

---

<div class="post-metadata">

**Author:** ![zenemig](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/zenemig/32/4418_2.png) [@zenemig](https://discourse.processing.org/u/zenemig)\
**Post date:** [April 15, 2019, 2:31pm UTC](https://discourse.processing.org/t/how-do-i-convert-processing-code-so-that-itd-work-on-leapmotion/10281/2 "2019-04-15T14:31:05Z")

</div>

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:

> **[nok/leap-motion-processing](https://github.com/nok/leap-motion-processing)**
>
> Contributed library to use the Leap Motion in Processing. - nok/leap-motion-processing

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [April 15, 2019, 2:59pm UTC](https://discourse.processing.org/t/how-do-i-convert-processing-code-so-that-itd-work-on-leapmotion/10281/3 "2019-04-15T14:59:29Z")

</div>

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?
