Thursday, 15 October 2020

Brain Dead Coding

I AM done with this for now I think.

I have attempted to make a collision physics for this fucking snowfall for way too long. I even tried to just do just ease the snow particles away but to no avail. I don't really know what's wrong with it, but I did learn how to utilize arrays so that the computer doesn't explode trying to load all of these snowfall particles.

anyways my head hurts lots soooo.. Here's the video 


My code is a big ol' mess. So have fun cringing at it cuz I wasted so much time trying to figure this out.

also the rain looks like its actually colliding with the box, Optical illusion I guess.


//this is mostly for the other one

int i;

int quantity = 1000;

float [] x = new float[quantity];

float [] y = new float[quantity];

float [] x1 = new float[quantity];

float [] y1 = new float[quantity];

int [] Size = new int[quantity];

int [] direction = new int[quantity];

int minSize = 4;

int maxSize = 5;

float xS;

int [] speed = new int[quantity];

//the big blocking cirle

float Ux1;

float Uy1;

float ease = .05;

//calls the snow from the other tab

SnowParticles snow;


void setup(){ 

  size(1280,720);

  smooth();

  noStroke();

  

  for(int i = 0; i < quantity; i++) {

    x[i] = random(0, width);

    y[i] = random(0, height);

    Size[i] = round(random(minSize, maxSize));

    //direction[i] = round(random(0, 1));

    speed[i] = round(random(1,10));

  }

}


void draw(){

  background(50,80,100,1);

  umbra(100);

  snowCall();

  

  fill(20,10,10,50);

  rect(128, 0, width*.8, height*.9);


}


void snowCall(){

  

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

  //attempt on easing snowfall away from the mouseX

  //calls for the Snowparticle from the other tab

  snow = new SnowParticles(x[i],y[i],Size[i]);

  snow.shakingMovement();

  snow.display();

  //direction is disabled so only the else works atm

  //switches between 2 directions of X

    if(direction[i] == 0) {

      x[i] += map(Size[i], minSize, maxSize, xS, xS);

    } else {

      x[i] -= map(Size[i], minSize, maxSize, xS, xS);

    }

  //makes the snow fall in the Y axis

  y[i] += speed[i] + direction[i]; 

  //basically the collision but it also makes it so the snow piece loops

  if(x[i] > width + Size[i] || x[i] < -Size[i] || y[i] > height*.89 + Size[i]) {

    x[i] = random(0, width);

    y[i] = -Size[i];

  }

  x[i] = constrain(x[i], 128, width*.9-Size[i]);

    

  }

  

}


void keyPressed(){

if (key == CODED)

  {

    //increases left to right speed

    if (keyCode == LEFT & xS > -20){

      xS--;

    }

    if (keyCode == RIGHT && xS < 20){

      xS++;

    }

  }

}

//custom function for "main character" aka the big grey box

void umbra(int Udiameter){

  //ease coding for X and Y

  float targetX = mouseX;

  float dx = targetX - Ux1;

  Ux1 += dx * ease;

  

  float targetY = mouseY;

  float dy = targetY - Uy1;

  Uy1 += dy * ease;

  //collisions for the box

  Ux1 = constrain(Ux1,128+(Udiameter/2),width*.9-(Udiameter/2));

  Uy1 = constrain(Uy1,0+(Udiameter/2),height*.9-(Udiameter/2));

  //what the box is made out of

  fill(200);

  push();

  rectMode(CENTER);

  rect(Ux1, Uy1, Udiameter, Udiameter);

  pop();

}


other tab:


class SnowParticles{

  float x;

  float y;

  int diameter;

  float speed = 1;

  

  SnowParticles(float tempX, float tempY, int tempDiameter){

    x = tempX;

    y = tempY;

    diameter = tempDiameter;

  }

  

  void shakingMovement(){

    x += random(-speed,speed);

    y += random(-speed,speed);

  }

  

  void display(){

    fill(150,255,255);

    rect(x, y, diameter, diameter);

  }

  

}

1 comment:

  1. Very cool. Let me know if you want to meet up so we can figure out how to make this do what you wanted it to!

    ReplyDelete

Speedran Coding

Another day another monki moment. Had about 2 hours to make this until it is up and done! My idea was to create a looping hallway that never...