Coding Different Trigonometric Functions in Processing

You can write a function for integer exponents and where execution time is important to speed things up.
Discussed and tested here:

In the example provided he did not require pow():

float x;
float y;

void setup()
  {
  size(500, 500);
  strokeWeight(2);
  translate(width/2, height/2 - 10);

//Using integer steps in formula used  
for (int i = -10; i<10; i+= 1)
    {
    y = 200/(1+pow(exp(1), i));
    point(10*i, 1-y);
    }

  translate(0, height/2);    
    
// Simplified and using float steps of 0.5 
  for (float i = -10; i<10; i+= .5)
    {
    y = 200/(1+exp(i));
    point(10*i, 1-y);
    }
  }

References:

Processing source code for exp() and pow()

:)

4 Likes