crowds/js/chapters/E_Complex_Contagion.js

415 lines
6.2 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-16 15:44:14 +00:00
id:"complex_complex",
text:"complex_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: {
2018-04-18 14:51:44 +00:00
"contagion":0.5,
2018-04-18 15:25:41 +00:00
"peeps":[[849,356,0],[808,199,0],[543,97,1],[679,114,0],[781,480,0],[906,480,0]],
"connections":[[0,1,1],[2,3,1],[3,1,1],[4,0,1],[0,5,1]]
2018-04-02 17:43:20 +00:00
},
options:{
2018-04-18 14:51:44 +00:00
infectedFrame: 2,
scale: 1.75,
2018-04-18 18:02:27 +00:00
startUncuttable: true,
_bottle: true
2018-04-02 17:43:20 +00:00
}
},
2018-04-03 17:32:26 +00:00
// UI for the simulation
{
type:"box",
2018-04-18 14:51:44 +00:00
x:520, y:230,
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-18 14:51:44 +00:00
// Show next if SIM STEP >= 3
2018-04-03 17:32:26 +00:00
if(!state.ended){
var sim = slideshow.simulations.sims[0];
2018-04-18 14:51:44 +00:00
if(sim.STEP>=3){
2018-04-03 17:32:26 +00:00
state.ended = true;
2018-04-12 19:50:59 +00:00
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:[
2018-04-16 15:44:14 +00:00
{type:"box", id:"complex_complex"}
2018-04-12 19:50:59 +00:00
],
add:[
{
type:"box",
2018-04-16 15:44:14 +00:00
text:"complex_complex_2",
2018-04-12 19:50:59 +00:00
x:0, y:0, w:480, h:540
}
]
},
2018-04-18 14:51:44 +00:00
{
2018-04-18 20:28:41 +00:00
chapter: "Complex-Wisdom",
2018-04-18 14:51:44 +00:00
clear:true,
add:[
// Intro text
{
2018-04-18 20:28:41 +00:00
id:"complex_complex_3",
2018-04-18 14:51:44 +00:00
type:"box",
text:"complex_complex_3",
2018-04-18 20:28:41 +00:00
x:480, y:0, w:480, h:540
},
2018-04-18 14:51:44 +00:00
// Sim
{
type:"sim",
x:0, y:0,
fullscreen: true,
network: {
"contagion":0.25,
2018-04-18 20:28:41 +00:00
"peeps":[[54,240,1],[227,237,0],[298,98,0],[405,157,0],[408,296,0],[311,380,0]],
2018-04-18 14:51:44 +00:00
"connections":[[1,2,0],[1,3,0],[4,1,0],[1,5,0],[0,1,0]]
},
options:{
infectedFrame: 3,
2018-04-18 18:02:27 +00:00
scale: 1.75,
_wisdom: true
2018-04-18 14:51:44 +00:00
}
},
// UI for the simulation
{
type:"box",
2018-04-18 20:28:41 +00:00
x:30, y:320,
2018-04-18 14:51:44 +00:00
sim_ui:"red"
}
],
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;
state.ended = true;
2018-04-20 18:47:58 +00:00
sim.win({
small:true
});
2018-04-27 12:24:33 +00:00
slideshow.next();
2018-04-18 14:51:44 +00:00
}
}
}
},
2018-04-27 12:24:33 +00:00
{
remove:[
{type:"box", id:"complex_complex_3"}
],
add:[
{
id:"end",
type:"box",
text:"complex_complex_3_end",
x:480, 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
2018-04-12 21:22:22 +00:00
// Intro text
{
type:"box",
2018-04-16 15:44:14 +00:00
id:"complex_cascade",
text:"complex_cascade",
2018-04-12 21:22:22 +00:00
x:60, y:0, w:840, h:100,
align: "center"
},
2018-04-03 17:32:26 +00:00
// Sim
2018-04-02 17:43:20 +00:00
{
type:"sim",
2018-04-12 21:22:22 +00:00
id:"contagion",
x:0, y:-40,
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,
2018-04-18 18:02:27 +00:00
startUncuttable: true,
_wisdom: true
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 21:22:22 +00:00
id:"ui",
x:380, y:370,
2018-04-06 16:06:55 +00:00
sim_ui:"red"
2018-04-03 17:32:26 +00:00
},
2018-04-18 20:28:41 +00:00
{
type:"box",
id:"complex_cascade_feel_free",
text:"complex_cascade_feel_free",
x:330, y:440, w:300, h:100,
align: "center"
},
2018-04-03 17:32:26 +00:00
// End text
{
id:"end",
type:"box",
2018-04-16 15:44:14 +00:00
text:"complex_cascade_end",
2018-04-18 20:28:41 +00:00
x:330, y:450, w:300, h:100,
2018-04-03 17:32:26 +00:00
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;
2018-04-18 20:28:41 +00:00
boxes.removeChildByID("complex_cascade_feel_free", true);
2018-04-03 17:32:26 +00:00
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
2018-04-12 21:22:22 +00:00
{
remove:[
2018-04-16 15:44:14 +00:00
{type:"box", id:"complex_cascade"},
2018-04-12 21:22:22 +00:00
{type:"box", id:"end"}
],
move:[
{type:"box", id:"ui", y:360-80},
{type:"sim", id:"contagion", y:-140}
],
add:[
{
type:"box",
2018-04-16 15:44:14 +00:00
text:"complex_post_cascade",
2018-04-18 20:28:41 +00:00
x:50, y:390, w:600, h:150,
2018-04-12 21:22:22 +00:00
align: "right"
},
{
type:"box",
2018-04-16 15:44:14 +00:00
text:"complex_post_cascade_end",
2018-04-12 21:22:22 +00:00
x:660, y:450, w:300, h:90
}
]
},
2018-04-03 17:32:26 +00:00
{
chapter: "Complex-Prevent",
clear:true,
add:[
// Intro text
{
type:"box",
2018-04-16 15:44:14 +00:00
id:"complex_prevent",
text:"complex_prevent",
2018-04-12 21:22:22 +00:00
x:80, y:0, w:800, h:140,
align: "center"
2018-04-03 17:32:26 +00:00
},
// Lil' contagion
{
2018-04-13 17:42:02 +00:00
id: "contagion",
2018-04-03 17:32:26 +00:00
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,
2018-04-18 18:02:27 +00:00
startUncuttable: true,
_wisdom: true
2018-04-03 17:32:26 +00:00
}
},
// UI for the simulation
{
type:"box",
2018-04-12 21:22:22 +00:00
id:"ui",
2018-04-03 17:32:26 +00:00
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
2018-04-13 17:42:02 +00:00
/*{
2018-04-03 17:32:26 +00:00
id:"end",
type:"box",
2018-04-16 15:44:14 +00:00
text:"complex_prevent_end",
2018-04-03 17:32:26 +00:00
x:660, y:440, w:300, h:100,
hidden:true
2018-04-13 17:42:02 +00:00
}*/
2018-04-03 17:32:26 +00:00
],
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
2018-04-12 21:22:22 +00:00
state.ended = true;
2018-04-03 17:32:26 +00:00
var boxes = slideshow.boxes;
setTimeout(function(){
2018-04-13 17:42:02 +00:00
//boxes.showChildByID("end", true);
2018-04-18 20:28:41 +00:00
sim.win({
x:350, y:270-90,
2018-04-20 18:47:58 +00:00
width:260, height:260,
small:true
2018-04-18 20:28:41 +00:00
});
2018-04-15 21:24:22 +00:00
},350);
2018-04-13 17:42:02 +00:00
setTimeout(function(){
slideshow.next();
2018-04-15 21:24:22 +00:00
},1100);
2018-04-03 17:32:26 +00:00
}
}else{
state.lastInfected = countInfected;
}
}
state.lastStep = sim.STEP;
}else{
state.lastStep = 0;
state.lastInfected = 1;
}
}
}
2018-04-13 17:42:02 +00:00
},
{
remove:[
2018-04-16 15:44:14 +00:00
{type:"box", id:"complex_prevent"}
2018-04-13 17:42:02 +00:00
],
move:[
{type:"box", id:"ui", y:0},
{type:"sim", id:"contagion", y:-70}
],
add:[
{
type:"box",
2018-04-16 15:44:14 +00:00
text:"complex_prevent_2",
2018-04-13 17:42:02 +00:00
x:0, y:390, w:650, h:100,
align: "right"
},
{
type:"box",
2018-04-16 15:44:14 +00:00
text:"complex_prevent_end",
2018-04-13 17:42:02 +00:00
x:660, y:450, w:300, h:90
}
]
},
{
chapter: "Complex-Groupthink",
clear: true,
add:[
2018-04-18 20:28:41 +00:00
// NASA Image
2018-04-13 17:42:02 +00:00
{
type:"box",
2018-04-26 14:15:00 +00:00
img:"sprites/nasa.png", x:0, y:0, w:425, h:450
2018-04-13 17:42:02 +00:00
},
// Text
{
type:"box",
2018-04-16 15:44:14 +00:00
text:"complex_groupthink",
2018-04-13 20:58:04 +00:00
x:460, y:0, w:500, h:540
2018-04-13 17:42:02 +00:00
},
]
2018-04-03 17:32:26 +00:00
}
2018-04-13 17:42:02 +00:00
);