Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / how to make a wheel of fortune type wheel

Author
Message
Donald Smith
17
Years of Service
User Offline
Joined: 15th Nov 2002
Location:
Posted: 23rd Feb 2011 20:35
How do I go about making a multi colored wheel like the Wheel of Fortune wheel? I'm not looking for the numbers on the wheel, however. I'm a noveice to this and thanks for the advice.
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Feb 2011 01:47 Edited at: 24th Feb 2011 01:51
Interesting problem...

1.
Firstly, we can solve the problem of the different colours. Let's store them in an array so they're easy to access.

If you are unfamiliar with arrays just ask.


2.
Now let's figure out how to draw a circle in segments.
Well here's a way to draw a circle bit by bit using our own maths:

sine and cosine compliment each other in a very useful way.

Now let's try filling in that circle:

hmmm, not perfect but it will do for now.


3.
Now we simply change colour every so often to get the wheel of fortune effect:



4.
Now we've finished, all that's left to do is spin that wheel!

Did you notice I changed the c(6) to c(5), that's because I forgot about 0, so c(6) actually has 7 elements and I couldn't be bothered to work out 360/7 so I took it down to c(5) (six elements) which is easier: 360/6 = 60, so each segment is 60 degrees.


Everything worthwhile requires effort.
Donald Smith
17
Years of Service
User Offline
Joined: 15th Nov 2002
Location:
Posted: 24th Feb 2011 07:07
Ok, thanks for your help. So I've modified the code to make 24 segments instead of 6 and for testing I've included a GOTO statement.



Now, each time the wheel is spun the random colors stay the same but the colors move positions. How can I keep the colors where they are for subsquent spins?

Thanks, Donald
LBFN
13
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 24th Feb 2011 14:54 Edited at: 24th Feb 2011 14:54
You can also draw lines to make up the wheel. I have edited the code to include that. It seems to work a little faster, but you still have some black dots here and there.

Many consider using GOTOs a poor programming practice that can be avoided by restructuring your code in most every case. I have included the use of a subroutine to show how it can be easily done.



Note: keystate(57) is the same as the spacekey.


Hope this helps.

LB

Donald Smith
17
Years of Service
User Offline
Joined: 15th Nov 2002
Location:
Posted: 24th Feb 2011 20:32
Ok, Thank you. Is there any way that the dots can be removed when the colored seqments are being drawn by the sin and cos functions?

In playing with the code, this draws more of the circle but it spins more slowly.



Thanks again, Donald
LBFN
13
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 25th Feb 2011 00:28
Do you need to create the wheel in the code? Why not make a wheel image using PhotoShop or even MS Paint, load it in and then texture a plane with it and rotate the plane to spin it?

Donald Smith
17
Years of Service
User Offline
Joined: 15th Nov 2002
Location:
Posted: 25th Feb 2011 05:04
That was one idea I had, which brings up a question. If I go that route, how do I texture a plane with an image and spin it?
LBFN
13
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 25th Feb 2011 17:20
It was easier for me just to write the code than to explain how it is done, so here you go:



I simply grabbed an image off the internet and made some quick changes to it. I have attached it to this post. Place it in the same folder as the .dba file for this and it should work fine. Note: I normally wouldn't use a .jpg, but they upload better on here.

I placed some comments in the code. If you have any questions, just ask.

Attachments

Login to view attachments
Latch
14
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 25th Feb 2011 21:37
@Donald Smith
Since you are already considering using 3d (a plain object) to make your wheel, you can take it a step further and build your wheel out of triangles with very little code. The following snippet explains the steps in detail as well as providing the actual code. For controlling the spinning, you can look to LBFN's code.



What's nice about this code is, you can change the value of slicecount and it will recalculate all of the triangles and angles that you need.

Enjoy your day.
Donald Smith
17
Years of Service
User Offline
Joined: 15th Nov 2002
Location:
Posted: 25th Feb 2011 23:40
Ok, how do I know or assign the dollar values the each wedge using a 3d model? It seems like using OBese87's code (thinking ahead), I make a black wedge (Bankrupt) and a white wedge (Lose a Turn). In the dim statement, I can add the dollar amounts for the colored wedges (I'll see dots in the circles). But, having three players, how I can I program whose players' pointer is the dollar amount under the colored wedge?

Sorry to be bothersome, but I really do appreciate the help.

Donald
Latch
14
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 26th Feb 2011 03:55 Edited at: 26th Feb 2011 03:59
In all of the examples, there are some consistencies: the wheel spins, the wedges are spaced based on a certain angle. Most likely, each player has a ticker at a certain position on the wheel. This position is at some angle relative to the center of the circle. As the wheel spins, it's rotation angle changes. Using the change in rotation and the fixed positional angles of the players, you can find which section of the wheel is closest to which player i.e. which players ticker is on which section of the wheel.

For example: if the wheel was in only 2 sections (wedges) and before the wheel was ever rotated it's rotation is 0 degree, the top wedge may be represented by 1 to 180 degrees and the bottom would be from 181 to 360 degrees. If player 1s ticker angle at 90 degrees then it would be within wheel wedge 1.

Now,when you spin the wheel, you add the wheels rotation to the fixed sections angles. If the wheel turned 45 degrees,then section 1 changes from 1 to 180, to 46 to 235. We can see that player 1's ticker is still in section 1. Not until the wheel has rotated at least 180 degrees does player 1s ticker register in section 2.

Depending on how many wedges there are, each wedge is going to have a start and end angle. As the wheel turns, you add the wheels rotation to the wedge angles. I a players ticker angle is within that range,you know which wedge the player is pointing at.

This applies to 2d and 3d.

Enjoy your day.

Login to post a reply

Server time is: 2020-08-06 08:29:32
Your offset time is: 2020-08-06 08:29:32