top of page
  • Writer's pictureRikka Ly

Keepin' it Wheel Processing3 Code

Updated: Jul 24, 2023

I encourage you to run this code yourself to see the looping randomness of the emissions!



import java.util.*;

int wheelxPos = 1050;
int frame = 0;
float CO2x;
float CO2y;
float CO2size;
int spacing = 20;
int r;
int wheelSize = 30;

ArrayList<gas> gasParticles = new ArrayList<gas>();
static ArrayList<CO2> CO2emissions = new ArrayList<CO2>();
static ArrayList<Integer> Y = new ArrayList<Integer>();

void setup() {
  size(1000, 1000);
  gas g = new gas();
  gasParticles.add(g);
}

void draw() {
  frame++;
  background(255);
  noStroke();
  fill(0);
  circle(wheelxPos, 850, 200);

  fill(255);
  pushMatrix();
  translate(wheelxPos, 850);
  rotate(radians(r));

  circle(spacing, spacing, wheelSize);
  circle(-spacing, spacing, wheelSize);
  circle(spacing, -spacing, wheelSize);
  circle(-spacing, -spacing, wheelSize);
  
  pushMatrix();
  rotate(radians(45));
  circle(spacing, spacing, wheelSize);
  circle(-spacing, spacing, wheelSize);
  circle(spacing, -spacing, wheelSize);
  circle(-spacing, -spacing, wheelSize);
  popMatrix();

  popMatrix();
  circle(wheelxPos, 850, 50);

  CO2emission();
  System.out.println(frame);

  if (wheelxPos != 500 || frame > 650) {
    wheelxPos -= 5;
    r -= 2;
  }
  if (wheelxPos == 500) {
    gasRising();
    if ((frame % 25 == 0) && (frame < 500)) {
      gas g = new gas();
      gasParticles.add(g);
    }
  }
  if (wheelxPos < -550) {
    wheelxPos = 1050;

    gasParticles = new ArrayList<gas>();
    CO2emissions = new ArrayList<CO2>();
    Y = new ArrayList<Integer>();
    gas g = new gas();
    gasParticles.add(g);
    CO2y = 0;
    CO2size = 0;
    frame = 0;
  }
  
}

void gasRising() {
  for (int num = 0; num < gasParticles.size(); num++) {
    gasParticles.get(num).ascend();
    gasParticles.get(num).display();

    fill(255);
  pushMatrix();
  translate(wheelxPos, 850);
  rotate(radians(r));

  circle(spacing, spacing, wheelSize);
  circle(-spacing, spacing, wheelSize);
  circle(spacing, -spacing, wheelSize);
  circle(-spacing, -spacing, wheelSize);
  
  pushMatrix();
  rotate(radians(45));
  circle(spacing, spacing, wheelSize);
  circle(-spacing, spacing, wheelSize);
  circle(spacing, -spacing, wheelSize);
  circle(-spacing, -spacing, wheelSize);
  popMatrix();

  popMatrix();
  circle(wheelxPos, 850, 50);

    if (gasParticles.get(num).x < 0 || gasParticles.get(num).x > 1000 || gasParticles.get(num).y < 0) {
      gasParticles.remove(num);
      num--;
    }
  }
}

class CO2 {
  float x;
  float y;
  float size;
  float POPsize = random(10, 30);
  float pop = 0;
  float check = int( random(1, 10) );
  float transparency = 1;
  float dtrans = random(0.01, 0.00001);

  CO2(float x, float y, float  size) {
    this.x = x;
    this.y = y;
    this.size = size;
  }

  void display() {
      noStroke();
      float a = map(transparency, 0, 1, 0, 255);
      if(frame > random(650, 800)){
        transparency -= dtrans;
      }
      fill(0, 0, 0, a);
      if (frame < 620) {
        size += 2;
      }
      circle(x, y, size);
    
  }
}

void CO2emission() {
  for (int num = 0; num < CO2emissions.size(); num++) {
    CO2emissions.get(num).display();
  }
}

class gas{
  float x;
  float y;
  float size;
  float yspeed;
  float xspread = random(-4.5, 4.5);
  CO2 c;
  
  gas(){
    x = 500;
    y = 850;
    size = random(40, 70);
    yspeed = random(5, 6);
  }
  
  void ascend(){
    y = y - yspeed;
    x = x + random(-2, 2) + xspread;
  }
  
  void display(){
    noStroke();
    fill(0);
    circle(x, y, size);
    
    if(x < 0 || x > 1000 || y < 0){
      CO2 c = new CO2(x, y, size);
      a1.CO2emissions.add(c);
    }
  }
}

26 views0 comments

Recent Posts

See All
bottom of page