crowds/js/chapters/3_Complex_Contagion.js

242 lines
3.6 KiB
JavaScript
Raw Normal View History

2018-04-02 17:43:20 +00:00
// 3 - Complex Contagion
2018-04-01 16:34:52 +00:00
SLIDES.push(
2018-04-03 17:32:26 +00:00
2018-04-01 16:34:52 +00:00
{
2018-04-02 17:43:20 +00:00
chapter: "Complex",
clear:true,
add:[
2018-04-03 17:32:26 +00:00
// Intro text
{
type:"box",
2018-04-12 19:50:59 +00:00
id:"_3_complex",
2018-04-03 17:32:26 +00:00
text:"_3_complex",
2018-04-12 19:50:59 +00:00
x:0, y:0, w:480, h:540
2018-04-03 17:32:26 +00:00
},
// Sim
2018-04-02 17:43:20 +00:00
{
type:"sim",
2018-04-03 17:32:26 +00:00
x:0, y:0,
2018-04-02 17:43:20 +00:00
fullscreen: true,
network: {
"contagion":0.25,
2018-04-12 19:50:59 +00:00
"peeps":[[819,90,0],[911,182,0],[905,310,0],[821,413,0],[688,252,0],[551,251,1]],
"connections":[[4,3,0],[2,4,0],[4,1,0],[4,0,0]]
2018-04-02 17:43:20 +00:00
},
options:{
infectedFrame: 3,
2018-04-12 19:50:59 +00:00
scale: 1.75
2018-04-02 17:43:20 +00:00
}
},
2018-04-03 17:32:26 +00:00
// UI for the simulation
{
type:"box",
2018-04-12 19:50:59 +00:00
x:520, y:340,
2018-04-06 16:06:55 +00:00
sim_ui:"red"
2018-04-12 19:50:59 +00:00
}
2018-04-03 17:32:26 +00:00
],
onupdate:function(slideshow, state){
2018-04-12 19:50:59 +00:00
// Show end if ALL infected
2018-04-03 17:32:26 +00:00
if(!state.ended){
var sim = slideshow.simulations.sims[0];
var peepCount = 0;
sim.peeps.forEach(function(peep){
if(peep.infected) peepCount++;
});
2018-04-12 19:50:59 +00:00
if(peepCount==sim.peeps.length){
2018-04-03 17:32:26 +00:00
state.ended = true;
2018-04-12 19:50:59 +00:00
sim.win();
slideshow.next();
2018-04-03 17:32:26 +00:00
}
}
}
2018-04-02 17:43:20 +00:00
},
2018-04-03 17:32:26 +00:00
2018-04-12 19:50:59 +00:00
{
remove:[
{type:"box", id:"_3_complex"}
],
add:[
{
type:"box",
text:"_3_complex_2",
x:0, y:0, w:480, h:540
}
]
},
2018-04-02 17:43:20 +00:00
{
chapter: "Complex-Cascade",
clear:true,
add:[
2018-04-03 17:32:26 +00:00
// Sim
2018-04-02 17:43:20 +00:00
{
type:"sim",
2018-04-03 17:32:26 +00:00
x:0, y:-140,
2018-04-02 17:43:20 +00:00
fullscreen: true,
network: {
2018-04-03 17:32:26 +00:00
"contagion":0.25,
2018-04-02 17:43:20 +00:00
"peeps":CASCADE_PUZZLE.peeps,
"connections":CASCADE_PUZZLE.connections
},
options:{
infectedFrame: 3,
scale: 1.25,
startUncuttable: true
}
},
2018-04-03 17:32:26 +00:00
// UI for the simulation
{
type:"box",
x:380, y:290,
2018-04-06 16:06:55 +00:00
sim_ui:"red"
2018-04-03 17:32:26 +00:00
},
// Intro text
{
type:"box",
text:"_3_cascade",
x:0, y:400, w:600, h:140
},
// End text
{
id:"end",
type:"box",
text:"_3_cascade_end",
x:660, y:440, w:300, h:100,
hidden:true
},
],
onupdate:function(slideshow, state){
// Show end if EVERYONE is infected
if(!state.ended){
var sim = slideshow.simulations.sims[0];
var peepCount = 0;
sim.peeps.forEach(function(peep){
if(peep.infected) peepCount++;
});
if(peepCount==sim.peeps.length){
var boxes = slideshow.boxes;
boxes.showChildByID("end", true);
state.ended = true;
sim.win();
}
}
}
2018-04-02 17:43:20 +00:00
},
2018-04-03 17:32:26 +00:00
{
chapter: "Complex-Prevent",
clear:true,
add:[
// Intro text
{
type:"box",
text:"_3_prevent",
x:0, y:0, w:350, h:200
},
// Lil' contagion
{
type:"sim",
x:0, y:80,
fullscreen: true,
network: {
"contagion":0.25,
"peeps":CONTAGION_PUZZLE.peeps,
"connections":CONTAGION_PUZZLE.connections
},
options:{
infectedFrame: 3,
scale: 1.25,
startUncuttable: true
}
},
// UI for the simulation
{
type:"box",
x:380, y:140,
2018-04-06 16:06:55 +00:00
sim_ui:"red"
2018-04-03 17:32:26 +00:00
},
// Outro text
{
id:"end",
type:"box",
text:"_3_prevent_end",
x:660, y:440, w:300, h:100,
hidden:true
}
],
onupdate:function(slideshow, state){
// Show end if sim is running AND no one left to infect
// that is, it's stalled... YAY!
var sim = slideshow.simulations.sims[0];
if(!state.ended){
if(Simulations.IS_RUNNING){
// if it's a new step...
if(sim.STEP > state.lastStep){
// ...but the infected count is the same as last step
var countInfected = 0;
sim.peeps.forEach(function(peep){ if(peep.infected) countInfected++; });
if(state.lastInfected == countInfected){
// oh, and it's NOT coz ALL of 'em are infected
if(countInfected!=sim.peeps.length){
// WIN
var boxes = slideshow.boxes;
setTimeout(function(){
boxes.showChildByID("end", true);
state.ended = true;
sim.win();
},500);
}
}else{
state.lastInfected = countInfected;
}
}
state.lastStep = sim.STEP;
}else{
state.lastStep = 0;
state.lastInfected = 1;
}
}
}
}
2018-04-01 16:34:52 +00:00
);