Advertisement
AlexandraTs

Android Processing LGBT Flow

Sep 28th, 2022 (edited)
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.97 KB | None | 0 0
  1. /*
  2.  
  3. * README:
  4.  
  5. * Paste all of this code into APDE, and change the export mode to wallpaper before hitting play (Android only).
  6.  
  7. * When your device restarts/shuts down the background may freeze. simply go into APDE and hit play again
  8.  
  9. * Line 69: Changes the time a flag will stay on screen
  10.  
  11. * line 71: Changes the amount of time the transition between two flags takes
  12.  
  13. * line 127: the amount of stars that go trough the screen
  14.  
  15. * Lines 112-121: What flags will be shown. delete the lines with the flags you don't want
  16.  
  17. * lines 131-137 : The sizes of the stars and the twinkles
  18.  
  19. * stars are what goes trough the screen to recolor it
  20.  
  21. * twinkles are what is created when you tap the screen
  22.  
  23. * to make the background more subtle delete the */ /* on line 159, but keep background(0, 0, 0);
  24.  
  25. * to make the twinkles not appear, remove line 282
  26.  
  27. */
  28.  
  29. ArrayList<Twinkle> twinkles;
  30.  
  31. Star[] stars;
  32.  
  33. color[] colors;
  34.  
  35. ArrayList<colorArr> totalColors;
  36.  
  37. int twinkleDeletionTimer;
  38.  
  39. int colorIndex;
  40.  
  41. int colorChangeTimer;
  42.  
  43. int colorChangeTimerConst;
  44.  
  45. int colorMixTimerConst;
  46.  
  47. int minimumStarSize;
  48.  
  49. int maximumStarSize;
  50.  
  51. int minimumTwinkleSize;
  52.  
  53. int maximumTwinkleSize;
  54.  
  55. /*****/
  56.  
  57. void setup() {
  58.  
  59. fullScreen();
  60.  
  61. twinkles = new ArrayList<Twinkle>();
  62.  
  63. twinkleDeletionTimer=0;
  64.  
  65. colorIndex = 0;
  66.  
  67. colorChangeTimer = 0;
  68.  
  69. colorChangeTimerConst = 2000; /*time that a flag will stay on the screen*/
  70.  
  71. colorMixTimerConst = 200; /*time that the transition between 2 flags will happen*/
  72.  
  73. /*genderfluid*/
  74.  
  75. color[] genderfluid = { color(255, 118, 163), color(255, 255, 255), color(191, 17, 215), color(0, 0, 0), color(48, 60, 190) };
  76.  
  77. /*trans*/
  78.  
  79. color[] transgender = { color(91, 207, 250), color(245, 171, 185), color(255, 255, 255), color(245, 171, 185), color(91, 207, 250) };
  80.  
  81. /* bi*/
  82.  
  83. color[] bi = { color(214, 2, 112), color(214, 2, 112), color(155, 79, 151), color(0, 56, 167), color(0, 56, 167) };
  84.  
  85. /*lesbian*/
  86.  
  87. color[] lesbian = { color(213, 45, 0), color(255, 154, 86), color(255, 255, 255), color(211, 98, 164), color(163, 2, 98) };
  88.  
  89. /*LGBT*/
  90.  
  91. color[] ogLGBT = { color(254, 0, 36), color(255, 123, 0), color(255, 240, 0), color(0, 98, 166), color(132, 0, 148) };
  92.  
  93. /*gay*/
  94.  
  95. color[] gay = { color(4, 144, 109), color(36, 206, 169), color(255, 255, 255), color(77, 75, 202), color(59, 26, 117) };
  96.  
  97. /*aro*/
  98.  
  99. color[] aro = { color(61, 165, 66), color(167, 211, 121), color(255, 255, 255), color(169, 169, 169), color(0, 0, 0) };
  100.  
  101. /*ace*/
  102.  
  103. color[] ace = { color(0, 0, 0), color(169, 169, 169), color(255, 255, 255), color(208, 121, 211), color(126, 0, 126) };
  104.  
  105. /*enby*/
  106.  
  107. color[] enby = { color(255, 244, 51), color(255, 255, 255), color(155, 89, 208), color(45, 45, 45), color(45, 45, 45) };
  108.  
  109.  
  110. /*Design?*/
  111.  
  112. totalColors = new ArrayList<colorArr>();
  113. totalColors.add(new colorArr(transgender));
  114. totalColors.add(new colorArr(genderfluid));
  115. totalColors.add(new colorArr(bi));
  116. totalColors.add(new colorArr(lesbian));
  117. totalColors.add(new colorArr(ogLGBT));
  118. totalColors.add(new colorArr(gay));
  119. totalColors.add(new colorArr(aro));
  120. totalColors.add(new colorArr(ace));
  121. totalColors.add(new colorArr(enby));
  122.  
  123. colors = totalColors.get(0).getArr();
  124.  
  125. /*Amount of Stars?*/
  126.  
  127. int starCount = 1000;
  128.  
  129. /*Size of Stars and Twinkles*/
  130.  
  131. minimumStarSize = 5;
  132.  
  133. maximumStarSize = 8;
  134.  
  135. minimumTwinkleSize = 3;
  136.  
  137. maximumTwinkleSize = 5;
  138.  
  139.  
  140.  
  141. stars = new Star[starCount];
  142.  
  143. for (int i = 0; i < starCount; i++) {
  144.  
  145. stars[i] = new Star();
  146.  
  147. }
  148.  
  149. }
  150.  
  151.  
  152.  
  153. /*****/
  154.  
  155.  
  156.  
  157. void draw() {
  158.  
  159. /*background(0, 0, 0);*/
  160.  
  161.  
  162.  
  163. for (Star s : stars) {
  164.  
  165. s.update();
  166.  
  167. s.display();
  168.  
  169. }
  170.  
  171.  
  172.  
  173. /*println(twinkles.size(), frameRate);*/
  174.  
  175. for (Twinkle t : twinkles) {
  176.  
  177. t.update();
  178.  
  179. t.display();
  180.  
  181. }
  182. if(colorChangeTimer < colorChangeTimerConst){
  183. colorChangeTimer+=1;
  184. }else if(colorChangeTimer > (colorChangeTimerConst + colorMixTimerConst)){
  185. colorChangeTimer = 0;
  186. colorIndex = (colorIndex+1) % totalColors.size();
  187. colors = totalColors.get(colorIndex).getArr();
  188. }else{
  189. colorChangeTimer+=1;
  190. color[] left = totalColors.get(colorIndex).getArr();
  191. color[] right = totalColors.get((colorIndex+1)%(totalColors.size())).getArr();
  192. float y = colorChangeTimer - colorChangeTimerConst;
  193. y /= colorMixTimerConst;
  194. y = constrain(y, 0.0, 1.0);
  195. color[] tempColors = {
  196. lerpColor(left[0], right[0], y),
  197. lerpColor(left[1], right[1], y),
  198. lerpColor(left[2], right[2], y),
  199. lerpColor(left[3], right[3], y),
  200. lerpColor(left[4], right[4], y),
  201. };
  202. colors = tempColors;
  203. }
  204.  
  205.  
  206. if(twinkleDeletionTimer>60){ /*once every 60 ticks, remove the dead twinkles.*/
  207.  
  208.  
  209.  
  210. int size=twinkles.size();
  211.  
  212. boolean move=true;
  213.  
  214. int i;
  215.  
  216.  
  217.  
  218. for(i=0 ; ((i<size)&&move);++i){
  219.  
  220.  
  221.  
  222. Twinkle t1=twinkles.get(i);
  223.  
  224. Twinkle t2=twinkles.get(size-1-i);
  225.  
  226.  
  227.  
  228. if(!t1.isDead()){
  229.  
  230. move=false;
  231.  
  232. i=size-1-i;
  233.  
  234. }
  235.  
  236. if(t2.isDead()){
  237.  
  238. i=i-1;
  239.  
  240. move=false;
  241.  
  242. }
  243.  
  244.  
  245.  
  246. if(move){
  247.  
  248. twinkles.set(i,t2); /*move a living twinkle to the front of the array from the back*/
  249.  
  250. }
  251.  
  252.  
  253.  
  254. }
  255.  
  256.  
  257.  
  258. for(int j=size-1;j>i;j--){
  259.  
  260. twinkles.remove(j); /*remove all the dead twinkles that are now at the back*/
  261.  
  262. }
  263.  
  264.  
  265.  
  266. twinkleDeletionTimer=0;
  267.  
  268. }else{
  269.  
  270. twinkleDeletionTimer+=1;
  271.  
  272. }
  273.  
  274. }
  275.  
  276.  
  277.  
  278. /******/
  279.  
  280. void mouseDragged() {
  281.  
  282. for (int i = 0; i < 3; i++) twinkles.add(new Twinkle(mouseX, mouseY)); /*add twinkles when dragging screen*/
  283.  
  284. }
  285.  
  286.  
  287.  
  288. /*Color Stuff*/
  289.  
  290. public color getColor(float y,float fixed_rand) {
  291.  
  292. float gradient = 40;
  293.  
  294. y += (fixed_rand-0.5)*gradient; /*randomize a bit*/
  295.  
  296. y = constrain(y, 0, height-1); /*keep value inside of screen*/
  297.  
  298. y /= height; /*put between 0 and 1*/
  299.  
  300. y *= colors.length-1; /*make valid for array*/
  301.  
  302. int yi=int(y);
  303.  
  304. color c = lerpColor(colors[yi], colors[yi+1], y%1); /*fade between colors*/
  305.  
  306. return c;
  307.  
  308. }
  309.  
  310.  
  311.  
  312. /*normal Tangent*/
  313.  
  314. public PVector nTangent(PVector center, PVector point){
  315.  
  316. PVector tangent=new PVector(center.y-point.y,point.x-center.x);
  317.  
  318. return tangent.normalize();
  319.  
  320. }
  321.  
  322.  
  323.  
  324. /*hard constrain*/
  325.  
  326. public float hardConstrain(float num,float min, float max){
  327.  
  328. float res=num-min;
  329.  
  330. if(res<0){res=max-min; }
  331.  
  332.  
  333.  
  334. else if(res>(max-min)){res=0; }
  335.  
  336.  
  337.  
  338. return (res+min);
  339.  
  340. }
  341.  
  342.  
  343.  
  344. /*distance*/
  345.  
  346. public float distance(PVector p1, PVector p2){
  347.  
  348. PVector dist= p1.copy();
  349.  
  350. dist.sub(p2);
  351.  
  352. return dist.mag();
  353.  
  354. }
  355.  
  356.  
  357.  
  358. class Twinkle {
  359.  
  360. PVector pos;
  361.  
  362. PVector vel = new PVector();
  363.  
  364.  
  365.  
  366. color col;
  367.  
  368. float size;
  369.  
  370. float alpha = 0;
  371.  
  372.  
  373.  
  374. float startSpeed = 6;
  375.  
  376.  
  377.  
  378. Twinkle(float x, float y) {
  379.  
  380. pos = new PVector(x, y);
  381.  
  382.  
  383.  
  384. /*randomness*/
  385.  
  386. /*movement*/
  387.  
  388. float randRad = 20;
  389.  
  390. PVector rand = PVector.random2D();
  391.  
  392. pos.add(rand.copy().mult(randRad));
  393.  
  394. vel.add(rand.mult(startSpeed*random(1.0f)));
  395.  
  396. /*appearance*/
  397.  
  398. col = getColor(pos.y,random(1.0f));
  399.  
  400. size = random(minimumTwinkleSize, maximumTwinkleSize);
  401.  
  402. }
  403.  
  404.  
  405.  
  406. void update() {
  407.  
  408. pos.add(vel);
  409.  
  410. vel.mult(0.95);
  411.  
  412.  
  413.  
  414. float sX = map(vel.mag(), startSpeed, 0, -PI/2, 3*PI/2);
  415.  
  416. float s = ((sin(sX)+1)/2)*255;
  417.  
  418. alpha = s;
  419.  
  420. }
  421.  
  422.  
  423.  
  424. void display() {
  425.  
  426. ellipseMode(CENTER);
  427.  
  428. noStroke();
  429.  
  430. fill(red(col), green(col), blue(col), alpha);
  431.  
  432. ellipse(pos.x, pos.y, size, size);
  433.  
  434. }
  435.  
  436.  
  437.  
  438. boolean isDead(){
  439.  
  440. return (vel.mag()<0.01);
  441.  
  442. }
  443.  
  444. }
  445.  
  446. public PVector center= new PVector(-150,-150);
  447.  
  448. public float b_width=10; /*border width*/
  449.  
  450.  
  451.  
  452. class Star {
  453.  
  454. PVector pos = new PVector();
  455.  
  456. float speed;
  457.  
  458. float fixed_rand;
  459.  
  460. color col;
  461.  
  462. float size;
  463.  
  464.  
  465.  
  466. Star() {
  467.  
  468. pos.set(random(-b_width,width+b_width), random(-b_width,height+b_width));
  469.  
  470.  
  471.  
  472. speed=random(0.125,0.25);
  473.  
  474. fixed_rand=random(1.0f);
  475.  
  476. col = getColor(pos.y,fixed_rand);
  477.  
  478. minimumStarSize = 5;
  479.  
  480. maximumStarSize = 7;
  481.  
  482. minimumTwinkleSize = 3;
  483.  
  484. maximumTwinkleSize = 5;
  485.  
  486. size = random(minimumStarSize, maximumStarSize);
  487.  
  488. }
  489.  
  490.  
  491.  
  492. void update() {
  493.  
  494. col = getColor(pos.y,fixed_rand);
  495.  
  496. PVector tang=nTangent(center,pos);
  497.  
  498. tang.mult((float)(speed*Math.log(distance(center,pos))));
  499.  
  500. pos.add(tang);
  501.  
  502. pos.x=hardConstrain(pos.x,-b_width,width+b_width);
  503.  
  504. pos.y=hardConstrain(pos.y,-b_width,height+b_width);
  505.  
  506. }
  507.  
  508.  
  509.  
  510. void display() {
  511.  
  512. ellipseMode(CENTER);
  513.  
  514. noStroke();
  515.  
  516. fill(col);
  517.  
  518. ellipse(pos.x, pos.y, size, size);
  519.  
  520. }
  521.  
  522. }
  523.  
  524. class colorArr{
  525. color[] arr;
  526. colorArr(color[] temp)
  527. {
  528. arr = temp;
  529. }
  530. color[] getArr()
  531. {
  532. return arr;
  533. }
  534. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement