<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with limit() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=limit%28%29</link>
      <pubDate>Sun, 08 Aug 2021 20:07:12 +0000</pubDate>
         <description>Tagged with limit() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedlimit%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Simple follow behaviour</title>
      <link>https://forum.processing.org/two/discussion/27087/simple-follow-behaviour</link>
      <pubDate>Fri, 23 Mar 2018 11:28:43 +0000</pubDate>
      <dc:creator>jbastow</dc:creator>
      <guid isPermaLink="false">27087@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to implement a simple follow behaviour where each object in the ArrayList follows the next object in the ArrayList. At the moment it seems like all the objects are following each other though? I'm assuming it's a problem with the loop but can't figure it out..</p>

<pre><code>ArrayList&lt;Mover&gt; movers;

void setup() {
  size(640, 360);
  movers = new ArrayList&lt;Mover&gt;();
  for (int i = 0; i &lt; 4; i++) {
    movers.add(new Mover());
  }
}

void draw() {
  background(255);

  for (int i = 0; i &lt; movers.size(); i++) {
    Mover m = movers.get(i);
    float alpha = i*85;

    m.follow(movers);
    m.update();
    m.display(alpha);
    m.boundary();
  }
}

class Mover {
  PVector location;
  PVector velocity;
  PVector acceleration;
  float mass;
  float radius;
  float maxspeed;
  float maxforce;
  float damping;

  Mover() {
    location = new PVector(random(width), random(height));
    velocity = new PVector();
    acceleration = new PVector();
    radius = 20;
    maxspeed = 2;
    maxforce = 0.3;
    damping = 0.98;
  }

  void follow(ArrayList&lt;Mover&gt; movers) {
    for (int i = 0; i &lt; movers.size()-1; i++) {
      Mover other = movers.get(i+1);
      PVector neighbour = PVector.sub(other.location, location);
      neighbour.setMag(maxspeed);
      PVector steer = PVector.sub(neighbour, velocity);
      steer.limit(maxforce);
      applyForce(steer);
    }
  }
  void applyForce(PVector force) {
    force.copy();
    acceleration.add(force);
  }

  void update() {
    velocity.add(acceleration);
    velocity.limit(maxspeed);
    velocity.mult(damping);
    location.add(velocity);
    acceleration.mult(0);
  }

  void display(float alpha) {
    fill(alpha);
    stroke(0);
    strokeWeight(1);
    ellipse(location.x, location.y, radius, radius);
  }

  void boundary() {
    if (location.x &lt; 0) { 
      location.x = width;
    }
    if (location.x &gt; width) { 
      location.x = 0;
    }  
    if (location.y &lt; 0) { 
      location.y = height;
    }
    if (location.y &gt; height) { 
      location.y = 0;
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to apply a repulsion force to a particle system ?</title>
      <link>https://forum.processing.org/two/discussion/26408/how-to-apply-a-repulsion-force-to-a-particle-system</link>
      <pubDate>Sat, 17 Feb 2018 19:34:05 +0000</pubDate>
      <dc:creator>solub</dc:creator>
      <guid isPermaLink="false">26408@/two/discussions</guid>
      <description><![CDATA[<p>Hi !</p>

<p>I've recently found <a rel="nofollow" href="https://medium.com/@zachlieberman/daily-sketches-2016-28586d8f008e">this article</a> from Zachary Lieberman where he provides some insights on his work. I'm particularly interested in his "recipe" to make a blob moving "organically" (almost like a fluid).</p>

<p><img src="https://cdn-images-1.medium.com/max/800/1*gapWpxJSlBSFiXVd-2RinQ.gif" alt="" /></p>

<p>This is a 2-step process:</p>

<blockquote class="Quote">
  <ul>
  <li>connect particles with springs (and connect the last particle to the first particle, making a loop)</li>
  <li>give the particles a repulsion force from each other that is proportional to distance (stronger force when closer) and has a maximum radius for interaction (i.e., if particles are beyond this distance, they don’t have an impact on each other)</li>
  </ul>
</blockquote>

<p>I made both a particle and a spring class but got lost when trying to implement the repulsion force. What should I change (add ?) in the following snippet (a spring class using basic Hooke's law) to "give the particles a repulsion force from each other that is proportional to distance" ?</p>

<p><strong>spring class</strong></p>

<pre><code>class Spring(object):

def __init__(self, x, y, l):
    self.startpoint = PVector(x, y)
    self.constant = .2
    self.lngth = l
    self.g = 10
    self.mass = 4

def connect(self, p):    # p refers to the particle_class
    force = PVector.sub(p.location, self.startpoint)
    distance = force.mag()
    stretch = distance - self.lngth

    force.normalize()
    force *= -1 * self.constant * stretch   # Hooke's law
    force.limit(.4) 
    p.applyForce(force) 


def displayLine(self, p):  
    stroke(255)
    strokeWeight(1)
    line(p.location.x, p.location.y, self.startpoint.x, self.startpoint.y) 
</code></pre>

<p>On a side note, I'm also curious to know how to display particles following a splatter shape (GIF above).</p>
]]></description>
   </item>
   <item>
      <title>How could I use a function from different class?</title>
      <link>https://forum.processing.org/two/discussion/25814/how-could-i-use-a-function-from-different-class</link>
      <pubDate>Thu, 04 Jan 2018 13:53:11 +0000</pubDate>
      <dc:creator>hsawa</dc:creator>
      <guid isPermaLink="false">25814@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I am quite new to Prcoessing and I am stuck on using functions from a class to another function. I basically want to use 'void update' in 'void oscEvent(OscMessage theOscMessage' to send update function to OSC. 
Hope my problem makes sense :(</p>

<p>here is the code:</p>

<pre><code>void draw() {
  background(0);
  for (Particle p : particles) {
    p.update();
  }
}

class Particle {

  PVector position, velocity;

  void update() {
    PVector mouse = new PVector(map(mouseX, 0, width, -width / 2, width / 2), map(mouseY, 0, height, -height / 2, height / 2), 0);
    PVector acc = PVector.sub(mouse, position);


    acc.limit(FULL_ACC);
    velocity.add(acc);
    velocity.limit(FULL_VEL);
    position.add(velocity);
  }

  void oscEvent(OscMessage theOscMessage) {
    if (theOscMessage.checkAddrPattern("/output_1")==true) {
      update(); //problem is here, what is the proper way in order for the OSC to pick up this info? 
      println("mouseMoved");
    } else if (theOscMessage.checkAddrPattern("/output_2")==true) {
      update();
      println("mouseMoved");
    } else if (theOscMessage.checkAddrPattern("/output_3") == true) {
      update();
      println("mouseMoved");
    } else {
      println("Unknown OSC message received");
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Limit MouseX &amp; MouseY Movement</title>
      <link>https://forum.processing.org/two/discussion/25486/limit-mousex-mousey-movement</link>
      <pubDate>Sun, 10 Dec 2017 04:33:13 +0000</pubDate>
      <dc:creator>jspanier925</dc:creator>
      <guid isPermaLink="false">25486@/two/discussions</guid>
      <description><![CDATA[<p>I was wondering what the best way to limit mouse movement, for example if I put mouseX and mouseY on these pupils</p>

<pre><code>ellipse(280,165,28,28); //Left Eye
ellipse(310,165,28,28); //Right Eye
fill(0);
ellipse(278,162,3,3);   //Left Pupil
ellipse(315,167,3,3);   //Right Pupil
</code></pre>

<p>how would I limit movement to within the eyes?</p>
]]></description>
   </item>
   <item>
      <title>How to preserve distance between 3d objects in order that they won't collide?!</title>
      <link>https://forum.processing.org/two/discussion/22999/how-to-preserve-distance-between-3d-objects-in-order-that-they-won-t-collide</link>
      <pubDate>Fri, 09 Jun 2017 14:18:08 +0000</pubDate>
      <dc:creator>lolonulu</dc:creator>
      <guid isPermaLink="false">22999@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I was wondering if someone could check this method based on shiffman's nature of code's one. In my sketch some spheres rotate in a 3d space and I try to force them to stay at a certain distance that they won't collide and stick together... Here is just the method below...Thanks a lot in advance ;))</p>

<pre><code>void separate (Sphere[]planets) {
    float desiredDist = radius*6;
    PVector sum = new PVector();
    int count = 0;
    if (planets != null) {
      if (level &gt; 0 ) {
        for (int i = 0; i &lt;planets.length; i++) {
          int j=1;
          for (j+=i; j&lt;planets.length; j++) {
            float d = PVector.dist(planets[i].location, planets[j].location);
            if ((d &gt;0) &amp;&amp; (d&lt;desiredDist)) {
              PVector diff = PVector.sub(planets[i].location, planets[j].location);
              diff.normalize();
              diff.div(d);
              sum.add(diff);
              count++;
            }

            if (count &gt; 0) {
              sum.div((float)count);
            }
            if (sum.mag() &gt; 0) {
              sum.setMag(maxSpeed);
              PVector steer = PVector.sub(sum, velocity);
              steer.limit(maxForce);
              applyForce(steer);
            }
          }
        }
      }
    }
  }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Move to target (PVector confusion)</title>
      <link>https://forum.processing.org/two/discussion/22696/move-to-target-pvector-confusion</link>
      <pubDate>Sun, 21 May 2017 09:22:55 +0000</pubDate>
      <dc:creator>freshfish</dc:creator>
      <guid isPermaLink="false">22696@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I am trying to wrap my brain around PVectors and using them to move objects. I simply wanted my circles to start in the center and move to a random location on the canvas. I get the movement part but not the target or the subtract functions.</p>

<pre><code>void update() {
target.sub(location);
target.normalize();
target.mult (.1);

velocity.add(acceleration);
velocity.limit(20);
location.add(velocity);
</code></pre>

<p>}</p>

<p>target is a PVector that contains a random x/y
the velocity add and the location add get the circle moving but I cannot get it to move to the target :(
Help thanks</p>
]]></description>
   </item>
   <item>
      <title>Need help getting object to leave trail</title>
      <link>https://forum.processing.org/two/discussion/19370/need-help-getting-object-to-leave-trail</link>
      <pubDate>Mon, 28 Nov 2016 21:04:07 +0000</pubDate>
      <dc:creator>MRoden1993</dc:creator>
      <guid isPermaLink="false">19370@/two/discussions</guid>
      <description><![CDATA[<p>I have a sketch where a Pacman character moves around the screen trying to eat cherries. I want Pacman to leave a trail of yellow dots as he moves and to then remove the dots when he comes back into contact with them. The problem at the moment though is that the dots are transmitted on Pacmans location and so he removes them before they show up on screen. I therefore need a way of transmitting the dots just behind Pacman instead. Any help would be much appreciated.</p>

<pre><code>    Pacman pacman = new Pacman(75); 

   void setup() {
  size(500, 500); //set the size of the page to 500pixels by 500pixels
  ellipseMode(CENTER); //set ellipse mode to center
  }

  void draw() {

  background(0); //set background to black
  pacman.update(); //use the function update() as written in class Pacman                               
  pacman.transmit(); //use the function transmit() as written in class Pacman 
  pacman.drawTrail(); //use the function drawTrail() as written in class Pacman
  pacman.collideTrail(); //use the function collideTrail() as written in class Pacman
  pacman.checkEdges();
  pacman.draw(); //use the function draw() as written in class Pacman
  }

  class Pacman {

  PVector location; 
  PVector velocity;                                                     
  PVector acceleration;                                                    
  PVector target; 
  float topspeed; 
  float tolerance = 15;      
  float direction = 0;

  float diameter; //declare diameter as float
  float MouthAngle = 0; //set MouthAngle to 0 (starting position closed)
  float OpeningAngle = PI * 2 / 180; 
  boolean MouthMovement = true; //set variable for MouthMovement
  ArrayList trail; // declare the use of trail as an Arraylist
  boolean MousePressed = false;


  Pacman(float dia) {

    diameter = dia;  
    trail = new ArrayList(); // assign trail as a function to create a new Arraylist
    location = new PVector(250,250);            
    velocity = new PVector(0, 0); 
    target = new PVector(width/2, height/2);                              
    topspeed = 3; //top speed is assigned a value of 3
  }

  void update() {


    PVector dir = PVector.sub(target, location);
    float distance = dist(location.x, location.y, target.x, target.y); 



    if (topspeed &gt; tolerance) {                                           
      topspeed *= 0.9;
    } else {
      topspeed = distance*0.05;
    }

    dir.normalize(); //normalize
    direction = dir.mag(); 
    acceleration = dir; // acceleration = direction                                               
    velocity.add(acceleration); 
    velocity.limit(topspeed);   //limit velocity to topspeed


    if (distance&lt;tolerance) { 
      target.x = random(width -100, width +100); 
      target.y = random(height -100, height +100);
    } else { //if the target hasn't been reached 
      location.add(velocity); //continue to move as normal

      if (mousePressed) {
        target.x = mouseX;
        target.y = mouseY;
      }
    }
  }

  void draw() {

    float dX = location.x - target.x; 
    float dY = location.y - target.y; 


    float angle = radians((atan2(dY, dX) * 180 / PI));


    if (dist(target.x, target.y, location.x, location.y) &gt; 0) {
      cherries();

      pushMatrix();
      translate(location.x, location.y);
      rotate(angle);
      if (MouthMovement == true) MouthAngle += OpeningAngle; 
      else MouthAngle -= OpeningAngle; 
      if (MouthAngle &gt; TWO_PI / 8 || MouthAngle &lt; 0) MouthMovement = ! MouthMovement;
      stroke(0);
      fill(255, 255, 0); // set fill to yellow
      arc(0, 0, diameter, diameter, HALF_PI*-2 + MouthAngle, HALF_PI*2 -MouthAngle); 
      fill (0); //set fill to black
      ellipse(0, 0 - diameter / 4, diameter/8, diameter/8);
      popMatrix();
    }
  }

  void checkEdges() {
    if (location.x  &gt; width -diameter/2 || location.x  &lt;0 +diameter/2 ) { 
      velocity.x *= -2; //its velocity is multiplied by -0.1
      target.x = random(width); 
      target.y = random(height);
    } 
    if (location.y +diameter/2&gt; height || location.y  &lt;0 +diameter/2 ) { 
      velocity.y *= -2; //its velocity is multiplied by -0.1
      target.x = random(width); 
      target.y = random(height);
    }
  }

  void transmit() {


    for (int i=0; i&lt;trail.size (); i++) { 
      if (trail.size() != 0) { 
        crumbs t = (crumbs) trail.get(i); 
        t.draw();
      }
    }
  }
  void drawTrail() {


    trail.add(new crumbs(new PVector(location.x, location.y), 10));
  }

  void collideTrail() {

    PVector crumbPos; 
    for (int i=0; i&lt;trail.size (); i++) {
      crumbs drop = (crumbs) trail.get(i);
      crumbPos = drop.loc;
      float d = location.dist(crumbPos); 
      if (d &lt; diameter/2) { //if Pacman is touching the crumbs                                
        trail.remove(i);
        // target.x = random(width); 
        //  target.y = random(height); 
        //velocity.x *= -2;
        //velocity.y *= -2;
      }
    }
  }


  void cherries() {
    stroke(0, 255, 0); //set stroke to green
    line (target.x -5, target.y+1, target.x-2.5, target.y-25); //draw line
    line (target.x +5, target.y-1, target.x-2.5, target.y-25); //draw line

    stroke(0);
    fill(255, 0, 0); //set fill to red
    ellipse(target.x-5, target.y-1, 15, 15); //draw ellipse 
    ellipse(target.x+5, target.y+1, 15, 15); //draw ellipse
   }
  }

   class crumbs { 

  PVector loc; //declare loc as a PVector 
  float diameter; //declare diameter as a float 



  crumbs(PVector loc_, float dia) {
    loc = loc_; 
    diameter=dia;
  }

  void draw () { 
    fill (255, 255, 0); 
    noStroke(); 

    ellipse(loc.x, loc.y, diameter, diameter);
    }
  }
</code></pre>
]]></description>
   </item>
   <item>
      <title>How do I make my 'spaceship' shoot projectiles?</title>
      <link>https://forum.processing.org/two/discussion/18867/how-do-i-make-my-spaceship-shoot-projectiles</link>
      <pubDate>Thu, 03 Nov 2016 17:09:18 +0000</pubDate>
      <dc:creator>junkpot</dc:creator>
      <guid isPermaLink="false">18867@/two/discussions</guid>
      <description><![CDATA[<p>I want to make a game about space battles and I need your help. 
Basically, all I need is a part of code, that makes my object shoot projectiles that fly for ~500 pixels when pressing spacebar. Here's the code.</p>

<pre lang="processing">
PVector location = new PVector (400,400);
PVector velocity = new PVector (0,0);
PVector acceleration = new PVector (0,0);
PVector mouse = new PVector (0,0);
float accelerationMax = 0.5;
int speedMax = 5;
int a = 40;
int b = 80;

void setup() {
size (800,800);
noCursor();
}
void draw() {
background (40);
fill(255,0,0);
ellipse(mouseX,mouseY,10,10);
line(mouseX,mouseY-15,mouseX,mouseY+15);
line(mouseX+15,mouseY,mouseX-15,mouseY);
mouse.set(mouseX, mouseY);
acceleration = PVector.sub(mouse,location);
acceleration.limit(accelerationMax);
location.add(velocity);
velocity.limit(speedMax);
velocity.add(acceleration);
if (mousePressed) {
accelerationMax = 0.01;
speedMax = 0;
}
else {
  accelerationMax = 0.5;
  speedMax = 5;
} 
pushMatrix();
rectMode(CENTER);
translate (location.x, location.y);
rotate (PI/2 + velocity.heading());
fill(0,0,0);
beginShape();
vertex(30,10);
vertex(45,35);
vertex(35,30);
vertex(38,40);
vertex(45,45);
vertex(15,45);
vertex(22,40);
vertex(25,30);
vertex(15,35);
endShape();
popMatrix();
}
</pre>
]]></description>
   </item>
   <item>
      <title>debugging (possibly PVector/ArrayList)</title>
      <link>https://forum.processing.org/two/discussion/17511/debugging-possibly-pvector-arraylist</link>
      <pubDate>Wed, 13 Jul 2016 09:03:28 +0000</pubDate>
      <dc:creator>AiSard</dc:creator>
      <guid isPermaLink="false">17511@/two/discussions</guid>
      <description><![CDATA[<p>This is a snippet of a server I'm writing that's supposed to interface with a robot, but have been bogged down by this bug..</p>

<p>The problem (probably?) revolves around getFinalVec() which checks if vecBuffer[] (an ArrayList of PVectors) isn't empty and is valid (not too close to a certain point). I also included computeNextVector() just in case as its called from within getFinalVec()</p>

<p>Assume RSol-RIst is basically (0,0,0)
As far as I understand it, vecBuffer[] is acting weirdly. When I checked nextDistance (which should be a PVector close to vecBuffer.get(0) ) I found it to alternate between the correct value and a wildly different one. So even though I input 18 PVectors in to vecBuffer[] I was seeing 36, but .size() was never greater than 18. The superflous PVector would trigger (nextDistance.mag() &lt; cullDistance) and so remove an element from vecBuffer every other pass until it was empty :(</p>

<p>I've only done the basics with ArrayLists and PVectors so I'm assuming that I've messed up in some really simple (but hopefully immediately recognizable) way with one of them that some one can see?</p>

<p>Thanks in advance.</p>

<pre><code>import java.util.*;
import hypermedia.net.*;
import controlP5.*;

ArrayList&lt;PVector&gt; vecBuffer = new ArrayList();

//...

void draw() {
  background(0);

  if (kukaBuffer!="") {
    kukaRef = splitTokens(kukaBuffer, "=");   //load kuka data
    extractVectors();                         //extract RIst/RSol
    getFinalVec();                            //defines finalVec and ensures valid input

    extractIPOC();
    sendtoKuka();
  }
}

void getFinalVec() {
  boolean check = false;
  while (check==false) {
    if (vecBuffer.size()==0) {
      finalVec = nullVec;
      check = true;      //get out of check, null vec
    } else {
      PVector nextDistance = PVector.sub(RSol, RIst);
      nextDistance.add(vecBuffer.get(0));
      println(nextDistance);
      println("{n="+vecBuffer.size());
      println(nextDistance.mag()&lt;cullDistance);
      if (nextDistance.mag() &lt; cullDistance) {
        vecBuffer.remove(0);
        println("removed!!");
        check = false;   //redo check
      } else {
        finalVec = computeNewVector();
        check = true;    //get out of check, new vec
      }
    }
  }
}

PVector computeNewVector() {
  //travel vector
  PVector nextDistance = PVector.sub(RSol, RIst);
  nextDistance.add(vecBuffer.get(0));
  //println("distance: "+nextDistance.mag());
  if (nextDistance.mag() &lt; slowLim) {
    println("reached point");
    prevVec = currVec;
    currVec = nullVec;
    vecBuffer.remove(0);
  }

  float prevScalar = prevVec.mag() - acc;
  if (prevScalar&lt;=0) {
    prevVec = nullVec;
  } else {
    prevVec.setMag(prevScalar);
  }

  float currScalar = currVec.mag() + acc;
  currVec = vecBuffer.get(0);
  if (currScalar &gt;= spd) {
    currVec.setMag(spd);
  } else {
    currVec.setMag(currScalar);
  }

  //println(vecBuffer.get(0));
  PVector newVec = PVector.add(currVec, prevVec);
  newVec.limit(spd);
  return newVec; //finalVec
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>PVector constructor, Recursive class</title>
      <link>https://forum.processing.org/two/discussion/15716/pvector-constructor-recursive-class</link>
      <pubDate>Sun, 27 Mar 2016 19:31:42 +0000</pubDate>
      <dc:creator>shanejcashman</dc:creator>
      <guid isPermaLink="false">15716@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to figure out how to set a PVector as an arguement for my Spawnball class, but "Spawnball(int d, PVector loc)"
gives an error. Also I'd like to add a spawn function that draws multiple ellipses on top of the original ball. I'd like to do this in a way that calls the class within itself, but I have no idea how to structure the code for that. Thanks!</p>

<pre><code>Spawnball sb = new Spawnball(50);
Spawnball sb2 = new Spawnball(30);
void setup() {
  size(850, 650);
  noCursor();
}

void draw() {
  background(0);
  sb.update();
  sb.display();
  noFill();
  stroke(200);
  ellipse(mouseX, mouseY, 8, 8);
}

class Spawnball {
  int dia;
  PVector loc;
  PVector vel;
  PVector acc;

  Spawnball(int d) {
    dia = d;
    loc = new PVector(0, 0);
    vel = new PVector(0, 0);
    acc = new PVector(0, 0);
  }

  void update() {
    PVector pos = new PVector(mouseX, mouseY);
    pos.sub(loc);
    pos.setMag(.1);
    acc = pos;
    vel.add(acc);
    loc.add(vel);
    acc.mult(0);
    vel.limit(3);
  }

  void display() {
    fill(10, 175, 3*dia);
    noStroke();
    ellipse(loc.x, loc.y, dia, dia);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Reducing the size of a vector</title>
      <link>https://forum.processing.org/two/discussion/13285/reducing-the-size-of-a-vector</link>
      <pubDate>Mon, 26 Oct 2015 18:32:29 +0000</pubDate>
      <dc:creator>CharlesDesign</dc:creator>
      <guid isPermaLink="false">13285@/two/discussions</guid>
      <description><![CDATA[<p>Hi there,</p>

<p>I've created a grid of eyes and I'm trying to get each pupil to follow the mouse without it coming out of the ellipse.
As I understand multiplying the vector by a factor of 0.5 would half the size of my line, unfortunately this is not the case.</p>

<p>Could anyone help me out?!</p>

<p>Thanks :)</p>

<p>Ps: Of course, if there's is a more efficient way of doing this please feel free to point it out.</p>

<pre><code>int nEyes = 20;
PVector[] eyes = new PVector[nEyes*5];
PVector[] mouse = new PVector[nEyes*5];

void setup() {
  size(600, 400);
  noFill();
  smooth();

  // Creating an array of points
  int i = 0;
  for (int x = 1; x &lt; nEyes; x++) {
    for (int y = 1; y &lt; nEyes; y++) {
      eyes[i] = new PVector((width/nEyes) * x, (height/nEyes) * y);
      y ++;
      i ++;
    }
    x ++;
  }
}

void draw() {

  background(255);

  for (int i = 0; i &lt; eyes.length; i++) {
    noFill();
    ellipse(eyes[i].x, eyes[i].y, 50, 25); // This is the eye

    mouse[i] = new PVector(mouseX, mouseY);

    //mouse[i].sub(eyes[i]); // These won't work
    //mouse[i].mult(0.1);
    //mouse[i].limit(20);


    fill(0);
    ellipse(mouse[i].x, mouse[i].y, 10, 10); // This is the pupil
    line(eyes[i].x, eyes[i].y, mouse[i].x, mouse[i].y);
  }
}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>