Advertisement
petarts

stars

Apr 13th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. /*
  2. * How to use:
  3. * 1. Download APDE
  4. * 2. Launch it and paste this code in there.
  5. * 3. Press the Button right of the play button and select "wallpaper"
  6. * 4. Press play -> install -> select as wallpaper
  7. *
  8. * Original Source Code provided by u/throwaway-8979323
  9. * https://pastebin.com/TWdVNTfq
  10. *
  11. * Current version is by u/petarts
  12. * https://pastebin.com/Fn8LwxNq
  13. */
  14.  
  15. ArrayList<Twinkle> twinkles = new ArrayList<Twinkle>();
  16. Star[] stars;
  17.  
  18. color[] colors;
  19.  
  20. //***
  21. void setup() {
  22. fullScreen();
  23.  
  24. //genderfluid
  25. color[] genderfluid = { color(255, 118, 163), color(255, 255, 255), color(191, 17, 215), color(0, 0, 0), color(48, 60, 190) };
  26. //trans
  27. color[] transgender = { color(91, 207, 250), color(245, 171, 185), color(255, 255, 255), color(245, 171, 185), color(91, 207, 250) };
  28.  
  29. //Design?
  30. colors = transgender;
  31.  
  32. //Amount of Stars?
  33. int starCount = 1000;
  34.  
  35. stars = new Star[starCount];
  36. for (int i = 0; i < starCount; i++) {
  37. stars[i] = new Star();
  38. }
  39. }
  40.  
  41. //***
  42. int tick=0;
  43. void draw() {
  44. background(0, 0, 0);
  45.  
  46. for (Star s : stars) {
  47. s.update();
  48. s.display();
  49. }
  50.  
  51. //println(twinkles.size(), frameRate);
  52. for (Twinkle t : twinkles) {
  53. t.update();
  54. t.display();
  55. }
  56.  
  57.  
  58. if(tick>60){ //once every 60 ticks, remove the dead twinkles.
  59.  
  60. int size=twinkles.size();
  61. boolean move=true;
  62. int i;
  63.  
  64. for(i=0 ; ((i<size)&&move);++i){
  65.  
  66. Twinkle t1=twinkles.get(i);
  67. Twinkle t2=twinkles.get(size-1-i);
  68.  
  69. if(!t1.isDead()){
  70. move=false;
  71. i=size-1-i;
  72. }
  73. if(t2.isDead()){
  74. i=i-1;
  75. move=false;
  76. }
  77.  
  78. if(move){
  79. twinkles.set(i,t2); //move a living twinkle to the front of the array from the back
  80. }
  81.  
  82. }
  83.  
  84. for(int j=size-1;j>i;j--){
  85. twinkles.remove(j); //remove all the dead twinkles that are now at the back
  86. }
  87.  
  88. tick=0;
  89. }else{
  90. tick+=1;
  91. }
  92. }
  93.  
  94. //***
  95. void mouseDragged() {
  96. for (int i = 0; i < 3; i++) twinkles.add(new Twinkle(mouseX, mouseY)); //add twinkles when dragging screen
  97. }
  98.  
  99. //Color Stuff
  100. public color getColor(float y,float fixed_rand) {
  101. float gradient = 40;
  102. y += (fixed_rand-0.5)*gradient; //randomize a bit
  103. y = constrain(y, 0, height-1); //keep value inside of screen
  104. y /= height; //put between 0 and 1
  105. y *= colors.length-1; //make valid for array
  106. int yi=int(y);
  107. color c = lerpColor(colors[yi], colors[yi+1], y%1); //fade between colors
  108. return c;
  109. }
  110.  
  111. //normal Tangent
  112. public PVector nTangent(PVector center, PVector point){
  113. PVector tangent=new PVector(center.y-point.y,point.x-center.x);
  114. return tangent.normalize();
  115. }
  116.  
  117. //hard constrain
  118. public float hardConstrain(float num,float min, float max){
  119. float res=num-min;
  120. if(res<0){res=max-min; }
  121.  
  122. else if(res>(max-min)){res=0; }
  123.  
  124. return (res+min);
  125. }
  126.  
  127. //distance
  128. public float distance(PVector p1, PVector p2){
  129. PVector dist= p1.copy();
  130. dist.sub(p2);
  131. return dist.mag();
  132. }
  133.  
  134. class Twinkle {
  135. PVector pos;
  136. PVector vel = new PVector();
  137.  
  138. color col;
  139. float size;
  140. float alpha = 0;
  141.  
  142. float startSpeed = 2;
  143.  
  144. Twinkle(float x, float y) {
  145. pos = new PVector(x, y);
  146.  
  147. //randomness
  148. //movement
  149. float randRad = 200;
  150. PVector rand = PVector.random2D();
  151. pos.add(rand.copy().mult(randRad));
  152. vel.add(rand.mult(startSpeed));
  153. //appearance
  154. col = getColor(pos.y,random(1.0f));
  155. size = random(3, 5);
  156. }
  157.  
  158. void update() {
  159. pos.add(vel);
  160. vel.mult(0.95);
  161.  
  162. float sX = map(vel.mag(), startSpeed, 0, -PI/2, 3*PI/2);
  163. float s = ((sin(sX)+1)/2)*255;
  164. alpha = s;
  165. }
  166.  
  167. void display() {
  168. ellipseMode(CENTER);
  169. noStroke();
  170. fill(red(col), green(col), blue(col), alpha);
  171. ellipse(pos.x, pos.y, size, size);
  172. }
  173.  
  174. boolean isDead(){
  175. return (vel.mag()<0.01);
  176. }
  177. }
  178. public PVector center= new PVector(-150,-150);
  179. public float b_width=10; //border width
  180.  
  181. class Star {
  182. PVector pos = new PVector();
  183. float speed;
  184. float fixed_rand;
  185. color col;
  186. float size;
  187.  
  188. Star() {
  189. pos.set(random(-b_width,width+b_width), random(-b_width,height+b_width));
  190.  
  191. speed=random(0.125,0.25);
  192. fixed_rand=random(1.0f);
  193. col = getColor(pos.y,fixed_rand);
  194. size = random(5, 8);
  195. }
  196.  
  197. void update() {
  198. col = getColor(pos.y,fixed_rand);
  199. PVector tang=nTangent(center,pos);
  200. tang.mult((float)(speed*Math.log(distance(center,pos))));
  201. pos.add(tang);
  202. pos.x=hardConstrain(pos.x,-b_width,width+b_width);
  203. pos.y=hardConstrain(pos.y,-b_width,height+b_width);
  204. }
  205.  
  206. void display() {
  207. ellipseMode(CENTER);
  208. noStroke();
  209. fill(col);
  210. ellipse(pos.x, pos.y, size, size);
  211. }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement