<?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 #functions - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%23functions</link>
      <pubDate>Sun, 08 Aug 2021 21:15:22 +0000</pubDate>
         <description>Tagged with #functions - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23functions/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Return values through a function's parameter</title>
      <link>https://forum.processing.org/two/discussion/21895/return-values-through-a-function-s-parameter</link>
      <pubDate>Sat, 08 Apr 2017 17:35:47 +0000</pubDate>
      <dc:creator>157239n</dc:creator>
      <guid isPermaLink="false">21895@/two/discussions</guid>
      <description><![CDATA[<p>In Pascal, i heard about something like this:</p>

<pre><code>program abc;
var x,y:integer;
procedure something(a,b:integer);
var c:integer;
begin
  c:=a;
  a:=b;
  b:=a
end;
begin
  a:=3;
  b:=5;
  {now a=3, b=5}
  swap(a,b);
  {now a=3, b=5}
end.
</code></pre>

<p>but if you were to add "var" before the parameters:</p>

<pre><code>program abc;
var x,y:integer;
procedure something(var a,b:integer);
var c:integer;
begin
  c:=a;
  a:=b;
  b:=a
end;
begin
  a:=3;
  b:=5;
  {now a=3, b=5}
  swap(a,b);
  {now a=5, b=3}
end.
</code></pre>

<p>I wonder how can i achieve the same result? I also wonder what this problem is called.</p>

<p>Thanks in advanced for helping me.</p>
]]></description>
   </item>
   <item>
      <title>How to use the current coordinates of an object outside its display function</title>
      <link>https://forum.processing.org/two/discussion/19662/how-to-use-the-current-coordinates-of-an-object-outside-its-display-function</link>
      <pubDate>Sun, 11 Dec 2016 15:08:18 +0000</pubDate>
      <dc:creator>rickymarto</dc:creator>
      <guid isPermaLink="false">19662@/two/discussions</guid>
      <description><![CDATA[<p>Hello everybody,</p>

<p>I want to drew a graphical interface to control the parameters of few oscillators that I'm going to build through the Minim library. I created a class which consists of a circle with three other little circles inside and this object rotates around itself. (let's say a wheel with three points on it). With the <em>display()</em> function inside the class I drew in <em>draw()</em> three of these wheels.</p>

<p>Now, what I want to do is to get the current position on the screen of the smaller rotating circles of each wheel, in order to calculate the distance between each one of them and the other small circles of the other wheels. The aim is to map each value of the distance with a parameter of my oscillators.</p>

<p>If I calculate the distance in the <em>void display()</em> I cannot use it outside this function and I cannot do it  in draw() for example, because the coordinates of the points are valid only in display().</p>

<p>How can I get and use the current position od each small circle?</p>

<pre><code>Wheel wheelA;
Wheel wheelB;
Wheel wheelC;


void setup() {
  size(800, 800);  

  wheelA = new Wheel();
  wheelB = new Wheel();
  wheelC = new Wheel();
}

void draw() {
  background(255);

  pushMatrix();
  wheelA.display(180, 180, 0.02); 
  popMatrix();

  pushMatrix();
  wheelB.display(620, 180, 0.03); 
  popMatrix();

  pushMatrix();
  wheelC.display(400, 620, 0.01);  
  popMatrix();
}

class Wheel { 
  float posX;
  float posY;
  float ang= 0;
  float aVel;

  float xA;
  float yA;
  float xB;
  float yB;
  float xC;
  float yC;

  // The constructor defined
  Wheel() {
  }

  void  display(float posX, float posY, float aVel) {
    xA = 0;
    yA = 80;
    xB= 55;
    yB = -55;
    xC = -55;    
    yC = -55;


    //Wheel - big circle
    stroke(0);
    strokeWeight(3);
    fill(255);
    ellipseMode(CENTER);
    translate(posX, posY);  
    rotate(ang);
    ellipse(0, 0, 200, 200);

    //small circles
    ellipse(xA, yA, 10, 10);
    ellipse(xB, yB, 10, 10);
    ellipse(xC, yC, 10, 10);

    ang=ang+aVel;

  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>ArrayList of function calls</title>
      <link>https://forum.processing.org/two/discussion/19316/arraylist-of-function-calls</link>
      <pubDate>Sat, 26 Nov 2016 19:01:08 +0000</pubDate>
      <dc:creator>kfrajer</dc:creator>
      <guid isPermaLink="false">19316@/two/discussions</guid>
      <description><![CDATA[<p>Is it possible to create an ArrayList of function calls? For example, I have</p>

<pre><code>void step0(){}
void step1(){}
void step2(){}
(...)
void stepN(){}
</code></pre>

<p>Then to create an</p>

<pre><code>ArrayList&lt;void&gt; myFxn = new ArrayList&lt;void&gt;();
myFxn.add(step0);
myFxn.add(step1);
myFxn.add(step2);
myFxn.add(stepN);
</code></pre>

<p>Then finally</p>

<pre><code>void keyPressed(){
  if(key&gt;='a' &amp;&amp; key&lt;='z')
     myFxn.get(key-'a');
}
</code></pre>

<p>The ArrayList has a list of functions I could access in an ordered manner. Just curious if this is something that can be implemented with current tools.</p>

<p>Kf</p>
]]></description>
   </item>
   <item>
      <title>Function expressions</title>
      <link>https://forum.processing.org/two/discussion/17424/function-expressions</link>
      <pubDate>Tue, 05 Jul 2016 21:16:22 +0000</pubDate>
      <dc:creator>PeteAJ</dc:creator>
      <guid isPermaLink="false">17424@/two/discussions</guid>
      <description><![CDATA[<p>I've been reading about function expressions in Javascript. Like <code>var greet = function greet(name, timeOfDay) {
return “Good “ + timeOfDay + “ “ + name + “!”;
}</code></p>

<p>Is it possible to do something like this in Processing? The way I am inclined to try this is setting the function to float and creating a variable to reference it in the body of my program. Just curious if anyone dealt with this much.</p>
]]></description>
   </item>
   <item>
      <title>Object's properties.</title>
      <link>https://forum.processing.org/two/discussion/17389/object-s-properties</link>
      <pubDate>Sat, 02 Jul 2016 15:51:18 +0000</pubDate>
      <dc:creator>irving</dc:creator>
      <guid isPermaLink="false">17389@/two/discussions</guid>
      <description><![CDATA[<p>Hello,
Where or how can I access the properties (methods) that can be passed to an object? For example, if I want to know which properties I can pass to the ellipse() object, where can I find this information? I am having a hard time finding out how to talk to my objects.</p>

<p>At the moment I am using console.dir(Object.keys(ellipse())); but what I cannot really make sense of what it is returning.</p>

<p>Any help is welcome. Apologies if the question has been asked before, I could not find the answer in the forum.</p>

<p>Thanks!
Irving.</p>
]]></description>
   </item>
   <item>
      <title>Best method for storing and calling function as variable?</title>
      <link>https://forum.processing.org/two/discussion/14676/best-method-for-storing-and-calling-function-as-variable</link>
      <pubDate>Sat, 30 Jan 2016 02:31:30 +0000</pubDate>
      <dc:creator>CantSayIHave</dc:creator>
      <guid isPermaLink="false">14676@/two/discussions</guid>
      <description><![CDATA[<p>I just created a Button class for my current project, and I'd like a way to assign a function to each button created.</p>

<p>It would be most useful to store the function as a variable upon calling the constructor and later call that function when a click is detected inside the Button. After searching the forums I see it's rather difficult to do this, and it's also a bad idea to store the function name as a String and use that to call it.</p>

<p>I'd like to avoid hard coding the functions for each button into a clickHandler function. Do you guys have suggestions on what to do?</p>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>Audio</title>
      <link>https://forum.processing.org/two/discussion/12398/audio</link>
      <pubDate>Fri, 04 Sep 2015 12:44:06 +0000</pubDate>
      <dc:creator>lviensen</dc:creator>
      <guid isPermaLink="false">12398@/two/discussions</guid>
      <description><![CDATA[<p>Como faço para saber quando o áudio parou de ser executado na função, e posso executar outra função a seguir?</p>
]]></description>
   </item>
   <item>
      <title>dealing with a boolean array (how to execute when all bool elements of the array is true?)</title>
      <link>https://forum.processing.org/two/discussion/12135/dealing-with-a-boolean-array-how-to-execute-when-all-bool-elements-of-the-array-is-true</link>
      <pubDate>Tue, 18 Aug 2015 05:53:08 +0000</pubDate>
      <dc:creator>Rstar37</dc:creator>
      <guid isPermaLink="false">12135@/two/discussions</guid>
      <description><![CDATA[<p>I'm having a problem writing my code. I wanted to execute a statement when more than one expression is true</p>

<pre><code>boolean checking(){
  boolean myVar = false;
  boolean[] each = new boolean [8];
  for (int i = 0; i &lt; 8; i++){
    if(i &gt; 0){   //just a random expression
      each[i] = true;
    }
  }
  if(each[0] &amp;&amp; each[1] &amp;&amp; each[2] &amp;&amp; each[3] &amp;&amp; each[4] &amp;&amp; each[5] &amp;&amp; each[6] &amp;&amp; each[7]){ //i need a better way to write that since the elements aren't always going to be 8 elements
    myVar = true;
  }
  return myVar;
}
</code></pre>

<p>this is a boolean function example (not the whole code)</p>
]]></description>
   </item>
   <item>
      <title>Use a function to display images</title>
      <link>https://forum.processing.org/two/discussion/12086/use-a-function-to-display-images</link>
      <pubDate>Fri, 14 Aug 2015 15:04:48 +0000</pubDate>
      <dc:creator>piddj</dc:creator>
      <guid isPermaLink="false">12086@/two/discussions</guid>
      <description><![CDATA[<p>I have 8 images that I want to display via a function. Each implementation of the function needs to show a different image.
What I cant work out is how to pass the image—for that function implementation—what image it needs to show...</p>

<p>ie.</p>

<p>PImage a, b;</p>

<p>void setup() {</p>

<p>a = loadImage("a.jpg");</p>

<p>b = loadImage("b.jpg");</p>

<p>}</p>

<p>void draw() {</p>

<p>myImage(???????, 40, 40); // to show a</p>

<p>myImage(???????, 80, 80); // to show b</p>

<p>}</p>

<p>void myImage(???????, int x, int y) {</p>

<p>image(???????, x, y);</p>

<p>}</p>

<p>Can anyone help clarify the ??????????'s ?</p>

<p>Thanks in advance.</p>
]]></description>
   </item>
   <item>
      <title>Treating each circle separate</title>
      <link>https://forum.processing.org/two/discussion/11159/treating-each-circle-separate</link>
      <pubDate>Thu, 04 Jun 2015 21:05:06 +0000</pubDate>
      <dc:creator>J_LAM</dc:creator>
      <guid isPermaLink="false">11159@/two/discussions</guid>
      <description><![CDATA[<pre><code>    float dotx , dotx2 , dotx3;
    float doty;
    float dspeed, dspeed2, dspeed3; 
    void setup(){
      size(600,600);
      background(255);
      frameRate(40);
      dotx = 0;
      dotx2 = 0;
      dotx3 = 0;
      dspeed = random(6, 10);
      dspeed2 = random(7, 11);
      dspeed3 = random(6, 10);
      doty = height/2;
    }
    void draw(){
      background(255);
      fill(#FF56AA);
      ellipse(dotx,doty+125, 50,50);
      ellipse(dotx,doty, 50,50);
      ellipse(dotx,doty-140, 50,50);
      if (dotx &gt;= width || dotx &lt; 0){
        dspeed = -dspeed;
      }
      if (dotx2 &gt;= width || dotx &lt;0){
        dspeed2 = -dspeed2;
      }  
      if (dotx3 &gt;= width || dotx &lt;0){
        dspeed3 = -dspeed3;
      }  
      dotx = dotx + dspeed;
    }
</code></pre>

<p>How can I make these circles move as individual functions? I tried using different variables for each circle, and still no good!</p>
]]></description>
   </item>
   </channel>
</rss>