, 60 , . Firebase .once async, , P5 , , .
, , , .
1 -
.
1: , , , . , .on("value") .once("value"), firebase , , , 60 , . : . 1 .
2: , , 60 . .once draw() . . 2 .
2 -
, . , , circleCount. , , , , , . ( )
, -, circles1 circles2 .. , .ref("circles" + j) . , : .ref("circles/" + j), , circle circles. , circles/circle1 circles/circle2 ..
, firebase, . Firebase , forEach .
3 - firebase
. , firebase 1/60 (16 miliseconds), . , . 30 , , firebase 30 .
1
(, , - , , xPos)
var latestCirclePositionsSnapshot;
function setup() {
createCanvas(windowWidth, windowHeight);
background(40);
stroke(80);
smooth();
frameRate(60);
firebase.database().ref("circles").on("value", function(snapshot) {
latestCirclePositionsSnapshot = snapshot;
});
}
function draw() {
drawCircles();
}
function clearBackground () {
stroke(80);
background(40);
}
function drawCircles() {
clearBackground();
stroke(0);
latestCirclePositionsSnapshot.forEach(function(circleSnapshot) {
var circleData = circleSnapshot.val();
fill(143, 2, 2);
ellipse(circleData.xPos, 50, 50);
});
}
, firebase, . ( , P5 60 , firebase , firebase firebase ..)
2
, , , , firebase (, )
var circlePositions;
var gotPositions = false;
function setup() {
createCanvas(windowWidth, windowHeight);
background(40);
stroke(80);
smooth();
frameRate(60);
firebase.database().ref("circles").once("value", function(snapshot) {
circlePositions = snapshot;
gotPositions = true;
});
}
function draw() {
drawCircles();
}
function clearBackground () {
stroke(80);
background(40);
}
function drawCircles() {
clearBackground();
stroke(0);
if (gotPositions) {
circlePositions.forEach(function(circleSnapshot) {
var circleData = circleSnapshot.val();
fill(143, 2, 2);
ellipse(circleData.xPos, 50, 50);
});
} else {
}
}
, :) Processing Firebase.