• fullscreen
  • colorCycler.pde
  • yingyang.pde
  • class colorCycler {
      float cycleSpeed;
      float r_part;
      float b_part;
      float g_part;
      float r_target;
      float b_target;
      float g_target;
      boolean r_upwards;
      boolean g_upwards;
      boolean b_upwards;
    
      colorCycler(float cycleSpeed_in) {
        cycleSpeed = cycleSpeed_in;
        randomColor();
      }
      
      void randomColor() {
        /*r_part = random(255);
        g_part = random(255);
        b_part = random(255);*/
        r_part = 255;
        g_part = 255;
        b_part = 255;
        r_target = random(255);
        g_target = random(255);
        b_target = random(255);
      }
    
      //cycle the color one and return it
      color nextColor() {
        //red part
        if (r_part >= r_target) {
          if(r_upwards) {//target reached
            r_target = random(255);
            if (r_target >= r_part) {
              r_upwards = true;
            }
            else {
              r_upwards = false;
            }
          }
          else {
            r_part -= cycleSpeed;
          }
        }
        else {
          if(r_upwards) {
            r_part += cycleSpeed;
          }
          else {//target reached
            r_target = random(255);
            if (r_target >= r_part) {
              r_upwards = true;
            }
            else {
              r_upwards = false;
            }
          }
        }
    
        //green part
        if (g_part >= g_target) {
          if(g_upwards) {//target reached
            g_target = random(255);
            if (g_target >= g_part) {
              g_upwards = true;
            }
            else {
              g_upwards = false;
            }
          }
          else {
            g_part -= cycleSpeed;
          }
        }
        else {
          if(g_upwards) {
            g_part += cycleSpeed;
          }
          else {//target reached
            g_target = random(255);
            if (g_target >= g_part) {
              g_upwards = true;
            }
            else {
              g_upwards = false;
            }
          }
        }
    
        //blue part
        if (b_part >= b_target) {
          if(b_upwards) {//target reached
            b_target = random(255);
            if (b_target >= b_part) {
              b_upwards = true;
            }
            else {
              b_upwards = false;
            }
          }
          else {
            b_part -= cycleSpeed;
          }
        }
        else {
          if(b_upwards) {
            b_part += cycleSpeed;
          }
          else {//target reached
            b_target = random(255);
            if (b_target >= b_part) {
              b_upwards = true;
            }
            else {
              b_upwards = false;
            }
          }
        }
    
        colorMode(RGB);
        return(color(r_part,g_part,b_part));
      }
    }
    
    
    /*created by rebirth*/
    
    float rot_angle1;
    int steps = 1000;
    color color1;
    color color2;
    colorCycler colorCycler1 = new colorCycler(.5);
    
    void setup() {
      size(800, 800);
      background(255/2);
      ellipseMode(CENTER);
      smooth();
      frameRate(30);
      noStroke();
    
    
      color1 = color(255,0,0);
      color2 = color(0);
    }
    
    
    void draw() {
      color1 = color(255);
      color2 = color(0);
      rot_angle1 = TWO_PI / steps * frameCount;
      drawYinYang(width/2, height/2, width/2, 0, rot_angle1);
    }
    
    void drawYinYang(float x, float y, int radius, int side, float rot) {
      //trace the outline in the color that is not the background color
      switch (side) {
      case 1:
        stroke(color1);
        break;
      case 2:
        stroke(color2);
        break;
      default:
        noStroke();//no outline on the outermost yinyang
      }
      noFill();
      pushMatrix();
      translate(x,y);
      fill(color1);
      ellipse(0,0,radius*2, radius*2);//entire circle
      fill(color2);
      arc(0,0,radius*2, radius*2, rot, rot+ PI);//half circle
      arc(radius/2 *cos(rot + PI),radius/2 * sin(rot + PI),radius, radius, rot + PI - .1, rot + TWO_PI + .1);//smaller half circle. add and subtract .1 to get rid of seams
      fill(color1);
      arc(radius/2 *cos(rot),radius/2 * sin(rot),radius, radius, rot - .1, rot+ PI + .1);//other smaller half circle
      fill(color1);
      noStroke();
      //ellipse(radius/2 * cos(rot), radius/2 * sin(rot), radius, radius);
      //ellipse(radius/2 * cos(rot + PI), radius/2 * sin(rot + PI), radius, radius);
    
      //the dots of the yinyang are other yinyangs!
      if (radius > 1) {
        drawYinYang(radius/2 * cos(rot), radius/2 * sin(rot), radius/4, 2, -rot);
        drawYinYang(radius/2 * cos(rot + PI), radius/2 * sin(rot + PI), radius/4, 1, -rot);
      }
      popMatrix();
    }
    
    color inverse_color(color c) {
      colorMode(RGB);
      float minRGB = min(red(c),min(green(c),blue(c)));
      float maxRGB = max(red(c),max(green(c),blue(c)));
      float min_plus_max = minRGB + maxRGB;
      return color(min_plus_max - red(c), min_plus_max - green(c), min_plus_max - blue(c));
    }
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    rebirth

    Yin Yang Recursion

    Add to Faves Me Likey@! 2
    You must login/register to add this sketch to your favorites.

    Symbolizes the sameness within the difference withing the sameness within the difference...

    New and improved version with zooming!
    http://www.openprocessing.org/visuals/?visualID=12951

    Guigui plus+
    30 Sep 2010
    Hello my friend! So you didn't feel to color cycle it? 8^)

    I have another sketch onto the Yin Yang symbol I didn't finished. I let it down a while ago but I will try to finish it one day. I'll warn you when done.
    You need to login/register to comment.