Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
allwinwilliams committed Nov 27, 2020
1 parent b12da79 commit d787eb1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 44 deletions.
29 changes: 12 additions & 17 deletions firework.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
// Daniel Shiffman
// http://codingtra.in
// https://youtu.be/CKeyIbT3vXI
const HUE_MIN = 0;
const HUE_MAX = 255;

class Firework {
constructor(sketch, x, y, z, gravity, hu1, hu2, namelength, fw) {
constructor(sketch, x, y, z, gravity, namelength, fw) {
this.sketch = sketch;
this.hu1 = hu1*namelength/20; // colour range
this.hu2 = hu2;
this.x = x;
this.y = y;
this.hu1 = sketch.map(this.x, -MAP_WIDTH/2, MAP_WIDTH/2, HUE_MIN, HUE_MAX); // colour range
this.hu2 = sketch.map(this.y, -MAP_HEIGHT/2, MAP_HEIGHT/2, HUE_MIN, HUE_MAX);
this.namelength = namelength;
this.firework = new Particle(this.sketch, x, 0, y, this.namelength, fw, z); // starting point
this.exploded = false;
this.particles = [];
this.x = x;
this.y = y;

this.burst_height = z;
this.gravity = gravity;
}

done() {
if (this.exploded && this.particles.length === 0) {
return true;
} else {
return false;
}
return this.exploded && this.particles.length === 0;
}

update() {
Expand All @@ -35,7 +34,6 @@ class Firework {
this.explode();
}
}

_.map(this.particles, (particle, index) => {
// particle.applyForce(gravity); // falls after bursting
particle.update();
Expand All @@ -44,24 +42,21 @@ class Firework {
}

explode() {

let n = this.sketch.int(this.sketch.map(this.y + this.namelength*10, -MAP_HEIGHT/2, MAP_HEIGHT/2 + 200, 1, 7)); // SHAPE - spokes
let d = this.sketch.int(this.sketch.map (this.x, -MAP_WIDTH/2, MAP_WIDTH/2, 1, 7)); // SHAPE - loops
for (let i = 0; i < 241; i++) // no. of particles
{
for (let i = 0; i < 241; i++) {
const p = new Particle(this.sketch, this.firework.pos.x, this.firework.pos.y, this.firework.pos.z, false, i, n, d);
this.particles.push(p);
}
}

show() {
let col;
if (!this.exploded) {
if(!this.exploded){
this.firework.show();
}

_.map(this.particles, (particle, index) => {
particle.show((index % 2 == 0)? this.hu1 : this.hu2);
})
});
}
}
17 changes: 5 additions & 12 deletions individual.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
var userSketch = function(sketch){
let firework;
let gravity;
let col = true;
let start_x; let start_y; let burst_height;
let start_x, start_y, burst_height;

sketch.setup =function() {
sketch.createCanvas(250, 250, sketch.WEBGL);
Expand Down Expand Up @@ -37,24 +35,19 @@ var userSketch = function(sketch){
location.firework.show();
return;
}

let {name, long, lat, time} = location;
let user_time = new Date(time);
let current_time = new Date();
let last_time = new Date();
last_time.setDate(last_time.getDate() - 1);
last_time.setDate(last_time.getDate() - 0.5);
burst_height = sketch.map(user_time.getTime(), last_time.getTime(), current_time.getTime(), TIME_MIN, TIME_MAX);

let name_value = sketch.nameProcessing(name);
start_x = sketch.map(long, LONG_MIN, LONG_MAX, -MAP_WIDTH/2, MAP_WIDTH/2);
start_y = sketch.map(lat, LAT_MAX, LAT_MIN, -MAP_HEIGHT/2, MAP_HEIGHT/2);
burst_height = sketch.map(user_time.getTime(), last_time.getTime(), current_time.getTime(), TIME_MIN, TIME_MAX);
// console.log(burst_height);
let hu1 = sketch.map(long, LONG_MIN, LONG_MAX, HUE_MIN, HUE_MAX);
let hu2 = sketch.map(lat, LAT_MIN, LAT_MAX, HUE_MIN, HUE_MAX);
let nl = sketch.nameProcessing(name);
console.log("namelength "+nl);

location.firework = new Firework(sketch, start_x, start_y, burst_height, gravity, hu1, hu2, nl, true);
location.firework = new Firework(sketch, start_x, start_y, burst_height, gravity, name_value, true);
location.added = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions particle.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Particle {
} else {
this.sketch.angleMode(this.sketch.RADIANS);
this.vel = rose(this.sketch, this.sketch.map(index, 0, 120, 0, this.sketch.PI*4), this.sketch.map(index, 0,120, -2*this.sketch.PI, 2*this.sketch.PI), n, d);
this.vel.mult(2); // explode form
this.vel.mult(1); // explode form
}
}

Expand Down Expand Up @@ -57,7 +57,7 @@ class Particle {
this.sketch.colorMode(this.sketch.HSB);

if (!this.firework) { // for the burst
this.sketch.strokeWeight(10);
this.sketch.strokeWeight(3);
this.sketch.stroke(col, 255, 255, this.lifespan); //[HSB, Alpha]

} else { // for the rocket
Expand Down
17 changes: 16 additions & 1 deletion service.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,22 @@ firebase.analytics();
let database = firebase.database();

function storeUser(name, lat, long, time) {
firebase.database().ref('users').push({
let stored = firebase.database().ref('users').push({
name,
lat,
long,
time
});
current_user.key = stored.key;
current_user.added = false;
}

function updateUser(key, name, lat, long, time){
// var updates = {};
// updates['/users/' + key] = postData;
// updates['/user-posts/' + uid + '/' + newPostKey] = postData;
//
firebase.database().ref(`/users/${key}`).update({
name,
lat,
long,
Expand Down
20 changes: 8 additions & 12 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const LONG_MIN = 69;
const LONG_MAX = 97;
const TIME_MIN = 0;
const TIME_MAX = 30;
const HUE_MIN = 0;
const HUE_MAX = 255;

const CANVAS_WIDTH = 0;
const CANVAS_HEIGHT = 0;
Expand All @@ -14,10 +12,8 @@ const MAP_WIDTH = 10 * (LONG_MAX - LONG_MIN);
const MAP_HEIGHT = 10 * (LAT_MAX - LAT_MIN);

var indiaSketch = function(sketch){
let fireworks = [];
let gravity;
let col = true;
let start_x; let start_y; let burst_height;
let start_x, start_y, burst_height;

sketch.preload = function() {
img = sketch.loadImage('indiamap.png');
Expand Down Expand Up @@ -73,17 +69,17 @@ var indiaSketch = function(sketch){
let current_time = new Date();
let last_time = new Date();
last_time.setDate(last_time.getDate() - 1);
burst_height = sketch.map(user_time.getTime(), last_time.getTime(), current_time.getTime(), TIME_MIN, TIME_MAX);

if(burst_height < 0){
return;
}

let name_value = sketch.nameProcessing(name);
start_x = sketch.map(long, LONG_MIN, LONG_MAX, -MAP_WIDTH/2, MAP_WIDTH/2);
start_y = sketch.map(lat, LAT_MAX, LAT_MIN, -MAP_HEIGHT/2, MAP_HEIGHT/2);
burst_height = sketch.map(user_time.getTime(), last_time.getTime(), current_time.getTime(), TIME_MIN, TIME_MAX);
// console.log(burst_height);
let hu1 = sketch.map(long, LONG_MIN, LONG_MAX, HUE_MIN, HUE_MAX);
let hu2 = sketch.map(lat, LAT_MIN, LAT_MAX, HUE_MIN, HUE_MAX);
let nl = sketch.nameProcessing(name);
console.log("namelength "+nl);
location.firework = new Firework(sketch, start_x, start_y, burst_height, gravity, hu1, hu2, nl, true);

location.firework = new Firework(sketch, start_x, start_y, burst_height, gravity, name_value, true);
location.added = true;
}

Expand Down

0 comments on commit d787eb1

Please sign in to comment.