-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from zarocknz/multiline-text
MAJOR: added Multiline text feature, image wheel example, fix bug in one image per segment.
- Loading branch information
Showing
8 changed files
with
799 additions
and
462 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
<!-- | ||
Winhweel.js basic code wheel example by Douglas McKechie @ www.dougtesting.net | ||
See website for tutorials and other documentation. | ||
The MIT License (MIT) | ||
Copyright (c) 2016 Douglas McKechie | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
--> | ||
<html> | ||
<head> | ||
<title>HTML5 Canvas Winning Wheel</title> | ||
<link rel="stylesheet" href="main.css" type="text/css" /> | ||
<script type="text/javascript" src="../../Winwheel.js"></script> | ||
<script src="http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenMax.min.js"></script> | ||
</head> | ||
<body> | ||
<div align="center"> | ||
<h1>Winwheel.js example wheel - basic image wheel</h1> | ||
<p>Here is an example of a basic image drawn wheel, where the entire face of the wheel has been created out of a graphically rich image.</p> | ||
<br /> | ||
<p>Choose a power setting then press the Spin button. You will be alerted to the prize won when the spinning stops.</p> | ||
<br /> | ||
<table cellpadding="0" cellspacing="0" border="0"> | ||
<tr> | ||
<td> | ||
<div class="power_controls"> | ||
<br /> | ||
<br /> | ||
<table class="power" cellpadding="10" cellspacing="0"> | ||
<tr> | ||
<th align="center">Power</th> | ||
</tr> | ||
<tr> | ||
<td width="78" align="center" id="pw3" onClick="powerSelected(3);">High</td> | ||
</tr> | ||
<tr> | ||
<td align="center" id="pw2" onClick="powerSelected(2);">Med</td> | ||
</tr> | ||
<tr> | ||
<td align="center" id="pw1" onClick="powerSelected(1);">Low</td> | ||
</tr> | ||
</table> | ||
<br /> | ||
<img id="spin_button" src="spin_off.png" alt="Spin" onClick="startSpin();" /> | ||
<br /><br /> | ||
<a href="#" onClick="resetWheel(); return false;">Play Again</a><br /> (reset) | ||
</div> | ||
</td> | ||
<td width="318" height="418" class="the_wheel" align="center" valign="center"> | ||
<canvas id="canvas" width="315" height="418"> | ||
<p style="{color: white}" align="center">Sorry, your browser doesn't support canvas. Please try another.</p> | ||
</canvas> | ||
</td> | ||
</tr> | ||
</table> | ||
<script> | ||
// Create new wheel object specifying the parameters at creation time. | ||
var theWheel = new Winwheel({ | ||
'numSegments' : 4, // Specify number of segments. | ||
'outerRadius' : 150, // Set outer radius so wheel fits inside the background. | ||
'drawMode' : 'image', // drawMode must be set to image. | ||
'drawText' : true, // Need to set this true if want code-drawn text on image wheels. | ||
'textFontSize' : 12, // Set text options as desired. | ||
'textOrientation' : 'curved', | ||
'textDirection' : 'reversed', | ||
'textAlignment' : 'outer', | ||
'textMargin' : 5, | ||
'textFontFamily' : 'monospace', | ||
'textStrokeStyle' : 'black', | ||
'textLineWidth' : 2, | ||
'textFillStyle' : 'white', | ||
'segments' : // Define segments. | ||
[ | ||
{'text' : 'T-55 Vampire'}, | ||
{'text' : 'P-40 Kittyhawk'}, | ||
{'text' : 'North American Harvard'}, | ||
{'text' : 'L-39C Albatross'} | ||
], | ||
'animation' : // Specify the animation to use. | ||
{ | ||
'type' : 'spinToStop', | ||
'duration' : 5, // Duration in seconds. | ||
'spins' : 8, // Number of complete spins. | ||
'callbackFinished' : 'alertPrize()' | ||
} | ||
}); | ||
|
||
// Create new image object in memory. | ||
var loadedImg = new Image(); | ||
|
||
// Create callback to execute once the image has finished loading. | ||
loadedImg.onload = function() | ||
{ | ||
theWheel.wheelImage = loadedImg; // Make wheelImage equal the loaded image object. | ||
theWheel.draw(); // Also call draw function to render the wheel. | ||
} | ||
|
||
// Set the image source, once complete this will trigger the onLoad callback (above). | ||
loadedImg.src = "planes.png"; | ||
|
||
|
||
|
||
// Vars used by the code in this page to do power controls. | ||
var wheelPower = 0; | ||
var wheelSpinning = false; | ||
|
||
// ------------------------------------------------------- | ||
// Function to handle the onClick on the power buttons. | ||
// ------------------------------------------------------- | ||
function powerSelected(powerLevel) | ||
{ | ||
// Ensure that power can't be changed while wheel is spinning. | ||
if (wheelSpinning == false) | ||
{ | ||
// Reset all to grey incase this is not the first time the user has selected the power. | ||
document.getElementById('pw1').className = ""; | ||
document.getElementById('pw2').className = ""; | ||
document.getElementById('pw3').className = ""; | ||
|
||
// Now light up all cells below-and-including the one selected by changing the class. | ||
if (powerLevel >= 1) | ||
{ | ||
document.getElementById('pw1').className = "pw1"; | ||
} | ||
|
||
if (powerLevel >= 2) | ||
{ | ||
document.getElementById('pw2').className = "pw2"; | ||
} | ||
|
||
if (powerLevel >= 3) | ||
{ | ||
document.getElementById('pw3').className = "pw3"; | ||
} | ||
|
||
// Set wheelPower var used when spin button is clicked. | ||
wheelPower = powerLevel; | ||
|
||
// Light up the spin button by changing it's source image and adding a clickable class to it. | ||
document.getElementById('spin_button').src = "spin_on.png"; | ||
document.getElementById('spin_button').className = "clickable"; | ||
} | ||
} | ||
|
||
// ------------------------------------------------------- | ||
// Click handler for spin button. | ||
// ------------------------------------------------------- | ||
function startSpin() | ||
{ | ||
// Ensure that spinning can't be clicked again while already running. | ||
if (wheelSpinning == false) | ||
{ | ||
// Based on the power level selected adjust the number of spins for the wheel, the more times is has | ||
// to rotate with the duration of the animation the quicker the wheel spins. | ||
if (wheelPower == 1) | ||
{ | ||
theWheel.animation.spins = 2; | ||
} | ||
else if (wheelPower == 2) | ||
{ | ||
theWheel.animation.spins = 5; | ||
} | ||
else if (wheelPower == 3) | ||
{ | ||
theWheel.animation.spins = 8; | ||
} | ||
|
||
// Disable the spin button so can't click again while wheel is spinning. | ||
document.getElementById('spin_button').src = "spin_off.png"; | ||
document.getElementById('spin_button').className = ""; | ||
|
||
// Begin the spin animation by calling startAnimation on the wheel object. | ||
theWheel.startAnimation(); | ||
|
||
// Set to true so that power can't be changed and spin button re-enabled during | ||
// the current animation. The user will have to reset before spinning again. | ||
wheelSpinning = true; | ||
} | ||
} | ||
|
||
// ------------------------------------------------------- | ||
// Function for reset button. | ||
// ------------------------------------------------------- | ||
function resetWheel() | ||
{ | ||
theWheel.stopAnimation(false); // Stop the animation, false as param so does not call callback function. | ||
theWheel.rotationAngle = 0; // Re-set the wheel angle to 0 degrees. | ||
theWheel.draw(); // Call draw to render changes to the wheel. | ||
|
||
document.getElementById('pw1').className = ""; // Remove all colours from the power level indicators. | ||
document.getElementById('pw2').className = ""; | ||
document.getElementById('pw3').className = ""; | ||
|
||
wheelSpinning = false; // Reset to false to power buttons and spin can be clicked again. | ||
} | ||
|
||
// ------------------------------------------------------- | ||
// Called when the spin animation has finished by the callback feature of the wheel because I specified callback in the parameters. | ||
// ------------------------------------------------------- | ||
function alertPrize() | ||
{ | ||
// Get the segment indicated by the pointer on the wheel background which is at 0 degrees. | ||
var winningSegment = theWheel.getIndicatedSegment(); | ||
|
||
// Do basic alert of the segment text. You would probably want to do something more interesting with this information. | ||
alert("The wheel stopped on " + winningSegment.text); | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
Description: | ||
Contains all the styles for the winning wheel page. | ||
Verison History: | ||
2012-01-28, Douglas McKechie | ||
- Created based off earlier version. | ||
2015-09-26, Douglas McKechie | ||
- Minor updates for the 2.0 winwheel example. | ||
*/ | ||
|
||
body | ||
{ | ||
font-family: arial; | ||
} | ||
|
||
/* Sets the background image for the wheel */ | ||
td.the_wheel | ||
{ | ||
background-image: url(./wheel_back.png); | ||
background-position: center; | ||
background-repeat: none; | ||
} | ||
|
||
/* Do some css reset on selected elements */ | ||
h1, p | ||
{ | ||
margin: 0; | ||
} | ||
|
||
div.power_controls | ||
{ | ||
margin-right:70px; | ||
} | ||
|
||
div.html5_logo | ||
{ | ||
margin-left:70px; | ||
} | ||
|
||
/* Styles for the power selection controls */ | ||
table.power | ||
{ | ||
background-color: #cccccc; | ||
cursor: pointer; | ||
border:1px solid #333333; | ||
} | ||
|
||
table.power th | ||
{ | ||
background-color: white; | ||
cursor: default; | ||
} | ||
|
||
td.pw1 | ||
{ | ||
background-color: #6fe8f0; | ||
} | ||
|
||
td.pw2 | ||
{ | ||
background-color: #86ef6f; | ||
} | ||
|
||
td.pw3 | ||
{ | ||
background-color: #ef6f6f; | ||
} | ||
|
||
/* Style applied to the spin button once a power has been selected */ | ||
.clickable | ||
{ | ||
cursor: pointer; | ||
} | ||
|
||
/* Other misc styles */ | ||
.margin_bottom | ||
{ | ||
margin-bottom: 5px; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.