HTML5 Canvas Disc Draw Application Demo Demo

Source: Internet
Author: User

Remember before we shared a disk lottery based on jquery plug-ins, you can use this plugin in their own website to provide users with a number of lottery activities. Today to share is also a disc lottery application, but it is based on HTML5 canvas, the operating principle is similar to the use of random number principle to achieve lottery results.

HTML code

The code is as follows Copy Code


<! DOCTYPE html>
<meta charset= "UTF-8" >
&LT;TITLE&GT;HTML5 Canvas Disc Draw Application Demo Demo </title>
<meta name= "viewport" content= "Width=device-width, initial-scale=1, User-scalable=no" >
<link rel= "stylesheet" type= "Text/css" href= "Css/main.css" >
<script type= "Text/javascript" src= "Js/jquery-1.11.3.min.js" ></script>
<script type= "Text/javascript" src= "Js/main.js" >
</script>
<body>
<div class= "Turnplate_box" >
<canvas id= "MyCanvas" width= "300px" height= "300px" > Sorry! Browser not supported. </canvas>
<canvas id= "myCanvas01" width= "200px" height= "200px" > Sorry! Browser not supported. </canvas>
<canvas id= "MyCanvas03" width= "200px" height= "200px" > Sorry! Browser not supported. </canvas>
<canvas id= "MyCanvas02" width= "150px" height= "150px" > Sorry! Browser not supported. </canvas>
<button id= "tupbtn" class= "turnplatw_btn" ></button>
</div>
<!--change the system default window-->
<script type= "Text/javascript" >
Window.alert = function (str)
{
var shield = document.createelement ("DIV");
Shield.id = "shield";
Shield.style.position = "absolute";
Shield.style.left = "50%";
Shield.style.top = "50%";
Shield.style.width = "280px";
Shield.style.height = "150px";
Shield.style.marginLeft = " -140px";
Shield.style.marginTop = " -110px";
Shield.style.zIndex = "25";
var Alertfram = document.createelement ("DIV");
Alertfram.id= "Alertfram";
AlertFram.style.position = "absolute";
AlertFram.style.width = "280px";
AlertFram.style.height = "150px";
AlertFram.style.left = "50%";
AlertFram.style.top = "50%";
AlertFram.style.marginLeft = " -140px";
AlertFram.style.marginTop = " -110px";
alertFram.style.textAlign = "center";
AlertFram.style.lineHeight = "150px";
AlertFram.style.zIndex = "300";
strhtml = "<ul style=\" list-style:none;margin:0px;padding:0px;width:100%\ ">\n";
strHTML + = "<li style=\" background: #626262; text-align:left;padding-left:20px;font-size:14px;font-weight:bold; height:25px;line-height:25px;border:1px solid #F9CADE; color:white\ ">[Winning reminder]</li>\n";
strHTML + = "<li style=\" background: #787878; text-align:center;font-size:12px;height:95px;line-height:95px; BORDER-LEFT:1PX solid #F9CADE border-right:1px solid #F9CADE; color: #DCC722 \ ">" +str+ "</li>\n";
strHTML + = "<li style=\" background: #626262; text-align:center;font-weight:bold;height:30px;line-height:25px; border:1px solid #F9CADE; \ "><input type=\" button\ "value=\" OK \ "Onclick=\" Dook () \ "Style=\" Width:80px;height : 20px;background: #626262; color:white;border:1px solid white;font-size:14px;line-height:20px;outline:none; Margin-top:4px\ "/></li>\n";
strHTML + = "</ul>\n";
alertfram.innerhtml = strhtml;
Document.body.appendChild (Alertfram);
Document.body.appendChild (shield);
This.dook = function () {
AlertFram.style.display = "None";
Shield.style.display = "None";
}
Alertfram.focus ();
Document.body.onselectstart = function () {return false;};
}
</script>

<div style= "text-align:center;clear:both;margin-top:50px" >
<script src= "/gg_bd_ad_720x90.js" type= "Text/javascript" ></script>
<script src= "/follow.js" type= "Text/javascript" ></script>
</div>
</body>

Main.js file

The code is as follows Copy Code

$ (document). Ready (function () {
Rotation angle
var angles;
Number of lottery draws available
var clicknum = 5;
Number of rotations
var rotnum = 0;
Jackpot Announcement
var notice = null;
Turntable initialization
var color = ["#626262", "#787878", "Rgba (0,0,0,0.5)", "#DCC722", "White", "#FF4350"];
var info = ["Thank you for participating", "1000", "10", "500", "100", "4999", "1", "20"];
var info1 = [' persistent ', ' yuan ', ' yuan ', ' Gold coin ', ' yuan ', ' Gold coin ', ' yuan ', ' gold coin ']
Canvasrun ();
$ (' #tupBtn '). Bind (' click ', function () {
if (clicknum >= 1) {
The number of lottery can be reduced by one
Clicknum = clickNum-1;
Turntable rotation
Runcup ();
The "Start Draw" button cannot be clicked on the turntable rotation process
$ (' #tupBtn '). attr ("Disabled", true);
Rotate the number of times plus a
Rotnum = Rotnum + 1;
"Start Draw" button cannot click Resume click
settimeout (function () {
alert (notice);
$ (' #tupBtn '). Removeattr ("Disabled", true);
},6000);
}
else{
Alert ("Pro, draw the number of times has been exhausted!" ");
}
});

Turntable rotation
function Runcup () {
Probability ();
var degvalue = ' rotate (' +angles+ ' deg ' + ') ';
$ (' #myCanvas '). CSS ('-o-transform ', degvalue); Opera
$ (' #myCanvas '). CSS ('-ms-transform ', degvalue); IE browser
$ (' #myCanvas '). CSS ('-moz-transform ', degvalue); Firefox
$ (' #myCanvas '). CSS ('-webkit-transform ', degvalue); Chrome and Safari
$ (' #myCanvas '). CSS (' transform ', degvalue);
}

The rotation angle of each award and the contents of the winning announcement
function probability () {
Get random numbers
var num = parseint (Math.random () * (7-0 + 0) + 0);
Probability
if (num = 0) {
Angles = 2160 * rotnum + 1800;
Notice = info[0] + info1[0];
}
Probability
else if (num = 1) {
Angles = 2160 * Rotnum + 1845;
Notice = info[7] + info1[7];
}
Probability
else if (num = 2) {
Angles = 2160 * rotnum + 1890;
Notice = info[6] + info1[6];
}
Probability
else if (num = 3) {
Angles = 2160 * Rotnum + 1935;
Notice = info[5] + info1[5];
}
Probability
else if (num = 4) {
Angles = 2160 * Rotnum + 1980;
Notice = info[4] + info1[4];
}
Probability
else if (num = 5) {
Angles = 2160 * rotnum + 2025;
Notice = info[3] + info1[3];
}
Probability
else if (num = 6) {
Angles = 2160 * Rotnum + 2070;
Notice = info[2] + info1[2];
}
Probability
else if (num = 7) {
Angles = 2160 * Rotnum + 2115;
Notice = info[1] + info1[1];
}
}

Draw a turntable
function Canvasrun () {
var Canvas=document.getelementbyid (' MyCanvas ');
var Canvas01=document.getelementbyid (' myCanvas01 ');
var Canvas03=document.getelementbyid (' MyCanvas03 ');
var Canvas02=document.getelementbyid (' MyCanvas02 ');
var ctx=canvas.getcontext (' 2d ');
var ctx1=canvas01.getcontext (' 2d ');
var ctx3=canvas03.getcontext (' 2d ');
var ctx2=canvas02.getcontext (' 2d ');
Createcircle ();
Createcirtext ();
Initpoint ();

Outer Circle
function Createcircle () {
var startangle = start Radian of 0;//sector
var Endangle = end Radian of 0;//sector
Draw a circle of 8 equal parts fan
for (var i = 0; i< 8; i++) {
StartAngle = math.pi* (I/4-1/8);
Endangle = startangle+math.pi* (1/4);
Ctx.save ();
Ctx.beginpath ();
Ctx.arc (150,150,100, StartAngle, Endangle, false);
Ctx.linewidth = 120;
if (i%2 = = 0) {
Ctx.strokestyle = color[0];
}else{
Ctx.strokestyle = color[1];
}
Ctx.stroke ();
Ctx.restore ();
}
}

Various awards
function Createcirtext () {
ctx.textalign= ' Start ';
Ctx.textbaseline= ' Middle ';
Ctx.fillstyle = color[3];
var step = 2*MATH.PI/8;
for (var i = 0; i < 8; i++) {
Ctx.save ();
Ctx.beginpath ();
Ctx.translate (150,150);
Ctx.rotate (I*step);
Ctx.font = "20px Microsoft Yahei";
Ctx.fillstyle = color[3];
Ctx.filltext (info[i],-30,-115,60);
Ctx.font = "14px Microsoft Yahei";
Ctx.filltext (info1[i],-30,-95,60);
Ctx.closepath ();
Ctx.restore ();
}
}

function Initpoint () {
Arrow pointer
Ctx1.beginpath ();
Ctx1.moveto (100,24);
Ctx1.lineto (90,62);
Ctx1.lineto (110,62);
Ctx1.lineto (100,24);
Ctx1.fillstyle = color[5];
Ctx1.fill ();
Ctx1.closepath ();
Middle Small Circle
Ctx3.beginpath ();
Ctx3.arc (100,100,40,0,math.pi*2,false);
Ctx3.fillstyle = color[5];
Ctx3.fill ();
Ctx3.closepath ();
Small round text
Ctx3.font = "Bold 20px Microsoft Yahei";
ctx3.textalign= ' Start ';
Ctx3.textbaseline= ' Middle ';
Ctx3.fillstyle = color[4];
Ctx3.beginpath ();
Ctx3.filltext (' Start ', 80,90,40);
Ctx3.filltext (' lottery ', 80,110,40);
Ctx3.fill ();
Ctx3.closepath ();
Middle Circle
Ctx2.beginpath ();
Ctx2.arc (75,75,75,0,math.pi*2,false);
Ctx2.fillstyle = color[2];
Ctx2.fill ();
Ctx2.closepath ();
}
}
});

The CSS code is as follows

The code is as follows Copy Code
*{
padding:0px;
margin:0px;
font-size:16px;
font-family: "Microsoft Yahei";
}
. turnplate_box{
width:300px;
height:300px;
margin:100px Auto;
position:relative;
}
. Turnplate_box canvas{
Position:absolute;
}
#myCanvas {
Background-color:white;
border-radius:100%;
}
#myCanvas01, #myCanvas03 {
left:50px;
top:50px;
z-index:30;
}
#myCanvas02 {
left:75px;
top:75px;
z-index:20;
}
#myCanvas {
-o-transform:transform 6s;
-ms-transform:transform 6s;
-moz-transform:transform 6s;
-webkit-transform:transform 6s;
Transition:transform 6s;
-o-transform-origin:50% 50%;
-ms-transform-origin:50% 50%;
-moz-transform-origin:50% 50%;
-webkit-transform-origin:50% 50%;
transform-origin:50% 50%;
}
. turnplatw_btn{
width:60px;
height:60px;
left:120px;
top:120px;
border-radius:100%;
Position:absolute;
Cursor:pointer;
Border:none;
Background:transparent;
Outline:none;
z-index:40;
}

Note: The above jquery package is downloaded online, while HTML5 and CSS3 are only supported by a newer version of the browser.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.