ALERT!
Click here to register with a few steps and explore all our cool stuff we have to offer!

Jump to content



Photo

JS/Html help


  • Please log in to reply
JS/Html help

#1

THEMIGHTYTHOR
THEMIGHTYTHOR
    Offline
    55
    Rep
    523
    Likes

    The God Butcher

  • PipPipPipPipPipPipPip
Posts: 1202
Threads: 309
Joined: Mar 02, 2018
Credits: 0

Deal with caution
User has an open scam report.
Six years registered
#1

<script>
var options = ["$100", "$10", "$25", "$250", "$30", "$1000", "$1", "$200", "$45", "$500", "$5", "$20", "Lose", "$1000000", "Lose", "$350", "$5", "$99"];

var startAngle = 0;
var arc = Math.PI / (options.length / 2);
var spinTimeout = null;

var spinArcStart = 10;
var spinTime = 0;
var spinTimeTotal = 0;

var ctx;

document.getElementById("spin").addEventListener("click", spin);

function byte2Hex(n) {
  var nybHexString = "0123456789ABCDEF";
  return String(nybHexString.substr((n >> 4) & 0x0F,1)) + nybHexString.substr(n & 0x0F,1);
}

function RGB2Color(r,g,B) {
return '#' + byte2Hex® + byte2Hex(g) + byte2Hex(B);
}

function getColor(item, maxitem) {
  var phase = 0;
  var center = 128;
  var width = 127;
  var frequency = Math.PI*2/maxitem;
 
  red   = Math.sin(frequency*item+2+phase) * width + center;
  green = Math.sin(frequency*item+0+phase) * width + center;
  blue  = Math.sin(frequency*item+4+phase) * width + center;
 
  return RGB2Color(red,green,blue);
}

function drawRouletteWheel() {
  var canvas = document.getElementById("canvas");
  if (canvas.getContext) {
    var outsideRadius = 200;
    var textRadius = 160;
    var insideRadius = 125;

    ctx = canvas.getContext("2d");
    ctx.clearRect(0,0,500,500);

    ctx.strokeStyle = "black";
    ctx.lineWidth = 2;

    ctx.font = 'bold 12px Helvetica, Arial';

    for(var i = 0; i < options.length; i++) {
      var angle = startAngle + i * arc;
      //ctx.fillStyle = colors[i];
      ctx.fillStyle = getColor(i, options.length);

      ctx.beginPath();
      ctx.arc(250, 250, outsideRadius, angle, angle + arc, false);
      ctx.arc(250, 250, insideRadius, angle + arc, angle, true);
      ctx.stroke();
      ctx.fill();

      ctx.save();
      ctx.shadowOffsetX = -1;
      ctx.shadowOffsetY = -1;
      ctx.shadowBlur    = 0;
      ctx.shadowColor   = "rgb(220,220,220)";
      ctx.fillStyle = "black";
      ctx.translate(250 + Math.cos(angle + arc / 2) * textRadius,
                    250 + Math.sin(angle + arc / 2) * textRadius);
      ctx.rotate(angle + arc / 2 + Math.PI / 2);
      var text = options[i];
      ctx.fillText(text, -ctx.measureText(text).width / 2, 0);
      ctx.restore();
    }

    //Arrow
    ctx.fillStyle = "black";
    ctx.beginPath();
    ctx.moveTo(250 - 4, 250 - (outsideRadius + 5));
    ctx.lineTo(250 + 4, 250 - (outsideRadius + 5));
    ctx.lineTo(250 + 4, 250 - (outsideRadius - 5));
    ctx.lineTo(250 + 9, 250 - (outsideRadius - 5));
    ctx.lineTo(250 + 0, 250 - (outsideRadius - 13));
    ctx.lineTo(250 - 9, 250 - (outsideRadius - 5));
    ctx.lineTo(250 - 4, 250 - (outsideRadius - 5));
    ctx.lineTo(250 - 4, 250 - (outsideRadius + 5));
    ctx.fill();
  }
}

function spin() {
  spinAngleStart = Math.random() * 10 + 10;
  spinTime = 0;
  spinTimeTotal = Math.random() * 3 + 4 * 1000;
  rotateWheel();
}

function rotateWheel() {
  spinTime += 15;
  if(spinTime >= spinTimeTotal) {
    stopRotateWheel();
    return;
  }
  var spinAngle = spinAngleStart - easeOut(spinTime, 0, spinAngleStart, spinTimeTotal);
  startAngle += (spinAngle * Math.PI / 180);
  drawRouletteWheel();
  spinTimeout = setTimeout('rotateWheel()', 30);
}

function stopRotateWheel() {
  clearTimeout(spinTimeout);
  var degrees = startAngle * 180 / Math.PI + 90;
  var arcd = arc * 180 / Math.PI;
  var index = Math.floor((360 - degrees % 360) / arcd);
  ctx.save();
  ctx.font = 'bold 30px Helvetica, Arial';
  var text = options[index]
  ctx.fillText(text, 250 - ctx.measureText(text).width / 2, 250 + 10);
  ctx.restore();
}

function easeOut(t, b, c, d) {
  var ts = (t/=d)*t;
  var tc = ts*t;
  return b+c*(tc + -3*ts + 3*t);
}

drawRouletteWheel();
</script>

 

So I made this script with a tutorial, but I want it to play a certain music and to popup a message when you win for an example $50

 

 


  • 0

#2

MrEchoTM
MrEchoTM
    Offline
    6
    Rep
    46
    Likes

    Web Developer

Posts: 184
Threads: 41
Joined: Sep 03, 2017
Credits: 0

Six years registered
#2

@WallyWest ,

 

If you want help, please add the html part too.


Edited by MrEchoTM, 20 April 2018 - 08:39 PM.

  • 0

I am a developer. ^^

DM me or join My discord server: discord.gg/peyGZKU


#3

THEMIGHTYTHOR
THEMIGHTYTHOR
    Offline
    55
    Rep
    523
    Likes

    The God Butcher

  • PipPipPipPipPipPipPip
Posts: 1202
Threads: 309
Joined: Mar 02, 2018
Credits: 0

Deal with caution
User has an open scam report.
Six years registered
#3

@WallyWest ,

 

If you want help, please add the html part too.

Its fine, I know JS and html abit better now so i learned this lol


  • 0

#4

minnosbrtt3
minnosbrtt3
    Offline
    0
    Rep
    0
    Likes

    New Member

  • PipPip
Posts: 13
Threads: 0
Joined: Apr 18, 2018
Credits: 0
Six years registered
#4

What error ? 


  • 0

#5

MrEchoTM
MrEchoTM
    Offline
    6
    Rep
    46
    Likes

    Web Developer

Posts: 184
Threads: 41
Joined: Sep 03, 2017
Credits: 0

Six years registered
#5

Its fine, I know JS and html abit better now so i learned this lol

 

@WallyWest ,

 

Okay, if you want help you can contact me anytime. :*


  • 0

I am a developer. ^^

DM me or join My discord server: discord.gg/peyGZKU



 Users browsing this thread: