Star Lights



About this creative coding work.

This creative coding work draws star-shaped blinking neon lights.
It was made with Processing programming language and Kdenlive video editor.


Thanks to nice music:
No Rocking in the Jazzhands Zone by Peter Gresser
2013/08/15
http://freemusicarchive.org/music/Peter_Gresser/Reimagine_The_Game/No_Rocking_in_the_Jazzhands_Zone
No Rocking in the Jazzhands Zone by Peter Gresser is licensed under a CC0 1.0 Universal License.

Processing example code.

I tried to blink the lights with Gaussian distribution and Sigmoid function.

// Star Lights
// Processing 3.2.1
// 2017.03.12
import processing.opengl.*;
import java.util.Random;

World wd;
Star[] st;
int sline = 16;  // line number of stars
int scolumn = 19; // column number of stars
int divline = 320;
int divcolumn = 280;
int snum = sline * scolumn;

void setup() {
  size(1280, 720, OPENGL);
  colorMode(HSB, 256, 100, 100, 100);
  // blendMode(SCREEN);
  // hint(DISABLE_DEPTH_TEST);
  smooth();
  frameRate(30);

  wd = new World();
  st = new Star[snum];

  // noise for star rotation speed
  float nl = random(10);
  float nc = random(10);
  
  // star objects
  float w = 8; // stroke weight
  for (int l = 0; l < sline; l++) {
    for (int c = 0; c < scolumn; c++) {
      st[l * scolumn + c] = new Star(
                                     (c - scolumn / 2) * divcolumn,
                                     -l * divline,
                                     w,
                                     map(noise(nl, nc), 0, 1, 0, 1.2)
                                     );
      nc += 0.08;
    }
    w = w * 0.9;
    nl += 0.08;
  }
}

void draw() {

  wd.redraw();

  for (int i = 0; i < snum; i++) {
    if (frameCount % 100 == 0) {
      float rand100 = random(1000);
      if (rand100 < 15) {
        st[i].damaged();
      } else if (rand100 < 200) {
        st[i].repaired();
      }
    }
    st[i].onoff();
    st[i].rolling();
    st[i].drawlight();
  }

  wd.roll();

  /*
  filter( BLUR, 2 );

  saveFrame("frames/####.png");
  if (frameCount >= 631) {
    exit();
  }
  */

}

class World {
  float r_X;
  float r_Y;
  float r_Z;

  World() {
    r_X = 0;
    r_Y = 0;
    r_Z = 0;
  }

  void redraw() {
    background(0, 0, 5);
    //  translate(width / 2, height / 2, 0);

        lightFalloff(1.0, 0.01, 0.00003);
    // I have no idea
    ambientLight(0, 0, 100, -600, 400, -300);
    ambientLight(0, 0, 100,  600, 400, -300);
    ambientLight(0, 0, 100, -600, 400, -2000);
    ambientLight(0, 0, 100,  600, 400, -2000);

    //       camera(100, 200, 800,
    //           60, 0, 0,
    camera(-100 + r_X,     260 + r_Y, 300 - r_Z,
           -30  - r_X / 3, 60  + r_Y, -r_Z,
           0, 1, 0);
  }

  void roll() {
    r_X += 0.15;
    r_Y += 0.18;
    r_Z += 0.20;
  }

}

class Star {
  int vertex_num;
  float vertex_radius, vertex_radian;
  Random obj_random;
  float scolor, ssatur, sbright;
  float on_easy, on_curve;
  float sx, sz, sweight;
  float sroll, slippy_sr, noise_sr;

  Star(float x, float z, float w, float s) {
    obj_random = new Random();
    vertex_num = 10;
    vertex_radian = radians(-customnoise(90, 92, 2));
    vertex_radius = 60;
    scolor = customnoise(35, 38, 3);
    ssatur = customnoise(30, 38, 8);
    sbright = 0.5;
    if (random(100) < 6) {
      damaged();
    } else {
      repaired();
    }
    sx = x;
    sz = z;
    sweight = w;
    sroll = customnoise(5, 45, 40);
    slippy_sr = s;
    noise_sr = random(100);
  }

  void damaged() {
    on_easy = random(0.5, 1.0);
    on_curve = random(0.8, 1.2);
  }

  void repaired() {
    on_easy = 0.2;
    on_curve = 1.0;
  }

  void onoff() {
    sbright = 100 * sigmoid(customnoise(sbright / 100, 1, 1), on_easy, on_curve);
  }

  void rolling() {
    sroll += map(noise(noise_sr), 0, 1, -slippy_sr, slippy_sr);
    noise_sr += 0.05;
  }

  void drawlight() {

    // hanging wire
    pushMatrix();
    translate(sx, -vertex_radius * 5, sz - 2);
    noStroke();
    fill(
         0,
         0,
         100,
         100
         );
    box(3, vertex_radius * 8, 3);
    popMatrix();

    // star light
    pushMatrix();
    translate(sx, 0, sz);
    rotateZ(vertex_radian);
    rotateX(radians(sroll));
    noFill();
    strokeWeight(sweight);
    stroke(
           scolor,
           ssatur,
           sbright * 0.8,
           100
           );
    starcurve();
    popMatrix();

  }

  void starcurve() {

    float vertex_r = 0;

    beginShape();
    for (int i = 0; i <= vertex_num + 2; ++i) {
      if (i%2 == 0) {
        vertex_r = vertex_radius;
      } else {
        vertex_r = vertex_radius / 1.8;
      }
      curveVertex(
                  vertex_r * cos(radians(360/vertex_num * i)),
                  vertex_r * sin(radians(360/vertex_num * i))
                  );
    }
    endShape(CLOSE);
  }

  // normal distribution
  float customnoise(float value, float limit, float divide) {
    float seed = value;
    float gauss = 0;
    gauss = (float) obj_random.nextGaussian() * divide;
    seed += gauss;

    if (abs(seed) >= limit) {
      seed = value * (limit - divide) / limit;
    }

    return seed;
  }

  // sigmoid function
  float sigmoid(float x, float a, float b) {
    float modx = a * (x - 1) + 1;
    return (float)(1.0 / (1.0 + Math.exp(-modx * b)));
  }

}


/*
Copyright (C) 2017- deconbatch

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see 
*/





Next Post Previous Post
No Comment
Add Comment
comment url