Cjmarkham
Cjmarkham

Reputation: 9681

HTML5 Canvas roulette wheel

I have built a roulette wheel in canvas and JS. The wheel has 12 segments which are 30 degrees wide.

I would like it so that when the wheel rotates past a wheel segment, a sound is played. I have tried to use modulus but could not get it working. Any tips or advice?

if (rotation % 30 == 0) {
    playSound();
}

Upvotes: 0

Views: 1445

Answers (1)

Denys Séguret
Denys Séguret

Reputation: 382130

Supposing your rotation in is degree, you probably want

if (((rotation+360)%360)<30) {

This starts by computing an angle between 0 and 360.

If you angle is in radian, which is the native unit of Canvas, you might do

 if (((rotation+2*Math.PI)%(2*Math.PI))<Math.PI/6) {

Upvotes: 4

Related Questions