Thursday, September 12, 2019

One Of Several Rainbow Processing Wallpapers

So I have a personal project whereby I'm using Processing to create a series of rainbow-on-black wallpapers. One is a rainbow rain effect, some are flickering dots. Another is bouncing dots. They all use similar code but they look slightly different. My plan is to eventually create a wallpaper manager for a user to select the wallpaper they want and install it as their background image and/or lockscreen, all themed after this rainbow-on-black look that I went for.

Eventually I may get around to posting all the code for the wallpapers, if you'd like to download the APDE app and compile it for a wallpaper yourself.

The first line can be modified to increase or decrease the number of circles, and commenting out the b[i]=ballHueCycle; line can remove the color cycling to decrease the level of rainbow vomit that's present in the wallpaper.


Ball[] b = new Ball[100];

boolean randBoolX;
boolean randBoolY;


void setup() {
  fullScreen();
  colorMode(HSB, 100);

  for (int i = 0; i < b.length; i++) {
    float randBoolTestX = random(1, 100);
    float randBoolTestY = random(1, 100);

    if (randBoolTestX >= 50) {
      randBoolX = true;
    }
    if (randBoolTestX < 50) {
      randBoolX = false;
    }
    if (randBoolTestY >= 50) {
      randBoolY = true;
    }
    if (randBoolTestY < 50) {
      randBoolY = false;
    }
    b[i] = new Ball(false, random(0, 1), randBoolX, randBoolY, random(1, 100), random(1, width), random(1, height), random(1, 10), random(1, 10), random(10, 60));
  }
}
void draw() {
  background (0);

  for (int i = 0; i < b.length; i++) {

    b[i].ballDraw();
    b[i].ballBounce();
    b[i].ballMove();
    b[i].ballFade();
    b[i].ballTransform();
    b[i].ballHueCycle();


    if (b[i].ballTransp <= 0) {
      b[i] = new Ball(false, random(0, 1), randBoolX, randBoolY, random(1, 100), random(1, width), random(1, height), random(1, 10), random(1, 10), random(10, 60));
    }
  }
}

class Ball {

  float ballHue;
  float ballX;
  float ballY;

  float ballTransp = 1;
  float ballOffsetX = 0;
  float ballOffsetY = 0;

  float fadeSpeed;

  float randX;
  float randY;

  float ballDiam;
  boolean bounceDirX;
  boolean bounceDirY;
  boolean ballMaxTransp = false;
  float ballMaxSize = random(80, 120);
  Boolean ballMaxSizeBool;
  float ballEnlarge = 0;

  Ball(boolean tempBallMaxSizeBool, float tempFadeSpeed, Boolean tempBounceDirX, Boolean tempBounceDirY, float tempBallHue, float tempBallX, float tempBallY, float tempRandX, float tempRandY, float tempBallDiam) {
    ballHue = tempBallHue;
    ballX = tempBallX;
    ballY = tempBallY;
    randX = tempRandX;
    randY = tempRandY;
    ballDiam = tempBallDiam;
    bounceDirX = tempBounceDirX;
    bounceDirY = tempBounceDirY;
    fadeSpeed = tempFadeSpeed;
    ballMaxSizeBool = tempBallMaxSizeBool;
  }
  void ballDraw() {
    noStroke();
    fill(ballHue, 100, 100, ballTransp); 
    ellipse(ballX + ballOffsetX, ballY + ballOffsetY, ballDiam + ballEnlarge, ballDiam + ballEnlarge);
  }

  void ballBounce() {

    if (ballX + ballOffsetX + 0.5*ballDiam <= 0) {
      ballOffsetX += randX;
      bounceDirX = !bounceDirX;
    }
    if (ballX + ballOffsetX + 0.5*ballDiam >= width) {
      ballOffsetX -= randX;
      bounceDirX = !bounceDirX;
    }
    if (ballY + ballOffsetY + 0.5*ballDiam <= 0) {
      ballOffsetY += randY;
      bounceDirY = !bounceDirY;
    }
    if (ballY + ballOffsetY + 0.5*ballDiam >= height) {
      ballOffsetY -= randY;
      bounceDirY = !bounceDirY;
    }
  }
  void ballMove() {
    if (bounceDirX == true) {
      if (ballX + ballOffsetX + 0.5*ballDiam > 0 && ballX + ballOffsetX + 0.5*ballDiam < width) {
        ballOffsetX += randX;
      }
    }
    if (bounceDirY == true) {
      if (ballY + ballOffsetY + 0.5*ballDiam > 0 && ballY + ballOffsetY + 0.5*ballDiam < height) {
        ballOffsetY += randY;
      }
    }
    if (bounceDirX == false) {
      if (ballX + ballOffsetX + 0.5*ballDiam > 0 && ballX + ballOffsetX + 0.5*ballDiam < width) {
        ballOffsetX -= randX;
      }
    }
    if (bounceDirY == false) {
      if (ballY + ballOffsetY + 0.5*ballDiam > 0 && ballY + ballOffsetY + 0.5*ballDiam < height) {
        ballOffsetY -= randY;
      }
    }
  }
  void ballFade() {

    if (ballMaxTransp == false) {
      ballTransp++;
    }
    if (ballTransp >= 100) {
      ballMaxTransp = true;
    }
    if (ballMaxTransp == true) {
      ballTransp -= fadeSpeed;
    }
  }

  void ballTransform() {
    if (ballMaxSizeBool == false) {
      ballEnlarge += sin(0.1*randX);
    }
    if (ballDiam + ballEnlarge >= ballMaxSize) {
      ballMaxSizeBool = true;
      ballEnlarge -= sin(0.1*randX);
    }
    if (ballMaxSizeBool == true) {
      ballEnlarge -= sin(0.1*randX);
    }
    if (ballEnlarge <= 0) {
      ballMaxSizeBool = false;
    }
  }
  void ballHueCycle() {
    ballHue++;
    if (ballHue >100) {
      ballHue = 1;
    }
  }
}

No comments:

Post a Comment