xxxxxxxxxx
78
var cseA = ['Sarah', 'Jake', 'Ka Hou', 'Michael', 'Kenny'];
var cseB = ['Leandro', 'Dylan', 'Hugo', 'Bosco', 'Ana'];
// --- Last Pairs
var activity1 = [
['Sarah', 'Bosco'],
['Jake', 'Ana'],
['Ka Hou', 'Dylan'],
['Michael', 'Hugo'],
['Kenny', 'Leandro'],
];
var activity2 = [
['Sarah', 'Dylan'],
['Jake', 'Bosco'],
['Ka Hou', 'Ana'],
['Michael', 'Leandro'],
['Kenny', 'Hugo'],
];
// ---------------
var button;
var lineHeight = 45;
var randomized = false;
function setup() {
createCanvas(400, 400);
button = createButton('Randomize');
button.position((width/2)-50, 20);
button.mousePressed(randomize);
}
function draw() {
background(174, 224, 132);
// Draw a header
textSize(18);
textStyle(BOLD);
text("CSE-A", 80, 90);
text("CSE-B", 240, 90);
line(80, 100, 310, 100);
// List the names
if (randomized) {
textStyle(NORMAL);
for (var i = 0; i < cseA.length; i++) {
text(cseA[i], 80, 140 + (i * lineHeight));
text('⇄', 185, 140 + (i * lineHeight));
text(cseB[i], 240, 140 + (i * lineHeight));
}
}
}
function randomize()
{
cseA = shuffle(cseA);
cseB = shuffle(cseB);
// Prevent the same groups as last time
var alreadyDone = false;
for (var i = 0; i < cseA.length; i++) {
for (var k = 0; k < activity1.length; k++) {
if (cseA[i] == activity1[k][0] && cseB[i] == activity1[k][1]) {
alreadyDone = true;
}
}
}
if (alreadyDone) {
randomize();
}
randomized = true;
}