Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Delete night sky, add color drop.

  • Loading branch information...
commit f61de0eebbaff6fda8e24f45a24cda7e4e6c9223 1 parent 74e683c
Matthew Mets cibomahto authored

Showing 2 changed files with 42 additions and 93 deletions. Show diff stats Hide diff stats

  1. +42 0 ColorDrop.pde
  2. +0 93 NightSky.pde
42 ColorDrop.pde
... ... @@ -0,0 +1,42 @@
  1 +class ColorDrop extends Routine {
  2 + void draw() {
  3 + background(0);
  4 +
  5 + float frame_mult = 3; // speed adjustment
  6 +
  7 + long frame = frameCount - modeFrameStart;
  8 +
  9 + for(int row = 0; row < height; row++) {
  10 + float phase = sin((float)((row+frame*frame_mult)%height)/height*3.146);
  11 +
  12 + float r = 0;
  13 + float g = 0;
  14 + float b = 0;
  15 +
  16 +
  17 + if((row+frame*frame_mult)%(3*height) < height) {
  18 + r = 255*phase;
  19 + g = 0;
  20 + b = 0;
  21 + }
  22 + else if((row+frame*frame_mult)%(3*height) < height*2) {
  23 + r = 0;
  24 + g = 255*phase;
  25 + b = 0;
  26 + }
  27 + else {
  28 + r = 0;
  29 + g = 0;
  30 + b = 255*phase;
  31 + }
  32 +
  33 + stroke(r,g,b);
  34 + line(0, row, width, row);
  35 + }
  36 +
  37 + if (frame > FRAMERATE*TYPICAL_MODE_TIME) {
  38 + newMode();
  39 + }
  40 + }
  41 +
  42 +}
93 NightSky.pde
... ... @@ -1,93 +0,0 @@
1   -class NightSky extends Routine {
2   - int NUMBER_OF_STARS = 30;
3   - NightStar[] nightStars;
4   - PImage grad;
5   -
6   - void setup(PApplet parent) {
7   - super.setup(parent);
8   -
9   - color c1 = color(0, 0, 20);
10   - color c2 = color(0, 20, 60);
11   - grad = generateGradient(c1, c2, WIDTH*ZOOM, HEIGHT*ZOOM);
12   -
13   - nightStars = new NightStar[NUMBER_OF_STARS];
14   - for (int i=0; i<NUMBER_OF_STARS; i++) {
15   - nightStars[i] = new NightStar();
16   - }
17   - }
18   -
19   - void draw() {
20   - background(0);
21   - image(grad, 0, 0);
22   - noStroke();
23   - fill(0, 20, 0);
24   - rect(0, HEIGHT*ZOOM * 0.7, WIDTH*ZOOM, HEIGHT*ZOOM * 0.3);
25   - for (int i=0; i<NUMBER_OF_STARS; i++) {
26   - nightStars[i].draw();
27   - }
28   -
29   - if (frameCount - modeFrameStart > FRAMERATE*TYPICAL_MODE_TIME) {
30   - newMode();
31   - }
32   - }
33   -
34   - // Generate a vertical gradient image
35   - PImage generateGradient(color top, color bottom, int w, int h) {
36   - int tR = (top >> 16) & 0xFF;
37   - int tG = (top >> 8) & 0xFF;
38   - int tB = top & 0xFF;
39   - int bR = (bottom >> 16) & 0xFF;
40   - int bG = (bottom >> 8) & 0xFF;
41   - int bB = bottom & 0xFF;
42   -
43   - PImage bg = createImage(w,h,RGB);
44   - bg.loadPixels();
45   - for(int i=0; i < bg.pixels.length; i++) {
46   - int y = i/bg.width;
47   - float n = y/(float)bg.height;
48   - // for a horizontal gradient:
49   - // float n = x/(float)bg.width;
50   - bg.pixels[i] = color(
51   - lerp(tR,bR,n),
52   - lerp(tG,bG,n),
53   - lerp(tB,bB,n),
54   - 255);
55   - }
56   - bg.updatePixels();
57   - return bg;
58   - }
59   -}
60   -
61   -class NightStar {
62   - float x;
63   - float y;
64   - int brightness;
65   - public NightStar() {
66   - this.reset();
67   - }
68   -
69   - public void draw() {
70   -
71   - noStroke();
72   - this.twinkle();
73   - fill(brightness);
74   - rect(x, y, 1, 1);
75   -
76   - }
77   -
78   - public void twinkle() {
79   - brightness = brightness + round(random(-20, 20));
80   - if(brightness > 255){
81   - brightness = 255;
82   - }
83   - }
84   -
85   - public void reset() {
86   - x = random(WIDTH*ZOOM);
87   - y = random(HEIGHT*ZOOM) * 0.7;
88   - println("New star " + x + "/" + y + " ");
89   - }
90   -
91   -}
92   -
93   -

0 comments on commit f61de0e

Please sign in to comment.
Something went wrong with that request. Please try again.