Advertisement
Guest User

starry

a guest
May 15th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. float seed;
  2. float strokeWidth;
  3. void setup() {
  4.  
  5. size(800,500);
  6. background(0);
  7. seed = random(10000);
  8. strokeWidth = 15f/800*width;
  9. }
  10.  
  11. void draw() {
  12. if (strokeWidth > 1) {
  13. for (int i = 0; i < 100; i++)placeStroke(random(width), random(height), 15f/800*width, 15f/800*width);
  14. strokeWidth *= .85;
  15. }
  16. }
  17. void keyPressed() {
  18. if (key == 's') {
  19. saveFrame("this-####.jpg");
  20. } else {
  21. seed = random(10000);
  22. strokeWidth = 15f/800*width;
  23. }
  24. }
  25.  
  26. void dobackground() {
  27. for (float x = 0; x < width; x++) {
  28. }
  29. }
  30.  
  31. color backgroundColor(float x, float y) {
  32. color sky = color(#1339CE);
  33. color whitesky = color(#7993F0);
  34. float whiteskyfactor = noise(x*.005, y*.01, seed);
  35. whiteskyfactor -= .6;
  36. whiteskyfactor = smoothstep(-.1, .1, whiteskyfactor);
  37. sky = lerpColor(sky, whitesky, whiteskyfactor);
  38. color star = color(#EDED8B);
  39. float starfactor = noise(x*.005, y*.005, seed);
  40. starfactor = pow(starfactor, 1.7);
  41. starfactor = starfactor-.5;
  42. starfactor = smoothstep(-.03, .05, starfactor);
  43. sky = lerpColor(sky, star, starfactor);
  44. return sky;
  45. }
  46.  
  47.  
  48.  
  49. void placeStroke(float x, float y, float w, float h) {
  50. float rw = random(1)*w;
  51. float t = random(PI*2);
  52. for (float i = 0; i < rw; i++) {
  53.  
  54. t += PI*2/rw;
  55. pushMatrix();
  56. float rx, ry;
  57. rx = random(-w, w);
  58. ry = random(-h, h);
  59. translate(x, y);
  60. translate(rx, ry);
  61. rotate(t);
  62. strokeWeight(strokeWidth);
  63. translate(0, -h/2);
  64. color c =pickColor(rx+x, ry+y);
  65. color b = color(random(255));
  66. c = lerpColor(c,b,random(.2));
  67. stroke(c);
  68. line(0, 0, 0, h);
  69. popMatrix();
  70. }
  71. }
  72. float smoothstep(float edge0, float edge1, float t) {
  73. t =constrain((t-edge0)/(edge1-edge0), 0, 1);
  74. return t;
  75. }
  76.  
  77. color pickColor(float x, float y) {
  78. color c;
  79. float ny = noise(x*.015, seed);
  80. ny *= height;
  81. float d = y-ny-height/4;
  82. float mountainvssky = smoothstep(-20, 20, d);
  83. mountainvssky = smoothstep(0, 1, mountainvssky);
  84. color sky = color(#1339CE);
  85. color whitesky = color(#7993F0);
  86. float whiteskyfactor = noise(x*.005, y*.01, seed);
  87. whiteskyfactor -= .6;
  88. whiteskyfactor = smoothstep(-.1, .1, whiteskyfactor);
  89. sky = lerpColor(sky, whitesky, whiteskyfactor);
  90. color star = color(#EDED8B);
  91. float starfactor = noise(x*.005, y*.005, seed);
  92. starfactor = pow(starfactor, 1.7);
  93. starfactor = starfactor-.5;
  94. starfactor = smoothstep(-.03, .05, starfactor);
  95. sky = lerpColor(sky, star, starfactor);
  96. color mountain = color(#4E5262);
  97. mountain = lerpColor(mountain, color(0), smoothstep(height/2, height, y));
  98. c = sky;
  99. c = lerpColor(sky, mountain, mountainvssky);
  100. c = lerpColor(c, color(random(255), random(255), random(255)), .02);
  101. return c;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement