Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * How to use:
- * 1. Download APDE
- * 2. Launch it and paste this code in there.
- * 3. Press the Button right of the play button and select "wallpaper"
- * 4. Press play -> install -> select as wallpaper
- *
- * Original Source Code provided by u/throwaway-8979323
- * https://pastebin.com/TWdVNTfq
- *
- * Current version is by u/petarts
- * https://pastebin.com/Fn8LwxNq
- */
- ArrayList<Twinkle> twinkles = new ArrayList<Twinkle>();
- Star[] stars;
- color[] colors;
- //***
- void setup() {
- fullScreen();
- //genderfluid
- color[] genderfluid = { color(255, 118, 163), color(255, 255, 255), color(191, 17, 215), color(0, 0, 0), color(48, 60, 190) };
- //trans
- color[] transgender = { color(91, 207, 250), color(245, 171, 185), color(255, 255, 255), color(245, 171, 185), color(91, 207, 250) };
- //Design?
- colors = transgender;
- //Amount of Stars?
- int starCount = 1000;
- stars = new Star[starCount];
- for (int i = 0; i < starCount; i++) {
- stars[i] = new Star();
- }
- }
- //***
- int tick=0;
- void draw() {
- background(0, 0, 0);
- for (Star s : stars) {
- s.update();
- s.display();
- }
- //println(twinkles.size(), frameRate);
- for (Twinkle t : twinkles) {
- t.update();
- t.display();
- }
- if(tick>60){ //once every 60 ticks, remove the dead twinkles.
- int size=twinkles.size();
- boolean move=true;
- int i;
- for(i=0 ; ((i<size)&&move);++i){
- Twinkle t1=twinkles.get(i);
- Twinkle t2=twinkles.get(size-1-i);
- if(!t1.isDead()){
- move=false;
- i=size-1-i;
- }
- if(t2.isDead()){
- i=i-1;
- move=false;
- }
- if(move){
- twinkles.set(i,t2); //move a living twinkle to the front of the array from the back
- }
- }
- for(int j=size-1;j>i;j--){
- twinkles.remove(j); //remove all the dead twinkles that are now at the back
- }
- tick=0;
- }else{
- tick+=1;
- }
- }
- //***
- void mouseDragged() {
- for (int i = 0; i < 3; i++) twinkles.add(new Twinkle(mouseX, mouseY)); //add twinkles when dragging screen
- }
- //Color Stuff
- public color getColor(float y,float fixed_rand) {
- float gradient = 40;
- y += (fixed_rand-0.5)*gradient; //randomize a bit
- y = constrain(y, 0, height-1); //keep value inside of screen
- y /= height; //put between 0 and 1
- y *= colors.length-1; //make valid for array
- int yi=int(y);
- color c = lerpColor(colors[yi], colors[yi+1], y%1); //fade between colors
- return c;
- }
- //normal Tangent
- public PVector nTangent(PVector center, PVector point){
- PVector tangent=new PVector(center.y-point.y,point.x-center.x);
- return tangent.normalize();
- }
- //hard constrain
- public float hardConstrain(float num,float min, float max){
- float res=num-min;
- if(res<0){res=max-min; }
- else if(res>(max-min)){res=0; }
- return (res+min);
- }
- //distance
- public float distance(PVector p1, PVector p2){
- PVector dist= p1.copy();
- dist.sub(p2);
- return dist.mag();
- }
- class Twinkle {
- PVector pos;
- PVector vel = new PVector();
- color col;
- float size;
- float alpha = 0;
- float startSpeed = 2;
- Twinkle(float x, float y) {
- pos = new PVector(x, y);
- //randomness
- //movement
- float randRad = 200;
- PVector rand = PVector.random2D();
- pos.add(rand.copy().mult(randRad));
- vel.add(rand.mult(startSpeed));
- //appearance
- col = getColor(pos.y,random(1.0f));
- size = random(3, 5);
- }
- void update() {
- pos.add(vel);
- vel.mult(0.95);
- float sX = map(vel.mag(), startSpeed, 0, -PI/2, 3*PI/2);
- float s = ((sin(sX)+1)/2)*255;
- alpha = s;
- }
- void display() {
- ellipseMode(CENTER);
- noStroke();
- fill(red(col), green(col), blue(col), alpha);
- ellipse(pos.x, pos.y, size, size);
- }
- boolean isDead(){
- return (vel.mag()<0.01);
- }
- }
- public PVector center= new PVector(-150,-150);
- public float b_width=10; //border width
- class Star {
- PVector pos = new PVector();
- float speed;
- float fixed_rand;
- color col;
- float size;
- Star() {
- pos.set(random(-b_width,width+b_width), random(-b_width,height+b_width));
- speed=random(0.125,0.25);
- fixed_rand=random(1.0f);
- col = getColor(pos.y,fixed_rand);
- size = random(5, 8);
- }
- void update() {
- col = getColor(pos.y,fixed_rand);
- PVector tang=nTangent(center,pos);
- tang.mult((float)(speed*Math.log(distance(center,pos))));
- pos.add(tang);
- pos.x=hardConstrain(pos.x,-b_width,width+b_width);
- pos.y=hardConstrain(pos.y,-b_width,height+b_width);
- }
- void display() {
- ellipseMode(CENTER);
- noStroke();
- fill(col);
- ellipse(pos.x, pos.y, size, size);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement