CURVES

Live processing code
Back
curves rosace;
void setup() {
    size(700, 700);
    background(0);
    noStroke();
    rosace=new curves(width/2, height/2, 0.01, 2);
    rosace.rescale();
}

void draw() {
    rosace.update();
    rosace.changecolor();
}

//equation given directly in polar coordinates (use mode = 1 in "rosace")
float funcR(float theta) {
  float ma=sqrt(2);
  float mb=4;
  float a=5;
  float b=10;
  return a*cos(mb*pow(theta,2)); //equation to update to display whatever you want                          
}

//equation given in a parametric form (X(t), Y(t)) (use mode = 2 in "rosace")
float funcX(float theta) {
  float ma=sqrt(2);
  float mb=4;
  float a=5;
  float b=10;
  return a*cos(theta)*sin(theta); //equation to update to display whatever you want  
}

float funcY(float theta) {
  float ma=sqrt(2);
  float mb=4;
  float a=5;
  float b=10;
  return a*cos(theta)*tan(theta); //equation to update to display whatever you want  
}

//Class definition. Mainly used for the display styling. Lots of things to improve ;-)
class curves {

  float x, y, dt;
  int mode;
  int option1 = 0; //0 = normal, 1= random
  int red=205;
  int blue=102;
  int green=0;
  float theta=0;
  float rmax=0;

  curves(float xpos, float ypos, float s, int modeplot) {
    x=xpos;
    y=ypos;
    dt=s;
    mode = modeplot;
  }

  //this method is used to help scaling the curves. 
  void rescale(){
    rmax=0;
    for (int i=0;i<100;i++){
      theta=2*3.14/100*i;
      float tmp=sqrt(pow(func(theta,mode)[0], 2)+pow(func(theta,mode)[1], 2));
      if (tmp>rmax) {
        rmax=tmp;
      }
    }
    rmax *=1.1;
  }

  void update() {
    x=width/2+(func(theta,mode)[0])/(2*rmax/width);
    y=height/2+(func(theta,mode)[1])/(2*rmax/height);
    fill(red, blue, green);
    ellipse(x, y, 2, 2);
    d=10+5*abs(sin(theta));
    fill(red, blue, green,55);
    ellipse(x, y, d, d);
    if (option1 == 0){
    theta +=dt;
    }
    else if (option1 == 1){
    theta = random(0,4000);
    }
  }

  void changecolor() {
    red +=int(random(-5, 5));
    blue +=int(random(-5, 5));
    green +=int(random(-5, +5));
        if (red > 255){
     red = 255; 
    }
    if (red < 0){
     red = 0; 
    }
        if (blue > 255){
     blue = 255; 
    }
    if (blue < 0){
     blue = 0; 
    }
        if (green > 255){
     green = 255; 
    }
    if (green < 0){
     green = 0; 
    }
  }
  
  void initcolor(){
    red =int(random(0, 255));
    blue =int(random(0, 255));
    green =int(random(0, 255));
  }
  
  void restart(){
    background(0);
  }
}
     
float[] func(float theta, int mode) {
  float valueX = 0;
  float valueY = 0;
  float[] value = new float[2];
  switch(mode) {
  case 1:
    { //for a r(theta) function
      valueX = funcR(theta)*cos(theta);
      valueY = funcR(theta)*sin(theta);
      break;
    }
  case 2:
    { // for a parametric (x,y) function;
      valueX = funcX(theta);
      valueY = funcY(theta);
      break;
    }
  }
  value[0] = valueX;
  value[1] = valueY;
  return value;
}