Skip to content

Commit

Permalink
hacking on a pulsar thingy....
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Carpenter committed Jun 26, 2012
1 parent 2ca6fb2 commit 519f3b7
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 7 deletions.
7 changes: 5 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
//

//$GLOBALS
var $canvas = null, $2d = null;
var $canvas = null, $2d = null, $num_pendulums = 15;

//lists
var $objects = [], $pendulums = [], $algorithms = [];
Expand All @@ -49,7 +49,7 @@

// build out some pendulums
var j;
for (i = 0; i < 15; i ++) {
for (i = 0; i < $num_pendulums; i ++) {
j = new pendulum( 650, 100, i, 160, 51 - i )
$pendulums.push( j );
}
Expand Down Expand Up @@ -88,6 +88,9 @@
//dirty, dirty, dirty hack...
gradienter.checked = true;
gradienter.onclick({target: gradienter});
} else {
$movement = false;
sort();
}


Expand Down
81 changes: 76 additions & 5 deletions pulsar.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,90 @@
function pulsar_callback(ball, position, tick){
if (window.$puslar == null)
if (window.$pulsar == null) {
window.$pulsar = new pulsar();
}

window.$pulsar.tick(ball, position, tick);
$pulsar.tick(ball, position, tick);
}

function pulsar(){
// delay between pulses
this.pulse_delay = 400;
// config variables
this.pulse_delay = 40;
this.pulse_step = 10;
this.pulse_trail = false; //TODO

// state variables
this.pulsing = false;
this.pulse_position = 0;
this.last_pulse_started = 0;

this.pulses = [];
for (i = 0; i < $num_pendulums; i++)
this.pulses[i] = {on: false, fixed: false, decay: 10}


this.tick = pulsar_tick;
this.new_pulse = pulsar_new_pulse;
this.increment_pulses = pulsar_increment_pulses;
}

function pulsar_tick(ball, position, tick){
ball.color.hsl(1,1,1);

if (position == 0){
//fire a pulse
if (!this.pulsing && tick - this.last_pulse_started >= this.pulse_delay) {
this.pulsing = true;
this.last_pulse_started = tick;
}

if (tick % this.pulse_delay == 0)
this.new_pulse();

this.increment_pulses(ball, position, tick);
}

ball.color.rgb(45,45,45);

if (this.pulses[position].on){
ball.color.rgb(155,155,155);
}

}

function pulsar_new_pulse(){
this.pulses[this.pulses.length - 1] = {on: true, fixed: false, decay: 10}
}

function pulsar_increment_pulses(ball, position, tick){
if (tick % this.pulse_step == 0){
//if the next one in the series isn't on, move this one there
for (i = 0; i < this.pulses.length; i ++){
if (i == 0){
if (this.pulses[i].on)
this.pulses[i].fixed = true;
}

if (this.pulses[i].fixed) {
this.pulses[i].decay --;

if (this.pulses[i].decay < 0)
this.pulses[i] = {on: false, fixed: false, decay: 10}

continue;
}


if (this.pulses[i].on){
if (!this.pulses[i - 1].on) {
this.pulses[i - 1].on = true;
this.pulses[i].on = false;
}

if (this.pulses[i - 1].fixed){
this.pulses[i].fixed = true;
}
}
}
}
}

if (window.$algorithms)
Expand Down

0 comments on commit 519f3b7

Please sign in to comment.