<?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 bind() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=bind%28%29</link>
      <pubDate>Sun, 08 Aug 2021 20:21:27 +0000</pubDate>
         <description>Tagged with bind() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedbind%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Animating with large datasets</title>
      <link>https://forum.processing.org/two/discussion/25225/animating-with-large-datasets</link>
      <pubDate>Mon, 27 Nov 2017 10:51:19 +0000</pubDate>
      <dc:creator>CPG</dc:creator>
      <guid isPermaLink="false">25225@/two/discussions</guid>
      <description><![CDATA[<p>Hi Everyone!</p>

<p>I have been working with P5 for a while now, but in my current project I'm working with large data sets for the first time.
The FPS I'm getting when animating over 2000+ data points is not good, is there a way to improve upon this?</p>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Instance mode over multiple files</title>
      <link>https://forum.processing.org/two/discussion/23580/instance-mode-over-multiple-files</link>
      <pubDate>Tue, 25 Jul 2017 17:44:00 +0000</pubDate>
      <dc:creator>ruairidh</dc:creator>
      <guid isPermaLink="false">23580@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I'm writing some sketches in p5 using instance mode. Some of them are getting pretty big, so I was wondering if there was any way to move some of the functionality into multiple files. My initial attempt was to move all the mouse event functions into another file, then import it into the main sketch file and call a function to register them:</p>

<p>test.js:</p>

<pre><code>import registerFunctions from './mouseHandler.js';
let sketch = function(p5) {

  var a = 5;

  p5.setup = function() {
    ...
    registerFunctions(p5);
  };

  p5.draw = function() {...};
};

let p5Sketch = new p5(sketch , 'canvas-holder');
</code></pre>

<p>mouseHandler.js:</p>

<pre><code>function _mousePressed() {
  console.log(a); // Obviously wont work
}

export default function registerInputFunctions(p5) {

    p5.mousePressed = _mousePressed;
}
</code></pre>

<p>My obvious issue is that I can't access the inner variables from test.js, so this method wont be very useful. So is there any way I can split the sketch into multiple files and somehow access the variables in the sketch from each of the other files?</p>

<p>Thanks in advance  :)&gt;-</p>
]]></description>
   </item>
   <item>
      <title>Creating array in function</title>
      <link>https://forum.processing.org/two/discussion/23153/creating-array-in-function</link>
      <pubDate>Tue, 20 Jun 2017 22:53:02 +0000</pubDate>
      <dc:creator>cameronnichols</dc:creator>
      <guid isPermaLink="false">23153@/two/discussions</guid>
      <description><![CDATA[<pre><code>`function Perceptron(n,lines){
  this.weights = new Array(lines);
  console.log(this.weights);
  for (var i = 0; i &lt; this.weights.length; i++){
    this.weights[i] = new Array(n);
  }
  this.lr = 0.002;
  for (var i = 0; i &lt; this.weights.length; i++){
    for (var j = 0; j &lt; this.weights[i].length; j++){
      this.weights[i][j] = random(-1,1);
    }
  }
  this.guesses = new Array(lines);
  for (var i = 0; i &lt; this.guesses.length; i++){
    this.guesses[i] = function(inputs){
      sum = 0;
      console.log(n+','+lines);
      console.log(this.weights.length);
      for (var j = 0; j &lt; this.weights[i].length; j++){
        sum += inputs[j]*this.weights[i][j];
      }
      return sign(sum);
    }
  }
}`
</code></pre>

<p>Here's my output: <a href="https://gyazo.com/318a9f2982f0a52efc735cfdb410caa2" target="_blank" rel="nofollow">https://gyazo.com/318a9f2982f0a52efc735cfdb410caa2</a></p>

<p>As you can see, I first define 'this.weights' as a new array, with length of 'lines' and yes, both arguments to the function are numbers.</p>

<p>But for some reason, I can log this.weights, and it says it's undefined, and I guess that's because all of the elements are undefined?</p>

<p>But it throws an error at line 85, which is simply <code>console.log(this.weights.length);</code></p>

<p>If I take that line out, then <code>for (var j = 0; j &lt; this.weights[i].length; j++){</code> throws an error, how can I fix this?</p>
]]></description>
   </item>
   <item>
      <title>CallBack function with parameters</title>
      <link>https://forum.processing.org/two/discussion/23013/callback-function-with-parameters</link>
      <pubDate>Sat, 10 Jun 2017 16:38:32 +0000</pubDate>
      <dc:creator>kfrajer</dc:creator>
      <guid isPermaLink="false">23013@/two/discussions</guid>
      <description><![CDATA[<p>This is what I have in my html:</p>

<p><code>&lt;p id="dz"&gt; Dropzone &lt;/p&gt;</code></p>

<p>and in my sketch.js I have this:</p>

<pre><code>function setup() {
  noCanvas();

  var dzPtr=select("#dz");
  dzPtr.dragOver(highlight);
  dzPtr.dragLeave(unhighlight);
}

function highlight(){
  this.style('background-color','#ccc');
}

function unhighlight(){
  this.style('background-color','#fff');
}
</code></pre>

<p>Question: Instead of having two function to work on the paragraph element, could I use one with parameters? How to implement something like this? I understand I will need a closure. Could somebody provide me an example?</p>

<p>Kf</p>
]]></description>
   </item>
   <item>
      <title>How to use button.moussePressed() in an Object ?</title>
      <link>https://forum.processing.org/two/discussion/18165/how-to-use-button-moussepressed-in-an-object</link>
      <pubDate>Tue, 13 Sep 2016 21:58:10 +0000</pubDate>
      <dc:creator>01ivier</dc:creator>
      <guid isPermaLink="false">18165@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I didn't succeed in creating a class in which a button from the DOM can call a local function with local variable.
For example, with this script...</p>

<pre><code>function setup() {
  myObject = new Test();
}


function Test() {

  this.something = 12345;
  this.button = createButton('Hello');

  this.test = function() {
    println(this.something);

  }

  this.button.mousePressed(this.test);
}
</code></pre>

<p>... <em>println</em> says that the argument is <em>undefined</em></p>

<p>If I put <code>println("123456");</code> in the test function, it works. 
But how can I do to use local variable ?</p>

<p>Thank you.</p>

<p>(I've tried with the "prototype way" without success.)</p>
]]></description>
   </item>
   <item>
      <title>How to transform an Array for the savefunction?</title>
      <link>https://forum.processing.org/two/discussion/17220/how-to-transform-an-array-for-the-savefunction</link>
      <pubDate>Sun, 19 Jun 2016 20:07:36 +0000</pubDate>
      <dc:creator>technik5</dc:creator>
      <guid isPermaLink="false">17220@/two/discussions</guid>
      <description><![CDATA[<p>Hello again,</p>

<p>Could someone explain how to transform an array full of different objects, that it can be saved to a .txt or .json-file?
To be more specific: I got an array that looks like the following</p>

<pre><code>[
  {
    "x": 517,
    "y": 206,
    "r": 20,
    "name": "Plant a Name",
    "countScaleRounds": 13,
    "maxScaleRounds": 100,
    "scaleFactor": 0.12
  },
  {
    "x": 387,
    "y": 261,
    "r": 20,
    "name": "Plant a Name",
    "countScaleRounds": 100,
    "maxScaleRounds": 100,
    "scaleFactor": 0.99
  },
  {
    "x": 256,
    "y": 360,
    "r": 20,
    "name": "Plant a Name",
    "countScaleRounds": 85,
    "maxScaleRounds": 100,
    "scaleFactor": 0.84
  },
  {
    "x": 226,
    "y": 433,
    "r": 20,
    "name": "Plant a Name",
    "countScaleRounds": 73,
    "maxScaleRounds": 100,
    "scaleFactor": 0.72
  }
]
</code></pre>

<p>and when save() is used, the result is a textfile with [object Object],[object Object],... but not the data from the array.
Now I'm hopping that some of the advanced programmasters can explain me what I'm missing out. Thx in advance.</p>

<p>the saving part in my script look like this:</p>

<pre><code>  function keyTyped() {
     if (key === 's' || key === 'S') {
     saveStrings(plants,"plants.txt");
     println(plants.txt);
     }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Issues with my anthill program</title>
      <link>https://forum.processing.org/two/discussion/8380/issues-with-my-anthill-program</link>
      <pubDate>Fri, 28 Nov 2014 05:28:12 +0000</pubDate>
      <dc:creator>ArnaudM</dc:creator>
      <guid isPermaLink="false">8380@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I'm trying to create an anthills program with some interactions between ants but I've already got some bad issues with this project. I've just done something to create anthills and to make ants move but... it's just creating one anthill and ants are motionless... Thank you !</p>

<p>Arnaud</p>

<pre><code>var fourmisParColonie,nombreDeFourmiliere;
var antsSystem = [];

function setup()
{   
    createCanvas(windowWidth,windowHeight);
    background(0);
    fourmisParColonie = 20;
    nombreDeFourmiliere = 4;

    for(i = 0; i &lt; nombreDeFourmiliere; i++)
    {
        antsSystem[i] = new Anthill(fourmisParColonie);
    }
}

function draw()
{
    for(i = 0; i &lt; nombreDeFourmiliere; i++)
    {
        antsSystem[i].displayAnthill();
    }
}

function Anthill(_fourmisParColonie)
{
    this.fourmisPC = _fourmisParColonie;
    this.antTab = [];
    this.fourmiliere = createVector(random(windowWidth),random(windowHeight));
    this.color = createVector(random(255),random(255),random(255));

    for(i = 0; i &lt; this.fourmisPC; i++)
    {
        this.antTab[i] = new Ant(this.fourmiliere);//création de chaque fourmi avec indication de la position de sa fourmilière
    }
}

Anthill.prototype.displayAnthill = function()
{
    background(0);

    for(i = 0; i &lt; this.fourmisPC; i++)
    {
        this.antTab[i].displayAnt(this.color);
    }
}

function Ant(_fourmiliere)
{
    this.lafourmilieredecetteAnt = createVector(_fourmiliere.x,_fourmiliere.y);
    this.positionAnt = createVector(this.lafourmilieredecetteAnt.x + random(-30,30),this.lafourmilieredecetteAnt.y + random(-30,30));//spawn fourmi autour de sa fourmilière
    this.destinationAnt = createVector(0,0);
    this.deltaDestinationAnt = createVector(0,0);
    this.timer1 = setInterval(this.definelookFor,random(200,5000));
    this.timer2 = setInterval(this.lookFor,20);
}

Ant.prototype.definelookFor = function() //nouvel objectif
{
    this.destinationAnt.x = random(-50,50);
    this.destinationAnt.y = random(-50,50);
    clearInterval(this.timer1);
    this.timer1 = setInterval(this.definelookFor,random(200,5000));
}

Ant.prototype.lookFor = function() //aller vers cet objectif
{
    this.vitesse = random(20);
    this.deltaDestinationAnt.x = this.destinationAnt.x*this.vitesse/2000;
    this.deltaDestinationAnt.y = this.destinationAnt.y*this.vitesse/2000;
    this.position.add(this.deltaDestinationAnt);
    clearInterval(this.timer2);
    this.timer2 = setInterval(this.lookFor,20);
}

Ant.prototype.displayAnt = function(_color)
{
    this.colorAnt = createVector(_color.x,_color.y,_color.z);
    fill(this.colorAnt.x,this.colorAnt.y,this.colorAnt.z);
    ellipse(this.positionAnt.x,this.positionAnt.y,10,10);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Problem with "this" scope while using OOP in p5.dom Element method</title>
      <link>https://forum.processing.org/two/discussion/8399/problem-with-this-scope-while-using-oop-in-p5-dom-element-method</link>
      <pubDate>Sun, 30 Nov 2014 11:55:17 +0000</pubDate>
      <dc:creator>jhonatanoliveira</dc:creator>
      <guid isPermaLink="false">8399@/two/discussions</guid>
      <description><![CDATA[<p>Hi there.</p>

<p>I am trying to modulate my code into objects, but I am having a problem with the <em>this</em> scope.
Inside the constructor of my <em>BackgroungTools</em> class I define some class' members, as shown below:</p>

<pre><code>BackgroundTools = function() {
        this.isBackgroundToolsOn = false

        this.backgroundButton = createButton('Background')
        this.backgroundButton.position(20,20)
        this.backgroundButton.mouseClicked(this.toggleBackgroundTools)

        this.backgroundSliderRed = createSlider(0,255)
        this.backgroundSliderRed.position(20,50)
        this.backgroundSliderRed.hide()
        console.log(this)
}

BackgroundTools.prototype.toggleBackgroundTools = function() {
    console.log(this)
    if (this.isBackgroundToolsOn) {
            this.backgroundSliderRed.hide()
            this.isBackgroundToolsOn = false
    } else {
            this.backgroundSliderRed.show()
            this.isBackgroundToolsOn = true
    }
}
</code></pre>

<p>Later, I then instantiate this class inside the <em>setup</em> function of p5:</p>

<pre><code>function setup() {
    canvas = createCanvas(800,600)
    background(0)
    backgroundTools = new BackgroundTools()
}

function draw() {
}
</code></pre>

<p>When <em>this</em> is printed in the Constructor we get what is expected (a pointer to the current object). But when I click in the button and the method <em>toggleBackgroundTools</em> is called, the <em>this</em> inside it isn't what we expect to be: it isn't a pointer to the current object, but it's something that prints in the console this: <code>[top: Window[0], window: Window[0], location: Location, external: Object, chrome: Object…]</code></p>

<p>I think that the method <em>mouseClicked</em> from p5.Element sort of change the scope of <em>this</em>. But I want to access the class' members in <em>toggleBackgroundTools</em> method.</p>

<p>Someone has went through this before?
Any ideas on how can I deal with this?</p>

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