morse joker

This commit is contained in:
Astro 2011-10-14 03:56:54 +02:00
parent ccab3a3afe
commit 4c53674c35
4 changed files with 522 additions and 2 deletions

BIN
morse.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 848 B

383
morse.svg Normal file
View File

@ -0,0 +1,383 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="100"
height="50"
id="svg2"
version="1.1"
inkscape:version="0.48.1 r9760"
sodipodi:docname="morse.svg"
inkscape:export-filename="/home/stephan/public_html/ds-quiz/morse.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<defs
id="defs4">
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
id="perspective10" />
<inkscape:perspective
id="perspective3607"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective3012"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective3036"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<radialGradient
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient6896"
id="radialGradient2351"
fy="240"
fx="240"
r="225"
cy="240"
cx="240" />
<linearGradient
id="linearGradient6896">
<stop
id="stop6898"
offset="0"
style="stop-color:#00ff36;stop-opacity:0" />
<stop
id="stop6900"
offset="1"
style="stop-color:#00ff36;stop-opacity:0.41176471" />
</linearGradient>
<linearGradient
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient5822"
id="linearGradient2359"
y2="152.74609"
x2="441.11914"
y1="152.74609"
x1="38.880859" />
<linearGradient
id="linearGradient5822">
<stop
id="stop5824"
offset="0"
style="stop-color:#38e077;stop-opacity:1" />
<stop
id="stop5826"
offset="1"
style="stop-color:#1dac47;stop-opacity:1" />
</linearGradient>
<linearGradient
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient5814"
id="linearGradient2356"
y2="311.83057"
x2="452.59863"
y1="311.83057"
x1="27.401367" />
<linearGradient
id="linearGradient5814">
<stop
id="stop5816"
offset="0"
style="stop-color:#2eb55a;stop-opacity:1" />
<stop
id="stop5818"
offset="1"
style="stop-color:#007005;stop-opacity:1" />
</linearGradient>
<radialGradient
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient3850"
id="radialGradient2379"
fy="240"
fx="240"
r="240"
cy="240"
cx="240" />
<radialGradient
gradientTransform="matrix(-0.5679026,-1.4348261,1.4011243,-0.5545635,-81.877424,420.14452)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient3850"
id="radialGradient2376"
fy="167.49931"
fx="196.07219"
r="240"
cy="167.49931"
cx="196.07219" />
<linearGradient
id="linearGradient3850">
<stop
id="stop3852"
offset="0"
style="stop-color:#ffffff;stop-opacity:0.80000001" />
<stop
id="stop4351"
offset="0.83783782"
style="stop-color:#ffffff;stop-opacity:0" />
<stop
id="stop3854"
offset="1"
style="stop-color:#ffffff;stop-opacity:0" />
</linearGradient>
<linearGradient
gradientUnits="userSpaceOnUse"
id="linearGradient3566"
y2="149"
x2="208.375"
y1="149"
x1="31.625">
<stop
id="stop2546"
offset="0"
style="stop-color:#767679;stop-opacity:1" />
<stop
id="stop2554"
offset="0.30000001"
style="stop-color:#b1c2c5;stop-opacity:1" />
<stop
id="stop2550"
offset="0.63"
style="stop-color:#c2d9db;stop-opacity:1" />
<stop
id="stop2552"
offset="0.83999997"
style="stop-color:#b8cbcd;stop-opacity:1" />
<stop
id="stop2548"
offset="1"
style="stop-color:#848487;stop-opacity:1" />
</linearGradient>
<linearGradient
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient3568"
id="linearGradient4793"
y2="35"
x2="29"
y1="35"
x1="211" />
<linearGradient
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient3568"
id="linearGradient3738"
y2="77"
x2="215"
y1="77"
x1="25" />
<linearGradient
id="linearGradient3568">
<stop
id="stop3570"
offset="0"
style="stop-color:#3d47c3;stop-opacity:1" />
<stop
id="stop3578"
offset="1"
style="stop-color:#29a2fb;stop-opacity:1" />
</linearGradient>
<linearGradient
gradientUnits="userSpaceOnUse"
id="linearGradient4937"
y2="51"
x2="211"
y1="51"
x1="29">
<stop
id="stop4899"
offset="0"
style="stop-color:#717171;stop-opacity:1" />
<stop
id="stop4905"
offset="0.30000001"
style="stop-color:#a0a0a0;stop-opacity:1" />
<stop
id="stop4903"
offset="0.77999997"
style="stop-color:#e7e7e7;stop-opacity:1" />
<stop
id="stop4901"
offset="1"
style="stop-color:#f5f5f5;stop-opacity:1" />
</linearGradient>
<linearGradient
gradientUnits="userSpaceOnUse"
id="linearGradient6341"
y2="36"
x2="121.5"
y1="13.5"
x1="111.5">
<stop
id="stop5997"
offset="0"
style="stop-color:#ff9915;stop-opacity:1" />
<stop
id="stop6003"
offset="1"
style="stop-color:#fff438;stop-opacity:1" />
</linearGradient>
<linearGradient
gradientUnits="userSpaceOnUse"
id="linearGradient6343"
y2="79"
x2="170"
y1="79"
x1="109">
<stop
id="stop6067"
offset="0"
style="stop-color:#fbf1b1;stop-opacity:1" />
<stop
id="stop6071"
offset="0.69999999"
style="stop-color:#fdcb46;stop-opacity:1" />
<stop
id="stop6069"
offset="1"
style="stop-color:#ff9915;stop-opacity:1" />
</linearGradient>
<linearGradient
gradientUnits="userSpaceOnUse"
id="linearGradient6339"
y2="45"
x2="115"
y1="128"
x1="102">
<stop
id="stop6202"
offset="0"
style="stop-color:#fff238;stop-opacity:1" />
<stop
id="stop6208"
offset="0.30000001"
style="stop-color:#d8ae1f;stop-opacity:1" />
<stop
id="stop6206"
offset="1"
style="stop-color:#b8770a;stop-opacity:1" />
</linearGradient>
<inkscape:perspective
id="perspective3250"
inkscape:persp3d-origin="120 : 80 : 1"
inkscape:vp_z="240 : 120 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 120 : 1"
sodipodi:type="inkscape:persp3d" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#313059"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="1"
inkscape:pageshadow="2"
inkscape:zoom="8.0574949"
inkscape:cx="43.248758"
inkscape:cy="37.570296"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:window-width="1916"
inkscape:window-height="1178"
inkscape:window-x="0"
inkscape:window-y="18"
inkscape:window-maximized="0">
<inkscape:grid
type="xygrid"
id="grid2816"
empspacing="5"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true" />
</sodipodi:namedview>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-1002.3622)">
<rect
style="fill:#ffffff;fill-opacity:0;fill-rule:evenodd;stroke:#ffffff;stroke-opacity:1;stroke-linejoin:round;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-linecap:butt"
id="rect2818"
width="100"
height="50"
x="0"
y="0"
transform="translate(0,1002.3622)" />
<path
sodipodi:type="arc"
style="fill:#fff566;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="path3066"
sodipodi:cx="15.5"
sodipodi:cy="27.5"
sodipodi:rx="6.5"
sodipodi:ry="6.5"
d="m 22,27.5 a 6.5,6.5 0 1 1 -13,0 6.5,6.5 0 1 1 13,0 z"
transform="translate(-4,999.86218)" />
<path
sodipodi:type="arc"
style="fill:#fff566;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="path3066-2"
sodipodi:cx="15.5"
sodipodi:cy="27.5"
sodipodi:rx="6.5"
sodipodi:ry="6.5"
d="m 22,27.5 a 6.5,6.5 0 1 1 -13,0 6.5,6.5 0 1 1 13,0 z"
transform="translate(14,999.86218)" />
<path
sodipodi:type="arc"
style="fill:#fff566;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="path3066-7"
sodipodi:cx="15.5"
sodipodi:cy="27.5"
sodipodi:rx="6.5"
sodipodi:ry="6.5"
d="m 22,27.5 a 6.5,6.5 0 1 1 -13,0 6.5,6.5 0 1 1 13,0 z"
transform="translate(32,999.86218)" />
<rect
style="fill:#fff566;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="rect3861"
width="17"
height="10"
x="58"
y="1022.3622" />
<rect
style="fill:#fff566;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="rect3861-2"
width="17"
height="10"
x="79"
y="1022.3622" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 11 KiB

15
quiz.js
View File

@ -137,6 +137,7 @@ var TIMER_ANSWER = 90;
var timer = new Timer();
var playerNames = [], playerScores = [], playerJokers = [];
console.log('playerNames', playerNames);
function startQuiz() {
var i;
@ -152,7 +153,7 @@ function startQuiz() {
if (name) {
playerNames[i] = name;
playerScores[i] = 0;
$('#scoreboard dl').append('<dt></dt><dd><span class="score">0</span><img src="fiftyfifty.png" class="fiftyfifty"><img src="nedap.png" class="nedap"><img src="irc.png" class="irc"><img src="fwd.png" class="fwd"></dd>');
$('#scoreboard dl').append('<dt></dt><dd><span class="score">0</span><img src="fiftyfifty.png" class="fiftyfifty"><img src="nedap.png" class="nedap"><img src="irc.png" class="irc"><img src="fwd.png" class="fwd"><img src="morse.png" class="morse"></dd>');
$('#scoreboard dl dt').last().text(name);
$('#players').append('<li class="player'+i+'"><span class="name"></span><span class="score">0</span></li>');
$('#players li.player'+i+' span.name').text(name);
@ -308,6 +309,15 @@ function takeJoker(activePlayer, joker) {
$('#irc ul').empty();
$('#irc').slideDown(500);
}
if (joker === 'morse') {
var morseText = "";
questions[currentQuestion].answers.forEach(function(answer) {
if (answer.right === true &&
(!morseText || Math.random() > 0.5))
morseText = answer.text;
});
sendToBackend({ morse: morseText });
}
}
function setQuestionContents(q) {
@ -488,6 +498,9 @@ function switchToGame() {
key === 's') {
takeJoker(activePlayer, 'fwd');
activePlayer = null;
} else if (activePlayer !== null &&
key === 'm') {
takeJoker(activePlayer, 'morse');
}
};

126
server.js
View File

@ -37,7 +37,7 @@ function connectNedap() {
});
nedap.connect('ws://localhost/', 'quiz-nedap');
}
connectNedap();
//connectNedap();
/*
@ -95,11 +95,131 @@ function pushIrcInfo() {
/*
* Buttons
*/
if (false){
var buzz = new (require('./buzz_iface/node_lib/buzz').Buzz)('/dev/ttyUSB0');
buzz.on('button', function(key) {
console.log({button:key});
sendToFrontend({ buzzer: key });
});
}
function setAllLEDs(brightness) {
for(var player = 0; player < 3; player++)
buzz.set_led(player, brightness);
}
var MORSE_ALPHABET = {
"A": ". -",
"B": "- . . .",
"C": "- . - .",
"D": "- . .",
"E": ".",
"F": ". . - .",
"G": "- - .",
"H": ". . . .",
"I": ". .",
"J": ". - - -",
"K": "- . -",
"L": ". - . .",
"M": "- -",
"N": "- .",
"O": "- - -",
"P": ". - - .",
"Q": "- - . -",
"R": ". - .",
"S": ". . .",
"T": "-",
"U": ". . -",
"V": ". . . -",
"W": ". - -",
"X": "- . . -",
"Y": "- . - -",
"Z": "- - . .",
"0": "- - - - -",
"1": ". - - - -",
"2": ". . - - -",
"3": ". . . - -",
"4": ". . . . -",
"5": ". . . . .",
"6": "- . . . .",
"7": "- - . . .",
"8": "- - - . .",
"9": "- - - - .",
"À": ". - - . -",
"Å": ". - - . -",
"Ä": ". - . -",
"È": ". - . . -",
"É": ". . - . .",
"Ö": "- - - .",
"Ü": ". . - -",
"ß": ". . . - - . .",
"CH": "- - - -",
"Ñ": "- - . - -",
".": ". - . - . -",
",": "- - . . - -",
":": "- - - . . .",
";": "- . - . - .",
"?": ". . - - . .",
"-": "- . . . . -",
"_": ". . - - . -",
"(": "- . - - .",
")": "- . - - . -",
"'": ". - - - - .",
"=": "- . . . -",
"+": ". - . - .",
"/": "- . . - .",
"@": ". - - . - ."
};
var DIT_LENGTH = 240;
var DAH_LENGTH = 3 * DIT_LENGTH;
var PAUSE_LENGTH = DIT_LENGTH;
var CHARACTER_PAUSE_LENGTH = 3;
var WORD_PAUSE_LENGTH = 7;
function morse(text) {
/* Assemble sequence */
var sequence = '';
for(var i = 0; i < text.length; i++) {
var symbols;
if (text[i] === " ")
for(var j = 0; j < WORD_PAUSE_LENGTH; j++)
sequence += " ";
else if ((symbols = MORSE_ALPHABET[text[i].toLocaleUpperCase()])) {
sequence += symbols;
for(j = 0; j < CHARACTER_PAUSE_LENGTH; j++)
sequence += " ";
}
}
sequence += " "; /* clear led at end */
console.log("morse", text, sequence);
/* Play */
var playSequence = function() {
console.log("playSequence", sequence[0])
var delay;
switch(sequence[0]) {
case ".":
setAllLEDs(1);
delay = DIT_LENGTH;
break;
case "-":
setAllLEDs(1);
delay = DAH_LENGTH;
break;
case " ":
setAllLEDs(0);
delay = PAUSE_LENGTH;
break;
}
sequence = sequence.substr(1);
if (sequence && delay)
setTimeout(playSequence, delay);
};
playSequence();
}
/*
* Web server
@ -140,6 +260,8 @@ new wss({ httpServer: server }).on('request', function(req) {
pushIrcInfo();
} else if (msg.buzzerLED) {
buzz.set_led(msg.buzzerLED[0], msg.buzzerLED[1]);
} else if (msg.morse) {
morse(msg.morse);
}
} catch (e) {
console.error(e.stack);
@ -161,3 +283,5 @@ function sendToFrontend(obj) {
}
server.listen(8081);
morse("c3d2");