<?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 div() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=div%28%29</link>
      <pubDate>Sun, 08 Aug 2021 19:50:53 +0000</pubDate>
         <description>Tagged with div() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggeddiv%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Interactivity</title>
      <link>https://forum.processing.org/two/discussion/26411/interactivity</link>
      <pubDate>Sat, 17 Feb 2018 21:01:19 +0000</pubDate>
      <dc:creator>byurur</dc:creator>
      <guid isPermaLink="false">26411@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone</p>

<p>I need help to add interactivity to a work I've done, can you help me with this?</p>

<pre><code>class Particle {

  PVector location;
  PVector velocity;
  PVector acceleration;
  PVector force,friction;
  float mass,r,distance,loc;
  float maxForce, maxSpeed,strength;
  int id,val;
  color c;
  float k = 0.02;
  int age = 0;
  int spawnAge = (int)random(80,120);
  float minr = 0;
  float maxr = 5.0;
  boolean spawned = false;

  Particle(float x, float y,int _id) {
    mass = 0.1;
    id = _id;
    r = 0.1;
    maxSpeed = 1;
    maxForce = 10;
    location = new PVector(constrain(x,r,width-r), constrain(y,r,height-r));
    velocity = new PVector(0, 0);
    acceleration = new PVector(0, 0);
  }

  void applyForce(PVector force) {
    //PVector f = PVector.div(force, mass);
    acceleration.add(force);
  }

  void update() {
    velocity.add(acceleration);
    velocity.limit(maxSpeed);
    location.add(velocity);
    acceleration.mult(0);
    friction();
    borders();
    age+=1;
  }

  void friction(){
     friction = velocity.copy();
     friction.mult(-1);
     friction.normalize();
     friction.mult(k);

     applyForce(friction);
  }

  void display() {

    ellipse(location.x,location.y,r*2,r*2);
  }

  PVector attract(Particle p) {
    force = PVector.sub(p.location,location);
    distance = force.magSq(); 

      distance = constrain(distance, 1.0, 5000.0);
      force.normalize();

      strength = (g) / (distance*4*PI);
      force.mult(strength);n
      return force;


  }

  void setRadius (PImage img){

      loc = (int)location.x + (int)location.y*img.width;
      //c= img.get((int)location.x,(int)location.y);
      //c =  img.pixels[int(loc)];
      val = img.pixels[int(loc)] &amp; 0xFF;
      r=  lerp(r,map(val,0.0,255.0,minr,maxr),0.01);

  }

  void borders() {
      if ( location.x &lt; r || location.x &gt; width-r){
          velocity.x = -velocity.x;
      }
      if ( location.y &lt; r || location.y &gt; height-r){
          velocity.y = -velocity.y;
      }

      if (location.x&gt; width-r) location.x = width-r;
      if (location.x&lt; r) location.x = r;
      if (location.y&gt; height-r) location.y = height-r;
      if (location.y&lt; r) location.y = r;

  }

}
</code></pre>
]]></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>Multiplying vectors</title>
      <link>https://forum.processing.org/two/discussion/18585/multiplying-vectors</link>
      <pubDate>Sun, 16 Oct 2016 21:37:04 +0000</pubDate>
      <dc:creator>willemkempers</dc:creator>
      <guid isPermaLink="false">18585@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>Everytime I want to do multiplications on PVectors I get frustrated as PVector.mult(PVector) doesn't exist. I've seen one or two threads on the forums about this, so I know that it apparently doesn't make much sense. Can someone point me to the correct way of multiplying a normalised position PVector with a pixel space PVector?</p>

<p>Say I have this:</p>

<p><code>PVector pixelSpaceSize = new PVector(400, 300);
PVector normalizedPosition = new PVector(0.8, 0.2);</code></p>

<p>And I want to get the pixel space position of my normalised position? Ideally I'd do...</p>

<p><code>PVector pixelPosition = PVector.mult(pixelSpaceSize, normalizedPosition);</code></p>

<p>Right? But instead I now have to multiply the individual fields:</p>

<p><code>PVector pixelPosition = PVector.mult(pixelSpaceSize.x * normalizedPosition.x, pixelSpaceSize.y * normalizedPosition.y, pixelSpaceSize.z * normalizedPosition.z);</code></p>

<p>I'm sure there's a very good reason why this is not-done, but how should I approach this? Stick to the incredibly long x * x, y * y and z * z or is there some other method?</p>

<p>Many thanks</p>
]]></description>
   </item>
   <item>
      <title>Dividing vectors</title>
      <link>https://forum.processing.org/two/discussion/17254/dividing-vectors</link>
      <pubDate>Tue, 21 Jun 2016 17:12:48 +0000</pubDate>
      <dc:creator>marciokoko</dc:creator>
      <guid isPermaLink="false">17254@/two/discussions</guid>
      <description><![CDATA[<p>I understand vector.div(2)</p>

<p>But what does div(2) do?</p>
]]></description>
   </item>
   </channel>
</rss>