diff options
author | Bryan Berry <bryan@olenepal.org> | 2010-01-04 13:36:17 (GMT) |
---|---|---|
committer | Bryan Berry <bryan@olenepal.org> | 2010-01-04 13:36:17 (GMT) |
commit | b022c87d8187fde2ee74f67c88399fc6c6b2051c (patch) | |
tree | 5e6c8d7ae52af4aa59487b8515daded052b5102a /examples | |
parent | 4802b58ae79280513693a6542942205aa0cc3837 (diff) |
moved math functions to Karma.* namespace. Fixed the lessons that used them to use proper referencesshuffle-karma
Diffstat (limited to 'examples')
26 files changed, 17 insertions, 343 deletions
diff --git a/examples/Conozco-Uruguay/assets/svg/alien-sad.svg b/examples/Conozco-Uruguay/assets/svg/alien-sad.svg index 34ea921..34ea921 100644..100755 --- a/examples/Conozco-Uruguay/assets/svg/alien-sad.svg +++ b/examples/Conozco-Uruguay/assets/svg/alien-sad.svg diff --git a/examples/Conozco-Uruguay/assets/svg/alien1.svg b/examples/Conozco-Uruguay/assets/svg/alien1.svg index 2bcf866..2bcf866 100644..100755 --- a/examples/Conozco-Uruguay/assets/svg/alien1.svg +++ b/examples/Conozco-Uruguay/assets/svg/alien1.svg diff --git a/examples/Conozco-Uruguay/assets/svg/alien2.svg b/examples/Conozco-Uruguay/assets/svg/alien2.svg index bf6f73e..bf6f73e 100644..100755 --- a/examples/Conozco-Uruguay/assets/svg/alien2.svg +++ b/examples/Conozco-Uruguay/assets/svg/alien2.svg diff --git a/examples/Conozco-Uruguay/assets/svg/alien3.svg b/examples/Conozco-Uruguay/assets/svg/alien3.svg index 377ee92..377ee92 100644..100755 --- a/examples/Conozco-Uruguay/assets/svg/alien3.svg +++ b/examples/Conozco-Uruguay/assets/svg/alien3.svg diff --git a/examples/Conozco-Uruguay/assets/svg/alien4.svg b/examples/Conozco-Uruguay/assets/svg/alien4.svg index e726de1..e726de1 100644..100755 --- a/examples/Conozco-Uruguay/assets/svg/alien4.svg +++ b/examples/Conozco-Uruguay/assets/svg/alien4.svg diff --git a/examples/Conozco-Uruguay/assets/svg/alien5.svg b/examples/Conozco-Uruguay/assets/svg/alien5.svg index b86eaa8..b86eaa8 100644..100755 --- a/examples/Conozco-Uruguay/assets/svg/alien5.svg +++ b/examples/Conozco-Uruguay/assets/svg/alien5.svg diff --git a/examples/Conozco-Uruguay/assets/svg/capitals2.svg b/examples/Conozco-Uruguay/assets/svg/capitals2.svg index a549de0..a549de0 100644..100755 --- a/examples/Conozco-Uruguay/assets/svg/capitals2.svg +++ b/examples/Conozco-Uruguay/assets/svg/capitals2.svg diff --git a/examples/Conozco-Uruguay/assets/svg/helpIcon.svg b/examples/Conozco-Uruguay/assets/svg/helpIcon.svg index d83c915..d83c915 100644..100755 --- a/examples/Conozco-Uruguay/assets/svg/helpIcon.svg +++ b/examples/Conozco-Uruguay/assets/svg/helpIcon.svg diff --git a/examples/Conozco-Uruguay/assets/svg/helpScreen.svg b/examples/Conozco-Uruguay/assets/svg/helpScreen.svg index 6271a3d..6271a3d 100644..100755 --- a/examples/Conozco-Uruguay/assets/svg/helpScreen.svg +++ b/examples/Conozco-Uruguay/assets/svg/helpScreen.svg diff --git a/examples/Conozco-Uruguay/assets/svg/playAgain.svg b/examples/Conozco-Uruguay/assets/svg/playAgain.svg index 251eaf5..251eaf5 100644..100755 --- a/examples/Conozco-Uruguay/assets/svg/playAgain.svg +++ b/examples/Conozco-Uruguay/assets/svg/playAgain.svg diff --git a/examples/Conozco-Uruguay/assets/svg/quitIcon.svg b/examples/Conozco-Uruguay/assets/svg/quitIcon.svg index 51d8cdb..51d8cdb 100644..100755 --- a/examples/Conozco-Uruguay/assets/svg/quitIcon.svg +++ b/examples/Conozco-Uruguay/assets/svg/quitIcon.svg diff --git a/examples/Conozco-Uruguay/assets/svg/spaceship1.svg b/examples/Conozco-Uruguay/assets/svg/spaceship1.svg index 0572a51..0572a51 100644..100755 --- a/examples/Conozco-Uruguay/assets/svg/spaceship1.svg +++ b/examples/Conozco-Uruguay/assets/svg/spaceship1.svg diff --git a/examples/Conozco-Uruguay/assets/svg/spaceship2.svg b/examples/Conozco-Uruguay/assets/svg/spaceship2.svg index 4288c2e..4288c2e 100644..100755 --- a/examples/Conozco-Uruguay/assets/svg/spaceship2.svg +++ b/examples/Conozco-Uruguay/assets/svg/spaceship2.svg diff --git a/examples/Conozco-Uruguay/assets/svg/spaceship80x200.svg b/examples/Conozco-Uruguay/assets/svg/spaceship80x200.svg index e7d84eb..e7d84eb 100644..100755 --- a/examples/Conozco-Uruguay/assets/svg/spaceship80x200.svg +++ b/examples/Conozco-Uruguay/assets/svg/spaceship80x200.svg diff --git a/examples/Math_Largest_Number_Identification/js/lesson.js b/examples/Math_Largest_Number_Identification/js/lesson.js index 769b7b4..769b7b4 100644..100755 --- a/examples/Math_Largest_Number_Identification/js/lesson.js +++ b/examples/Math_Largest_Number_Identification/js/lesson.js diff --git a/examples/NumberWords-svg/assets/svg/crossword.svg b/examples/NumberWords-svg/assets/svg/crossword.svg index 19fa940..19fa940 100644..100755 --- a/examples/NumberWords-svg/assets/svg/crossword.svg +++ b/examples/NumberWords-svg/assets/svg/crossword.svg diff --git a/examples/NumberWords-svg/index.html b/examples/NumberWords-svg/index.html index dd93b92..dd93b92 100644..100755 --- a/examples/NumberWords-svg/index.html +++ b/examples/NumberWords-svg/index.html diff --git a/examples/NumberWords-svg/js/lesson.js b/examples/NumberWords-svg/js/lesson.js index d9e9347..d9e9347 100644..100755 --- a/examples/NumberWords-svg/js/lesson.js +++ b/examples/NumberWords-svg/js/lesson.js diff --git a/examples/NumberWords/assets/image/football.png b/examples/NumberWords/assets/image/football.png Binary files differindex 93dbd71..93dbd71 100644..100755 --- a/examples/NumberWords/assets/image/football.png +++ b/examples/NumberWords/assets/image/football.png diff --git a/examples/NumberWords/assets/image/gameOver.png b/examples/NumberWords/assets/image/gameOver.png Binary files differindex 8114f48..8114f48 100644..100755 --- a/examples/NumberWords/assets/image/gameOver.png +++ b/examples/NumberWords/assets/image/gameOver.png diff --git a/examples/NumberWords/css/lesson.css b/examples/NumberWords/css/lesson.css index 1850cdc..1850cdc 100644..100755 --- a/examples/NumberWords/css/lesson.css +++ b/examples/NumberWords/css/lesson.css diff --git a/examples/NumberWords/index.html b/examples/NumberWords/index.html index 4c9319b..4c9319b 100644..100755 --- a/examples/NumberWords/index.html +++ b/examples/NumberWords/index.html diff --git a/examples/NumberWords/js/lesson.js b/examples/NumberWords/js/lesson.js index cf16aba..4eed9b0 100644..100755 --- a/examples/NumberWords/js/lesson.js +++ b/examples/NumberWords/js/lesson.js @@ -25,7 +25,7 @@ $(document).ready (function(){ var shuffle = function (choices) { for(var i=0;i<choices.length;i++) { - var num = k.rand(0,choices.length-1); + var num = Karma.rand(0,choices.length-1); var temp = choices[i]; choices[i]=choices[num]; choices[num]=temp; @@ -47,7 +47,7 @@ $(document).ready (function(){ } var showList = function () { //shows the list on right like One (1) - $("#"+ANS[key]).show().css({"color":COLOR[k.rand(0,COLOR.length-1)]}); + $("#"+ANS[key]).show().css({"color":COLOR[Karma.rand(0,COLOR.length-1)]}); }; var congrats = function() { diff --git a/examples/adding_up_to_10_canvas/js/lesson.js b/examples/adding_up_to_10_canvas/js/lesson.js index 6581bdf..efabd88 100755 --- a/examples/adding_up_to_10_canvas/js/lesson.js +++ b/examples/adding_up_to_10_canvas/js/lesson.js @@ -75,13 +75,13 @@ $(document).ready( writeScore(); - total = k.rand( 2, 10 ); //the total - n0 = total - k.rand(1, total - 1 ); //first number + total = Karma.rand( 2, 10 ); //the total + n0 = total - Karma.rand(1, total - 1 ); //first number n1 = total - n0; //second number //chose one option (the correct option) //and then put the correct value into it - correct = k.rand( 0, 2 ); + correct = Karma.rand( 0, 2 ); choices[ correct ] = total; for (var i=0; i<3; i++) { @@ -90,10 +90,10 @@ $(document).ready( continue; } else { // generate the other options - choices[ i ] = k.rand( 2, 10 ); + choices[ i ] = Karma.rand( 2, 10 ); for (var j = 0; j < i; j++){ if (choices[i] === choices[j]) { - choices[ i ] = k.rand( 2, 10 ); + choices[ i ] = Karma.rand( 2, 10 ); } } } @@ -111,10 +111,10 @@ $(document).ready( for (var i=0; i<n; i++) { do { flag = false; - x = k.rand( 0, d ); - y = k.rand( 0, d ); + x = Karma.rand( 0, d ); + y = Karma.rand( 0, d ); for ( var j=0; j<pos.length; j++) { - if ( k.distance2( pos[j], + if ( Karma.distance2( pos[j], {"x": x, "y": y} ) < 120 ) { flag = true; break; diff --git a/examples/adding_up_to_10_canvas/js/lesson1.js b/examples/adding_up_to_10_canvas/js/lesson1.js deleted file mode 100755 index bce243f..0000000 --- a/examples/adding_up_to_10_canvas/js/lesson1.js +++ /dev/null @@ -1,326 +0,0 @@ -$(document).ready( - function(){ - - var k = Karma({ - images: [ - {name: "ball", file: "ball37px.png"}, - {name: "balloon", file: "balloon37px.png"}, - {name: "banana", file: "banana37px.png"}, - {name: "chilli", file: "chilli.png"}, - {name: "fish" , file: "fish64px.png"}, - {name: "flower", file: "flower37px.png"}, - {name: "normalChimp", file: "normalChimp_120x125.png"}, - {name: "happyChimp", file: "happyChimp_120x125.png"}, - {name: "sadChimp", file: "sadChimp_120x125.png"} - ] - , - sounds: [ - {name: "correct", file: "correct.ogg"}, - {name: "incorrect", file: "incorrect.ogg"}, - {name: "trigger", file: "trigger.ogg"} - ], - canvases: [ - {name:"topLt", domId:"topLtCanvas"}, - {name:"topRt", domId:"topRtCanvas"}, - {name:"bottomLt", domId:"bottomLtCanvas"}, - {name:"bottomMd", domId:"bottomMdCanvas"}, - {name:"bottomRt", domId:"bottomRtCanvas"}, - {name:"timer", domId:"timerCanvas"}, - {name:"scorebox", domId:"scoreboxCanvas"}, - {name:"chimp", domId:"chimpCanvas"} - ] - }); - - - k.ready(function() { - - k.canvases['timer'].clear(); - - k.canvases["scorebox"].save(). - //clear(). - font("bold 50px sans-serif white"). - fillStyle("#fff"). - textBaseline("middle"). - fillText("foo", 30, 100). - restore(); - k.canvases["topLt"].ctx.drawImage(k.images["ball"].media, 5, 10); - - /* k.canvases["topLt"].ctx.drawImage(k.images["ball"].media, 5, 10); - k.canvases['timer'].ctx.fillRect(10, 30, 40, 20); - - k.canvases['timer'].ctx.fillStyle = "#fff"; - k.canvases['timer'].ctx.fillRect(10, startTimerY, endTimerX, 20); - k.canvases['timer'].clear(); - k.rand( 2, 10 ); - - k.canvases["scorebox"].save(). - clear(). - font("bold 50px sans-serif white"). - fillStyle("#fff"). - textBaseline("middle"). - fillText("" + score, 30, 100). - restore(); - */ - -/* - var imgNames = ["ball", "banana", "balloon","chilli", "fish", "flower"]; - //game logic - var total, level=0, time, n0, n1, correct; - var maskd=200; - var d=160; - var choices=[]; - var score = 0; - var correct; - var speed = 2000; - var playerCorrect = 0; - var endTimerX = 80; - var startTimerY = 10; - var endTimerY = 100; - var offsetTimerY = 5; - var timerId; - - var timerFn = function () { - k.canvases['timer'].clear(); - - if ( startTimerY >= endTimerY ){ - //you didn't answer in time - k.sounds["trigger"].play(); - answer(false, true); - game(); - } - else { - k.canvases['timer'].clear(); - startTimerY = startTimerY + offsetTimerY; - k.canvases['timer'].ctx.fillStyle = "#fff"; - k.canvases['timer'].ctx.fillRect(10, startTimerY, endTimerX, 20); - } - }; - - - function game () { - $.each(k.canvases, function () { - if (this.name != "chimp"){ - this.clear(); - } - }); - - - writeScore(); - total = k.rand( 2, 10 ); //the total - n0 = total - k.rand(1, total - 1 ); //first number - n1 = total - n0; //second number - - //chose one option (the correct option) - //and then put the correct value into it - correct = k.rand( 0, 2 ); - choices[ correct ] = total; - - for (var i=0; i<3; i++) { - //generate the two other options - if ( choices[i] === total) { - continue; - } else { - // generate the other options - choices[ i ] = k.rand( 2, 10 ); - for (var j = 0; j < i; j++){ - if (choices[i] === choices[j]) { - choices[ i ] = k.rand( 2, 10 ); - } - } - } - } - - var imgId = imgNames[ level ] ; - - - var card = function (surface, n, minx, miny, d ) { - surface.save(); - //var r = k.rectangle({x:minx, y:miny, width:maskd, height:maskd, - // stroke:false,fill:false}).draw(surface); - - // var r = surface.rectangle({x:minx, y:miny, width:maskd, height:maskd, - // stroke:false,fill:false} ); - - //do the clip - //surface.clip(); - var pos = []; - var x, y, flag; - - - for (var i=0; i<n; i++) { - do { - flag = false; - x = k.rand( 0, d ); - y = k.rand( 0, d ); - for ( var j=0; j<pos.length; j++) { - if ( k.distance2( pos[j], - {"x": x, "y": y} ) < 120 ) { - flag = true; - break; - } - } - - }while ( flag === true ); - pos.push( { "x":x, "y": y } ); - //k.images[ imgId ].draw(surface, x, y ) - surface.drawImage(k.images[imgId], x, y); - } - - - - surface.restore(); - } - - - //put the cards - card(k.canvases["topLt"], n0 , 0, 0, d); - card(k.canvases["topRt"], n1 , 0, 0, d); - card(k.canvases["bottomLt"], choices[ 0 ] , 0, 0, d); - card(k.canvases["bottomMd"], choices[ 1 ] , 0, 0, d); - card(k.canvases["bottomRt"], choices[ 2 ] , 0, 0, d); - - } - - var writeScore = function (){ - k.canvases["scorebox"].save(). - clear(). - font("bold 50px sans-serif white"). - fillStyle("#fff"). - textBaseline("middle"). - fillText("" + score, 30, 100). - restore(); - }; - - var answer = function (correct, tooSlow) { - - if ( correct === false) { - //answer was incorrect or took too long - score = score - 1; - playerCorrect = playerCorrect - 1; - writeScore(); - if (tooSlow === true) { - k.sounds[ "trigger" ].play(); - } else { - k.sounds[ "incorrect" ].play(); - } - //animate sad monkey - animateChimp(false); - - } else { - score = score + 1; - playerCorrect = playerCorrect + 1; - writeScore(); - k.sounds[ "correct" ].play(); - animateChimp(true); - if (playerCorrect === 5){ - level = (level+1)% imgNames.length; - speed = speed - 300; - playerCorrect = 0; - } - } - - changeTimer('start'); - - }; - - var animateChimp = function (answer) { - var timerChimp; - k.canvases["chimp"].clear(); - if( answer === true){ - //k.images["happyChimp"].draw(k.canvases["chimp"], 0, 0); - k.canvases["chimp"].drawImage(k.images["happyChimp"], 0, 0); - } else { - k.canvases["chimp"].drawImage(k.images["sadChimp"], 0, 0); - } - - var restoreChimp = function () { - k.canvases["chimp"].clear(); - k.canvases["chimp"].drawImage(k.images["normalChimp"], 0, 0); - }; - - timerChimp = setTimeout(restoreChimp, 800); - - - }; - - var changeTimer = function (status){ - startTimerY = 10; - k.canvases["timer"].clear(); - clearInterval(timerId); - - if (status === 'start'){ - timerId = setInterval(timerFn, speed); - } - - }; - - var startStop = function (start) { - score = level = 0; - startTimerY = 10; - $.each(k.canvases, function () { - if (this.name != "chimp"){ - this.clear(); - } - }); - - changeTimer('start'); - game(); - - - }; - - var start = function () { - startStop(true); - }; - - - var stop = function () { - changeTimer('stop'); - }; - - var reset = function () { - startStop(true); - }; - - - - - - //put the buttons - var buttons=[]; - buttons[ 0 ] = { "surface": k.canvases["bottomLt"], "id": 0}; - buttons[ 1 ] = { "surface": k.canvases["bottomMd"], "id": 1}; - buttons[ 2 ] = { "surface": k.canvases["bottomRt"], "id": 2}; - - $.each(buttons, function( key, item ) { - item.surface.node.addEventListener('click', function( ev ) { - if ( choices[ item.id ] === total){ - answer(true); - game(); - }else { - answer(false); - game(); - } - - }, false); - }); - - document.getElementById('start'). - addEventListener('click', start, false); - - - document.getElementById('stop'). - addEventListener('click', stop, false); - - document.getElementById('reset'). - addEventListener('click', reset, false); - - k.canvases["chimp"].drawImage(k.images["normalChimp"], 0, 0); - - //end of Karma.main - }); -*/ - - //end of ready - }); - });
\ No newline at end of file diff --git a/examples/adding_up_to_10_svg/js/lesson.js b/examples/adding_up_to_10_svg/js/lesson.js index b591973..40e4b1e 100755 --- a/examples/adding_up_to_10_svg/js/lesson.js +++ b/examples/adding_up_to_10_svg/js/lesson.js @@ -84,13 +84,13 @@ k.ready(function() { box.set.remove(); }); - totalCorrect = k.rand( 2, 5 + level ); //the totalCorrect - n0 = totalCorrect - k.rand(1, totalCorrect - 1 ); //first number + totalCorrect = Karma.rand( 2, 5 + level ); //the totalCorrect + n0 = totalCorrect - Karma.rand(1, totalCorrect - 1 ); //first number n1 = totalCorrect - n0; //second number //chose one option (the correct option) //and then put the correct value into it - correctCard = k.rand( 0, 2 ); + correctCard = Karma.rand( 0, 2 ); choices[ correctCard ] = totalCorrect; var computeUniqueChoice = function(choice){ @@ -98,7 +98,7 @@ k.ready(function() { if (choice === totalCorrect) { return choice; } else { - newChoice = k.rand( 1, 10 ); + newChoice = Karma.rand( 1, 10 ); if (newChoice === totalCorrect){ return computeUniqueChoice(choice); } else { @@ -121,10 +121,10 @@ k.ready(function() { for (var i=0; i<n; i++) { do { isOverlapping = false; - x = k.rand( 0, DRAW_MAX_X); - y = k.rand( 0, DRAW_MAX_Y ); + x = Karma.rand( 0, DRAW_MAX_X); + y = Karma.rand( 0, DRAW_MAX_Y ); for ( var j=0; j<positions.length; j++) { - if ( k.distance2( positions[j], + if ( Karma.distance2( positions[j], {"x": x, "y": y} ) < 137 ) { isOverlapping = true; break; |