<?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 pow() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=pow%28%29</link>
      <pubDate>Sun, 08 Aug 2021 17:38:54 +0000</pubDate>
         <description>Tagged with pow() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedpow%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>impossible to calculate number at fractional power</title>
      <link>https://forum.processing.org/two/discussion/28140/impossible-to-calculate-number-at-fractional-power</link>
      <pubDate>Wed, 07 Nov 2018 21:47:41 +0000</pubDate>
      <dc:creator>brugola</dc:creator>
      <guid isPermaLink="false">28140@/two/discussions</guid>
      <description><![CDATA[<p>Hi ... I can not understand how to write a complex mathematical function.</p>

<p>I would like to be able to calculate the density of the air as a function of: pressure, temperature and humidity.</p>

<p>This is the formula.</p>

<pre><code>air density=1/temperature*( pressure- humidity*610.78*10^(7.5* temperature-2048.625/temperature-35.85)/287.05+humidity*610.78*10^(7.5* temperature-2048.625/temperature-35.85)/461.495)
</code></pre>

<p>How could I do?</p>

<p>This is what I thought, but it does not work.</p>

<pre><code> // text(nf(1/(273.15+Temp)*((PAtm+249.08)-Umid*610.78*pow(10,7.5*(273.15+Temp)-2048.625/((273.15+Temp)-35.85))/287.05)
 // +(Umid*610.78*pow(10,7.5*(273.15+Temp)-2048.625/((273.15+Temp)-35.85))/461.495),0,2), width-342,height-539); 
</code></pre>
]]></description>
   </item>
   <item>
      <title>How do you redraw over this pixel array?</title>
      <link>https://forum.processing.org/two/discussion/28123/how-do-you-redraw-over-this-pixel-array</link>
      <pubDate>Sat, 22 Sep 2018 11:30:43 +0000</pubDate>
      <dc:creator>ProsExplorer</dc:creator>
      <guid isPermaLink="false">28123@/two/discussions</guid>
      <description><![CDATA[<p>Hello again,
I'm trying to redraw over this 2D pixel array of this program.</p>

<pre><code>// main setup settings
int dimy = 800;            // screen width 1681
int dimx = 850;            //screen height 1019
int bailout = 2000;         // number of iterations before bail
int plots = 171294;        // number of plots to execute per frame (x30 = plots per second) 171294
//zoom/magnification
float magx = 4.0; // default 3.0, smaller means more zoom
float magy = magx*(dimy/float(dimx));
//pan
float panx = 0.3; //default is 0.5
float pany = 0.0; //default is 0.0
//brightness multiplier
float brt = 1.0; // brightness factor

// 2D array to hold exposure values
int[] exposure = new int[dimx*dimy];

// maximum exposure value
int maxexposure;           

int time = 0;
int exposures = 0;

 float Ex = 2;

 float x, y;
 float x0, y0;

boolean drawing; 

int sgn(float value) {            //if signus is needed sgn(x)=x/abs(x) = 1, 0 or -1
 if (value &lt; 0) {return -1;}
 if (value &gt; 0) {return 1;}
 return 0;
}
float cosh(float value1) {
 return 0.5*(exp(value1)+exp(-value1));
}
float sinh(float value2) {
 return 0.5*(exp(value2)-exp(-value2));
}
float arg(float axis1, float axis2) {
 if (axis2==0) {return PI;}
 else {return -atan(axis1/axis2)+PI*sgn(axis2)*0.5;}
}
float spharg(float axisa, float axisb, float axisc) {
 return acos(axisc/sqrt(sq(axisa)+sq(axisb)+sq(axisc)));
}
void setup() {
 // set up drawing area
 size(800,850,P3D);
}
void draw() {
 plotPlots();
 time++;
 if (time%1==0) { //every second
   findMaxExposure();
   // Infinitely Looping, nested boolean iteration(x0,y0,DrawIt)
   renderBrot();
 }
}
void plotPlots() {

 // iterate through some plots
 for (int n=0;n&lt;plots;n++) {
   // Choose a random point in same range
   x = random(-2.0,2.0);
   y = random(-2.0,2.0);
   x0 = random(-2.0,2.0);
   y0 = random(-2.0,2.0);

   if (iterate(x,y,false)) {
    //Pauses Boolean, (d=pause, D=start)
     if (Ex &gt; 1){
       iterate(x,y,true);
       exposures++;
      }
      if (Ex &lt; 2){
       iterate(x,y,false);
      }
   }

 }
}
void renderBrot() {
 colorMode(RGB,1.0);
 // draw to screen
 for (int i=0;i&lt;dimx;i++) {
   for (int j=0;j&lt;dimy;j++) {
     float ramp = brt * exposure[i*dimy+j] / maxexposure;
     // blow out ultra bright regions
     if (ramp &gt; 1)  {
       ramp = 1;
     }
     //shading formulae
     color c = color(pow(sin(ramp),0.4),pow(ramp,0.75),pow(ramp,2.5)); // sunset
     set(j,i,c);
   }
 }
} 
//   Iterate the Mandelbrot and return TRUE if the point exits
//   Also handle the drawing of the exit points
boolean iterate(float x0, float y0, boolean drawIt) {
 float x = 0.0;
 float y = 0.0;
 //float t = random(0,1);
 //float r = random(0,1);  

 //x0 = 0.0;
 //y0 = 0.0;

 float xnew, ynew;
 int ix,iy;

 for (int i=0;i&lt;bailout;i++) {

   // Display iterations before false DrawIt boolean
   //if (i&gt;0){
   //println(i);
   // }

   //set your costum formula here...
   //example:
   //default Mandelbrot
   xnew = x * x - y * y + x0;
   ynew = 2 * x * y + y0;

// Draws pixel to screen -
// Based on if drawIt boolean is true, and iterations[i] &gt; 3

  // Defines and Draws Pixels in 2D Exposure Array
  // Draws pixel when iteration[i] &gt; 3 within current boolean cycle of xnew, ynew values
  if (drawIt &amp;&amp; (i &gt; 3)) {

     ix = int(dimx*(panx+xnew+magx/2.0)/magx);
     iy = int(dimy*(pany+ynew+magy/2.0)/magy);

     //Defines points (ix,iy) within screen ranges
     if (ix &gt;= 0 &amp;&amp; iy &gt;= 0 &amp;&amp; ix &lt; dimx &amp;&amp; iy &lt; dimy) {
       // rotate and expose point
       exposure[ix*dimy+iy]++;
   }
 }

   if ((xnew*xnew + ynew*ynew) &gt; 4) {
     // escapes
     return true;
   }
   x = xnew;
   y = ynew;
 }
 // does not escape
 return false;
}
void findMaxExposure() {
 // assume no exposure
 maxexposure=0;
 // find the largest density value
 for (int i=0;i&lt;dimy;i++) {
   for (int j=0;j&lt;dimx;j++) {
     maxexposure = max(maxexposure,exposure[i*dimx+j]);
   }
 }
} 
 void keyPressed(){

    //Return Iterate(x0,y0,DrawIt) False in Plot  
    if (key == 'r') {
     Ex = 1;
    }
    //Return Iterate(x0,y0,DrawIt) True in Plot  
    if (key == 'R') {
     Ex = 2;
    }
}
</code></pre>

<p>I've studied and tested many pixel array programs recently, but don't understand it enough to figure it out the exact method. I know the pixel array exposure[] is a 2D array within the looping, nested boolean iterate(x0,y0,drawIt) and that the pixel array output is derived from the specific code:</p>

<pre><code>    // Draws pixel to screen -
    // Based on if drawIt boolean is true, and iterations[i] &gt; 3

      // Defines and Draws Pixels in 2D Exposure Array
      // Draws pixel when iteration[i] &gt; 3 within current boolean cycle of xnew, ynew values
      if (drawIt &amp;&amp; (i &gt; 3)) {

         ix = int(dimx*(panx+xnew+magx/2.0)/magx);
         iy = int(dimy*(pany+ynew+magy/2.0)/magy);

         //Defines points (ix,iy) within screen ranges
         if (ix &gt;= 0 &amp;&amp; iy &gt;= 0 &amp;&amp; ix &lt; dimx &amp;&amp; iy &lt; dimy) {
           // rotate and expose point
           exposure[ix*dimy+iy]++;
       }
     }
</code></pre>

<p>It's not a boolean true/false issue as the entire program is written in an infinite loop of nested booleans drawing, iterate(x0,y0,drawIt) and when halted either in the drawing section or the plotPlots() section the pixel array remains intact upon continuation of the program (as demonstrated with Keypressed 'r', 'R'). The program is well threaded into itself with it's booleans and I have no reason to change that fact.</p>

<p>How would I go about updating the entire pixel array in this program to a single color (black) upon key press? Blanking out the canvas and the program continuing it's constant pixel drawing process of exposure points on screen again without the old pixels.</p>
]]></description>
   </item>
   <item>
      <title>Converting floats to short approximations</title>
      <link>https://forum.processing.org/two/discussion/20726/converting-floats-to-short-approximations</link>
      <pubDate>Wed, 08 Feb 2017 23:48:03 +0000</pubDate>
      <dc:creator>prince_polka</dc:creator>
      <guid isPermaLink="false">20726@/two/discussions</guid>
      <description><![CDATA[<p>I needed this in a project I'm working on and wrote this function which seems to work quite well, (haven't tested it extensively though)</p>

<pre><code>String nufix(float n) { // Numerical Suffix
  String a="";          // String manipulation variable
  float K = 1000.0;     // Kilo
  float M = pow(K, 2);  // Mega
  float G = pow(K, 3);  // Giga
  float T = pow(K, 4);  // Terra
  float P = pow(K, 5);  // Peta
  float E = pow(K, 6);  // Exa
  float Z = pow(K, 7);  // Zeta
  float Y = pow(K, 8);  // Yotta
  float sv=1.0;         // Suffix value
  char  sc=' ';         // Suffix char
  int neg=0; if (n&lt;0){neg=1;} // boolean as int for convenience

  if      (abs(n) &lt; 1) {return '.'+str(int(n*10));}
  else if (abs(n) &lt; K) {return str(int(n));}
  else if (abs(n) &lt; M) {sc='K'; sv=K;}
  else if (abs(n) &lt; G) {sc='M'; sv=M;}
  else if (abs(n) &lt; T) {sc='G'; sv=G;}
  else if (abs(n) &lt; P) {sc='T'; sv=T;}
  else if (abs(n) &lt; E) {sc='P'; sv=P;}
  else if (abs(n) &lt; Z) {sc='E'; sv=E;}
  else if (abs(n) &lt; Y) {sc='Z'; sv=Z;}
  else if (abs(n) &lt; Y*K) {sc='Y'; sv=Y;}
  else {return "yo mama";} // here I give up

  if (abs(n)&gt;=10.0*sv) {
  return str(int(n/sv))+sc;
  }
  else {
    a=str(n/sv);
    if (a.charAt(1+neg)=='.' &amp;&amp; a.charAt(2+neg)=='0') {
      return a.substring(0,1+neg)+sc;
      }
    else {return a.substring(0,3+neg)+sc;}
  }
}
</code></pre>

<p>Also this shorter but a little worse variant</p>

<pre><code>String nufix(float n) { 
  String scrs="KMGTPEZY";
  if      (abs(n) &lt; 1) {return '.'+str(int(n*10));}
  else if (abs(n) &lt; 1000.0) {return str(int(n));}
  for(int i=0; i&lt;scrs.length();i++)
  {
    if (abs(n) &lt; pow(1000.0,i+2)){
      return str(int(n/pow(K,i+1)))+scrs.charAt(i);
    }
  }
  return "yo mama";
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to translate a math equation in processing ?</title>
      <link>https://forum.processing.org/two/discussion/19055/how-to-translate-a-math-equation-in-processing</link>
      <pubDate>Tue, 15 Nov 2016 15:36:32 +0000</pubDate>
      <dc:creator>lbolli</dc:creator>
      <guid isPermaLink="false">19055@/two/discussions</guid>
      <description><![CDATA[<p>Hello,
I'm new in processing. 
I'm trying to create a variation on Fermat spiral based on an equation and then export it in PDF.
I have the code to create a Fermat spiral (several existing example exist) but I can't control it as I would do using an equation. I was wondering if there is a way to simply "translate" an equation into processing ?</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/028/WWT1TOVXQW0K.png" alt="Capture d’écran 2016-11-15 à 16.35.02" title="Capture d’écran 2016-11-15 à 16.35.02" /></p>

<p>Thanks for your tips and help !</p>
]]></description>
   </item>
   <item>
      <title>How to Draw to/Continually reload an offscreen buffer?</title>
      <link>https://forum.processing.org/two/discussion/18295/how-to-draw-to-continually-reload-an-offscreen-buffer</link>
      <pubDate>Mon, 26 Sep 2016 05:06:10 +0000</pubDate>
      <dc:creator>DrNormalLove</dc:creator>
      <guid isPermaLink="false">18295@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to make a drawing program based on the user input, but I can't seem to figure out how to draw to the permanent buffer vs. the screen.</p>

<p>E.g. allowing one to "slide" a specific shape without smearing it, via refreshing the buffer.</p>
]]></description>
   </item>
   <item>
      <title>NaN return in code when computing normal vector</title>
      <link>https://forum.processing.org/two/discussion/17622/nan-return-in-code-when-computing-normal-vector</link>
      <pubDate>Sat, 23 Jul 2016 02:16:41 +0000</pubDate>
      <dc:creator>nuh</dc:creator>
      <guid isPermaLink="false">17622@/two/discussions</guid>
      <description><![CDATA[<p>Hey im having trouble figuring out why my code returns NaN when i set m=0 or when i give it the angle =0 . Help would be greatly appreciated i've been trying to figure this out for a while now.</p>

<pre><code>    PVector nvector(float angle){
      float sinc = (m/8)*sin((m/2)*angle);
      float cosc= ((pow(m,2))/16)*cos((m/2)*angle); 

      float g =(-n2*pow(abs(1/a),n2))*pow(cos((m/4)*angle),n2-2)
        +(n3*pow(abs(1/b),n3))*pow(sin((m/4)*angle),n3-2) ;

      float dg = (n2*pow(abs(1/a),n2))*((n2-2))*sinc*pow(cos((m/4)*angle),n2-4)
        +(n3*pow(abs(1/b),n3))*((n3-2))*sinc*pow(sin((m/4)*angle),n3-4);

      float f = pow(abs((1/a)*cos((m/4)*angle)),n2)+ pow(abs((1/b)*sin((m/4)*angle)),n3);

      float df = sinc*g ;

      float d2f = dg*sinc+g*cosc ; 

      float r =pow(f,(-1/n1)); // this is taken care of by the shape function
      float dr = (-1/n1)*pow(f,((-1/n1)-1))*df;

      float d2r =  (1/n1)*((1/n1)+1)*pow(f,((-1/n1)-2))*pow(df,2)+(-1/n1)*pow(f,(-1/n1)-1)*d2f;

      PVector v1 = new PVector(cos(angle),sin(angle)); 
      PVector v3 = new PVector(cos(angle),sin(angle));
      PVector v2 = new PVector(-sin(angle),cos(angle));

      v1.mult(d2r);
      v2.mult((2*dr));
      v3.mult(r);

      PVector M = v1.add(v2);
      PVector N = M.sub(v3);

       return N;
    } 
</code></pre>
]]></description>
   </item>
   <item>
      <title>Most Efficient Conversion of Integer Value to Floating Point Value</title>
      <link>https://forum.processing.org/two/discussion/14169/most-efficient-conversion-of-integer-value-to-floating-point-value</link>
      <pubDate>Mon, 28 Dec 2015 17:05:45 +0000</pubDate>
      <dc:creator>Jim_Plaxco</dc:creator>
      <guid isPermaLink="false">14169@/two/discussions</guid>
      <description><![CDATA[<p>Note this is not a question about casting.</p>

<p>I am curious as to the most efficient way to take an integer value and convert it to a floating point so that the whole numbers become fractional numbers.</p>

<p>To illustrate, I want to convert any number from 99999  to  0.99999. 
So if the value is 7 I want the output to be 0.7. 
If the value is 8412223,  I want the output to be 0.8412223</p>

<p>Is there some "magic" bit-oriented operation that can achieve this or will it take a brute-force method (for example determine the number of digits in the value and then divide by an equivalent power of 10).</p>

<p>Any insights will be greatly appreciated. Thanks</p>
]]></description>
   </item>
   <item>
      <title>Calculation inaccuracy?</title>
      <link>https://forum.processing.org/two/discussion/12626/calculation-inaccuracy</link>
      <pubDate>Mon, 21 Sep 2015 21:29:40 +0000</pubDate>
      <dc:creator>soronemus</dc:creator>
      <guid isPermaLink="false">12626@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to use processing to communicate in real time with an arduino which is driving a 3d printer via serial communication. The problem I am having is that some calculations I am doing in processing are giving me the wrong answer. The below code is a simple calculation of the inverse kinematic solution of a 3PUU delta robot. I give it the cartesian coordinates (x, y, and z) and it is supposed to give me L1, L2, and L3 (the height of each carriage on the printer) in order to achieve that position. The L1 it is giving me is correct, but the L2 and L3 are off by 6-7mm which is huge for this application. I thought it might have been a problem with my code, but I used the same formulas in matlab and the answer was correct far past 4 decimal places. Are any of the functions that I am using causing loss of precision or rounding errors maybe? Possibly the sqrt() function or pow(bla, bla) function? Can anyone tell me why my answers are incorrect with this code?</p>

<p>If anyone is curious about the source of the formulas it is here: 
<a href="http://www.ohio.edu/people/williar4/html/pdf/DeltaKin.pdf" target="_blank" rel="nofollow">http://www.ohio.edu/people/williar4/html/pdf/DeltaKin.pdf</a>
pages 27 and 28</p>

<p>Code below:</p>

<p>//variables (lengths, etc) (mm)</p>

<p>float sb=432;</p>

<p>float rb=142;</p>

<p>float sp=127;</p>

<p>float lmin=67;</p>

<p>float lmax=479;</p>

<p>float l=264;</p>

<p>float h=44;</p>

<p>float wb=(sqrt(3)/6)*sb;</p>

<p>float ub=(sqrt(3)/3)*sb;</p>

<p>float wp=(sqrt(3)/6)/sp;</p>

<p>float up=(sqrt(3)/3)*sp;</p>

<p>float ox=0;</p>

<p>float oy=0;</p>

<p>float H=686;</p>

<p>//input coordinates (desired position)</p>

<p>float x=0;</p>

<p>float y=0;</p>

<p>float z=-500;</p>

<p>//calculations</p>

<p>float a=wb-up;</p>

<p>float b=(sp/2)-((sqrt(3)/2)*wb);</p>

<p>float c=wp-(.5*wb);</p>

<p>// calculations</p>

<p>float C1=pow(x,2)+pow(y,2)+pow(z,2)+pow(a,2)+(2<em>y</em>a)-pow(l,2);</p>

<p>float C2=pow(x,2)+pow(y,2)+pow(z,2)+pow(b,2)+pow(c,2)+(2<em>x</em>b)+(2<em>y</em>c)-pow(l,2);</p>

<p>float C3=pow(x,2)+pow(y,2)+pow(z,2)+pow(b,2)+pow(c,2)-(2<em>x</em>b)+(2<em>y</em>c)-pow(l,2);</p>

<p>//both solutions for each length (elbow up, and elbow down)</p>

<p>float L11=-z+sqrt(pow(z,2)-C1);</p>

<p>float L12=-z-sqrt(pow(z,2)-C1);</p>

<p>float L21=-z+sqrt(pow(z,2)-C2);</p>

<p>float L22=-z-sqrt(pow(z,2)-C2);</p>

<p>float L31=-z+sqrt(pow(z,2)-C3);</p>

<p>float L32=-z-sqrt(pow(z,2)-C3);</p>

<p>println("elbow up");</p>

<p>println("L1: "+L11);</p>

<p>println("L2: "+L21);</p>

<p>println("L3: "+L31);</p>

<p>println("elbow down");</p>

<p>println("L1: "+L12);</p>

<p>println("L2: "+L22);</p>

<p>println("L3: "+L32);</p>

<p>println("actual answer: 241");</p>
]]></description>
   </item>
   <item>
      <title>why is pow(2, 0) 1?</title>
      <link>https://forum.processing.org/two/discussion/11877/why-is-pow-2-0-1</link>
      <pubDate>Tue, 28 Jul 2015 22:38:49 +0000</pubDate>
      <dc:creator>clankill3r</dc:creator>
      <guid isPermaLink="false">11877@/two/discussions</guid>
      <description><![CDATA[<p>Maybe it's getting late but why is the power of 2 for the value 0  -&gt; 1?</p>

<pre><code>for (int i = 0; i &lt;= 16; i++) {
  println(i, pow(2, i));
}
</code></pre>

<p>(Code formatting keeps eating the code...)</p>
]]></description>
   </item>
   <item>
      <title>CP5 controls: Slider where for each increment, do something</title>
      <link>https://forum.processing.org/two/discussion/6152/cp5-controls-slider-where-for-each-increment-do-something</link>
      <pubDate>Sat, 05 Jul 2014 11:47:44 +0000</pubDate>
      <dc:creator>totalNewb</dc:creator>
      <guid isPermaLink="false">6152@/two/discussions</guid>
      <description><![CDATA[<p>Lets say I'm stretching a line  from point a to point b based on a slider value. At the moment, all pixels between point a and b are stretched equally (where the new width is squared and divided by 100):</p>

<pre><code>         sliderValue= (int)(theEvent.controller().value());
            a = (int) (pow( sliderValue, 2) /100);
</code></pre>

<p>But, I want to stretch points along the line at an increasing rate from a to b.  I want to do a statement where for each tick, the stretch on the pixels is increased.  so say the first point on my slider is 100:  <em>a</em> = pow(<em>a</em>, 2) /100    which equals 100. The second increment on the slider is 10, so now the slider value is at 110, but <em>a</em> should be 121 (<em>a</em> = pow(110,2)/100). The next point on the slider is 120, so <em>a</em> should be 144, and so on.
So the distanc between the points along the line increases, even though the slider tick mark value stays at increments of 10.</p>

<p>How do I do that in Processing? Thanks</p>
]]></description>
   </item>
   </channel>
</rss>