Published
Edited
Nov 12, 2020
3 stars
Insert cell
Insert cell
//endtime = new Date("2020-09-13T19:17:50.316")
Insert cell
setdeadline = d3.timeMinute.offset(new Date(), 9).toString()
Insert cell
deadline = new Date("2020-11-11T20:15:40.579") //("Sun Sep 27 2020 17:00:00 GMT-0700 (Pacific Daylight Time)")
Insert cell
height = 300
Insert cell
Insert cell
Insert cell
Insert cell
enjasize = 10
Insert cell
enjaseconds = {
let diffSeconds = moment(userdl).diff(now, "seconds");
let diffMinutes = moment(userdl).diff(now, "minutes");
let diffSecondHand = d3.max([0, diffSeconds - diffMinutes * 60]);

let count = diffMinutes + diffSecondHand;

let xbScale = d3
.scaleBand()
.domain(d3.range(count))
.range([0, width]);

// let x = d3.scaleLinear()
// .domain([])
// .range([])

let colorscale = d3.scaleSequential(d3.interpolateMagma).domain([0, 40]);

let size = enjasize + 5;
let w = enjaSecondWidth;
let n = Math.floor(w / size);
let mins = d3.range(count).map(i => {
let c = d3.color(colorscale(initialCircles[i].random * count));
c.opacity = 0.2;
return {
clock: clocks[i % 12],
i,
// x: 25 + (i % n) * size,
// y: 25 + Math.floor(i / n) * size,
xb: xbScale(i),
yb: height - size, // - (diffSeconds % 10) * 10,
w: xbScale.bandwidth(),
// phase: Math.random() * 10,
color: c.toString()
};
});
return mins;
}
Insert cell
viewof enjalot = {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
let q5, el;
if (this) {
el = this;
q5 = this.value;
} else {
q5 = new Q5();
q5.createCanvas(width, height);
el = html`${q5.canvas}`;
el.value = q5;
}
yield el;
// invalidation.then(() => q5.clear());
q5.noStroke();

let x = width / 2;
let y = height / 2;
let px = x;
let py = y;
// q5.fill("rgba(255,255,255, 0.01)");
// q5.rect(0, 0, width, height);
while (true) {
// q5.tint(255, 0, 0, 100);
// q5.fill(colors[0]);
// q5.rect(-10, -10, width + 20, height + 20);

// q5.fill("rgba(255,255,255, 0.5)");
// q5.rect(0, 0, width, height);

// q5.rect(-10, -10, width + 20, height + 20);
// q5.clear();

enjaseconds.forEach(d => {
q5.fill(d.color);
q5.rect(d.xb, 0, d.w, d.yb);
});

yield el;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
Insert cell
colors
Insert cell
enjaSecondWidth = width - 50
Insert cell
clocks[0]
Insert cell
Insert cell
circleStepMax = 0.2
Insert cell
circleRadius = 70
Insert cell
Insert cell
viewof ej_15minute_canvas = {
let alpha = 0.5;

const q5 = new Q5();
q5.createCanvas(width, height);

q5.randomSeed();
const el = html`${q5.canvas}`;
el.value = q5;
yield el;
q5.noStroke();
// q5.strokeWeight(0);
// q5.stroke(0, 190);

// Text here

invalidation.then(() => q5.clear());

let x = width / 2;
let y = height / 2;
let px = x;
let py = y;

let circles = [];

const addCircle = function(i) {
circles.push({
x: chance.floating({ min: 50, max: width - 50 }),
y: height / 4 + chance.floating({ min: 0, max: height / 2 }),
fill: chance.pick(colors),
r: circleRadius * (i * 0.001)
});
};

for (let c = 0; c < 1200; c++) {
addCircle(c);
}

const simulation = d3
.forceSimulation(circles)
.force("charge", d3.forceManyBody().strength(-0.1));

while (true) {
// q5.background(255);
// q5.clear();
// q5.fill(colors[0]);
q5.fill("rgba(255,255,255, 0.05)");
q5.rect(0, 0, width, height);

let now = moment(new Date());
let diffSeconds = moment(userdl).diff(now, "seconds");
let diffMinutes = moment(userdl).diff(now, "minutes");
let diffSecondHand = d3.max([0, diffSeconds - diffMinutes * 60]);
// for (let i = 0; i < diffMinutes; i++) {
// const rndX = chance.floating({ min: 0, max: width });
// const rndY = chance.floating({ min: 0, max: height });
// q5.circle(rndX, rndY, 30);
// q5.fill(colors[2]);
// }
// for (let i = 0; i < diffSecondHand; i++) {
// const rndX = chance.floating({ min: 0, max: width });
// const rndY = chance.floating({ min: 0, max: height });
// q5.circle(rndX, rndY, 10);
// q5.fill("black");
// }

// circles = circles.slice(0, +diffSecondHand);
circles = circles.slice(0, +diffSeconds);

for (let i = 0; i < circles.length; i++) {
// q5.fill = chance.pick(colors)
q5.fill(circles[i].fill);
q5.circle(circles[i].x, circles[i].y, circles[i].r);
if (chance.bool({ likelihood: i * 0.01 })) {
circles[i].x += chance.floating({
min: -circleStepMax,
max: circleStepMax
});
}
if (chance.bool()) {
// let yMax = _.max([i / 100, height]);
// circles[i].y += chance.floating({ min: -1, max: yMax });
circles[i].y += chance.floating({
min: -circleStepMax,
max: circleStepMax * 1.5
});
}

if (circles[i].y > height) {
circles[i].y -= circleRadius * 1.5;
}
if (circles[i].x > width) {
circles[i].x = 0;
}
}
q5.textSize(220);
// q5.fill(colors[0]);
// q5.text(`${diffMinutes}:${pad(diffSecondHand, 2)}`, 100, 250);

q5.textSize(48);
// q5.text("TIME LEFT", width * 0.28, 70);
// q5.text(circles.length, width * 0.28, 70);
// q5.text(diffSecondHand, 180, 140);
yield el;
}
}
Insert cell
initialCircles = {
let circles = [];

const addCircle = function(i) {
circles.push({
x: chance.floating({ min: 0, max: width }),
y: chance.floating({ min: 0, max: height / 2 }),
fill: chance.pick(colors),
random: Math.random(),
r: circleRadius * (i * 0.001)
});
};

for (let c = 0; c < 1200; c++) {
addCircle(c);
}
return circles;
}
Insert cell
//
//https://stackoverflow.com/questions/10073699/pad-a-number-with-leading-zeros-in-javascript
function pad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
Insert cell
md`## Firebase stuff`
Insert cell
Insert cell
Insert cell
Insert cell
import { colors } from '@codingwithfire/coding-with-doom-fire'
Insert cell
moment = require("moment")
Insert cell
Q5 = require("https://cdn.jsdelivr.net/gh/LingDong-/q5xjs/q5.min.js").catch(
() => window.Q5
)
Insert cell
d3 = require("d3@6")
Insert cell
_ = require("lodash")
Insert cell
Chance = require("chance")
Insert cell
chance = new Chance()
Insert cell
db = app.firestore()
Insert cell
firebaseConfig = ({
apiKey: "AIzaSyCXVpNv-wY1r8LIfvZjFsnB-rxo7wK7Csc",
authDomain: "cwf-ej-enj.firebaseapp.com",
databaseURL: "https://cwf-ej-enj.firebaseio.com",
projectId: "cwf-ej-enj",
storageBucket: "cwf-ej-enj.appspot.com",
messagingSenderId: "824648798292",
appId: "1:824648798292:web:70197a68c08e6f923dddc1",
measurementId: "G-0YF53DB757"
})
Insert cell
app = {
let app = firebase.initializeApp(firebaseConfig);
// firebase.analytics();
// firebase.auth().useDeviceLanguage();
return app;
}
Insert cell
firebase = require.alias({
"@firebase/app": "https://www.gstatic.com/firebasejs/7.2.3/firebase-app.js",
// "@firebase/auth": "https://www.gstatic.com/firebasejs/7.2.3/firebase-auth.js",
// "@firebase/analytics":
// "https://www.gstatic.com/firebasejs/7.2.3/firebase-analytics.js",
"@firebase/firestore":
"https://www.gstatic.com/firebasejs/7.2.3/firebase-firestore.js"
})(
"@firebase/app",
// "@firebase/auth",
// "@firebase/analytics",
"@firebase/firestore"
)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more