<?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 random2d() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=random2d%28%29</link>
      <pubDate>Sun, 08 Aug 2021 19:49:03 +0000</pubDate>
         <description>Tagged with random2d() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedrandom2d%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>2d Metaball sketch running super slow in Python mode</title>
      <link>https://forum.processing.org/two/discussion/27651/2d-metaball-sketch-running-super-slow-in-python-mode</link>
      <pubDate>Mon, 02 Apr 2018 20:27:28 +0000</pubDate>
      <dc:creator>solub</dc:creator>
      <guid isPermaLink="false">27651@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys,</p>

<p>I made several Python versions of 2d metaball sketches I found here on the forum or on the CodingTrain Github.</p>

<p>Problem: It runs super slow (&lt;1fps !) while all Java versions run very smoothly (60fps).</p>

<p>Questions:</p>

<ul>
<li><p>Why such a difference in the framerates ?</p></li>
<li><p>Is is possible to improve the Python code or am i for ever doomed for having chosen Python mode over Java mode ?</p></li>
</ul>

<p><strong>original JAVA code</strong></p>

<p>main tab:</p>

<pre><code>Blob[] blobs = new Blob[10];

void setup() {
  size(640, 360);
  colorMode(HSB);
  for (int i = 0; i &lt; blobs.length; i++) {
    blobs[i] = new Blob(random(width), random(height));
  }
}

void draw() {
  background(51);


  println(frameRate);

  loadPixels();
  for (int x = 0; x &lt; width; x++) {
    for (int y = 0; y &lt; height; y++) {
      int index = x + y * width;
      float sum = 0;
      for (Blob b : blobs) {
        float d = dist(x, y, b.pos.x, b.pos.y);
        sum += 10 * b.r / d;
      }
      pixels[index] = color(sum, 255, 255);
    }
  }

  updatePixels();

  for (Blob b : blobs) {
    b.update();
    //b.show();
  }
}
</code></pre>

<p>blob class</p>

<pre><code>class Blob {
  PVector pos;
  float r;
  PVector vel;

  Blob(float x, float y) {
    pos = new PVector(x, y);
    vel = PVector.random2D();
    vel.mult(random(2, 5));
    r = random(120, 400);
  }

  void update() {
    pos.add(vel); 
    if (pos.x &gt; width || pos.x &lt; 0) {
      vel.x *= -1;
    }
    if (pos.y &gt; height || pos.y &lt; 0) {
      vel.y *= -1;
    }
  }

  void show() {
    noFill();
    stroke(0);
    strokeWeight(4);
    ellipse(pos.x, pos.y, r*2, r*2);
  }
}
</code></pre>

<p><strong>PYTHON code</strong></p>

<pre><code>liste = []

def setup():
    size(640, 360, FX2D)
    colorMode(HSB)
    [liste.append(Blob(random(width), random(height))) for e in range(10)]

def draw():
    loadPixels()
    for x in range(width):
        for y in range(height):
            index = x + y * width
            sum = 0
            for e in liste:
                d = dist(x, y, e.pos.x, e.pos.y)
                try:
                    sum += 10 * e.r / d
                except ZeroDivisionError:
                    return 1
            pixels[index] = color(sum, 255, 255)
    updatePixels()

    for e in liste:
        e.update()

class Blob(object):
    def __init__(self, x, y):
        self.pos = PVector(x, y)
        self.velocity = PVector.random2D()
        self.velocity.mult(random(2, 5))
        self.r = random(120, 400)

    def update(self):
        self.pos.add(self.velocity)

        if self.pos.x &gt; width or self.pos.x &lt; 0:
            self.velocity.x *= -1
        if self.pos.y &gt; height or self.pos.y &lt; 0:
            self.velocity.y *= -1
</code></pre>
]]></description>
   </item>
   <item>
      <title>How could I make my Mitosis cells explode?</title>
      <link>https://forum.processing.org/two/discussion/22077/how-could-i-make-my-mitosis-cells-explode</link>
      <pubDate>Wed, 19 Apr 2017 09:51:03 +0000</pubDate>
      <dc:creator>JVE10</dc:creator>
      <guid isPermaLink="false">22077@/two/discussions</guid>
      <description><![CDATA[<p>I am working on creating a mitosis cell that can split using a function rather than having to click on it. I want to try and create a ball that is in the centre of the screen and will split out in a radial fashion.</p>

<p>This is my Cell function</p>

<p>function Cell(pos, r, c){</p>

<pre><code>if (pos) {
  this.pos = pos.copy();
} else {
  this.pos = createVector(700, 360, 700, 160);
}

this.r = r || 60;
this.c = c || color(random(100, 200), 0, random(100, 200), 100);

this.clicked = function(x, y) {
    var d = dist(this.pos.x, this.pos.y, x, y);
    if (d &lt; this.r) {
        return true;
    }   else {
        return false;
    }

}

this.mitosis = function() {
  this.pos.x += random(-10, 10);    
  var cell = new Cell(this.pos, this.r*0.8, this.c);
  return cell;
}

this.move = function () {
  var vel = p5.Vector.random2D();
  this.pos.add(vel);
}

this.show = function () {
    noStroke();
    fill(this.c);
    ellipse(this.pos.x, this.pos.y, this.r, this.r)
}
</code></pre>

<p>}</p>

<p>Any help would be really appreciated. Thank you</p>
]]></description>
   </item>
   <item>
      <title>beginShape()+ for loop + PVector running in Java but not in JavaScript mode.</title>
      <link>https://forum.processing.org/two/discussion/9504/beginshape-for-loop-pvector-running-in-java-but-not-in-javascript-mode</link>
      <pubDate>Thu, 19 Feb 2015 18:36:52 +0000</pubDate>
      <dc:creator>tande</dc:creator>
      <guid isPermaLink="false">9504@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I have this small piece of code that runs fine in processing java mode but not in java script mode. Can any one help me figure it out what is happening?</p>

<pre><code>PVector vertice[] = new PVector[6];
void setup() {
  size(200, 200);
  background(255);
}

void draw() {
}

void mouseClicked() {
  background(255);
  sorteiaPontos();
  desenhaCurvas();
}

void desenhaCurvas() {
  translate(width/2, height/2);
  noFill();

  beginShape();
  curveVertex(vertice[5].x, vertice[5].y);  
  for (int i=0; i&lt;6; i++) {
    curveVertex(vertice[i].x, vertice[i].y);
  }
  curveVertex(vertice[0].x, vertice[0].y);
  curveVertex(vertice[1].x, vertice[1].y);
  endShape();
}

void sorteiaPontos() {
  for (int i=0; i&lt;6; i++) {
    vertice[i]= PVector.random2D();
    vertice[i].mult(width/3);
  }
}
</code></pre>

<p>Thanks.</p>
]]></description>
   </item>
   </channel>
</rss>