Can my wheel stop on more than one preselected segment?
eddytele opened this issue · 2 comments
eddytele commented
Hello,
I would like my wheel to stop on more than one of any preselected segments e.g segment 4, 7, 9, 10 only. Is it possible? Have I tried the code below in vain. I have tested with 'or', 'and' javascript functions but the wheel only stops on one segment. Please help.
// Function with formula to work out stopAngle before spinning animation.
// Called from Click of the Spin button.
function calculatePrize()
{
// This formula always makes the wheel stop somewhere inside prizes at least
// 1 degree away from the start and end edges of the segment.
let stopAt = (91 + Math.floor((Math.random() * 43)))
||
let stopAt = (181 + Math.floor((Math.random() * 43)))
||
let stopAt = (271 + Math.floor((Math.random() * 43)))
// Important thing is to set the stopAngle of the animation before stating the spin.
theWheel.animation.stopAngle = stopAt;
// May as well start the spin from here.
theWheel.startAnimation();
}
Thanks
Eddy
Lbdevaa commented
Did you decided?
zarocknz commented
The code in the example is not valid JavaScript which is why it does not work.
I would simply add the possible options to an array and then use the Math.random() in JavaScript to choose one of the options, at random.
There is a also a getRandomForSegment(int segmentNumber) function in winWheel.js which can be used to pick a random angle inside a segment. I will use this in the example....
let winningSegments = [
theWheel.getRandomForSegment(4),
theWheel.getRandomForSegment(7),
theWheel.getRandomForSegment(9),
theWheel.getRandomForSegment(10)
];
let stopAt = winningSegments[Math.floor(Math.random() * Math.floor(winningSegments.length));