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 Professional Discussion / Random dots in a circle

Author
Message
appie21
20
Years of Service
User Offline
Joined: 12th Sep 2005
Location:
Posted: 30th May 2013 11:23
Hello

I have write a code that paint a circle

see


What I need is that there random dots appear in the circle.
How can I made this?
(my mathematics is not so good.. )
ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 30th May 2013 14:37 Edited at: 30th May 2013 14:41
The arguably easiest way to achieve that is using sin/cos to place them directly, given a random angle and distance. So something like this:



However, this will result in an uneven distribution and the dot density around the center of your circle will be higher than in the more distant regions. If you want them to be distributed evenly you could do something like this:



..which will generate random dots in a rectangle and only draw those that are within the circle.

Note: These code snippets are not optimized in any way, you might want to use lock/unlock pixels before and after those loops, and you could easily avoid using sqrt() in the second one by comparing the squared values, but I guess that doesn't really matter all that much right now.

Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 30th May 2013 15:02
http://forum.thegamecreators.com/?m=forum_view&t=195887&b=1

I posted previously about this.

2D draw commands are extremely slow. You will suffer a massive frame rate reduction using them.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th May 2013 16:23
Thanks Mage. Interesting thread. Will have to keep that in mind.
CSL
17
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: USA
Posted: 31st May 2013 20:20
I use lock pixels / unlock pixels between dot commands. It improves performance dramatically. And it works best with manual syncs.

CSL
ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 31st May 2013 23:42
Indeed. However I also realized that the line-command especially is slow as hell. At some point I simply wrote my own line-function that basically just resized a white 1x1 sized sprite to <LineLength>x<LineThickness>, rotated it accordingly, changed diffuse and alpha to achieve the required color and transparency and then pasted that sprite to the given position. Works flawlessly and is a lot faster than the built in function.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Jun 2013 01:09
Interesting. Does that work as well for filled circles, ellipses, etc?
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Jun 2013 00:13
Dot is very slow, locking and unlock the pixels between every call isn't going to improve anything. It's best to batch your drawing together and only unlock when you're done and ready to sync.

Using BOX is also faster than dot. And faster still is plotting the points directly to memory.

These demos were run in a loop without sync or clear screen.

390 fps:



670 fps:




1400fps:


appie21
20
Years of Service
User Offline
Joined: 12th Sep 2005
Location:
Posted: 3rd Jun 2013 08:07
Many thanks I will it try out today!
appie21
20
Years of Service
User Offline
Joined: 12th Sep 2005
Location:
Posted: 3rd Jun 2013 09:09
Hello

The speed is not important


I have work with it and i see dt is not good enough for my project


First I not like random (rnd) because they can the same numer twice or more.. (i want a random with never the same number (is that possible?)

What I really need is that in my circle random circles appear(dots are too small Have I encountered)
But

- Not hit or cross each other
- I can give the radial of the circles(so that i can change the size)
- that i can fill it with a collor
- if the main circle is filled with the circles the count stopped (or that i can give a value how many circles I want in my circle!


Hope some onde could help (and understand my question.. my English :-( )

se the attached image and then complete filled (i have made it in paint)
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 4th Jun 2013 06:05 Edited at: 4th Jun 2013 06:24
That's an interesting pattern. Do you want it to be a fractal so that you have even smaller circles filling in the gaps? Or are we just aiming for one level of circles?

I made this image in inkscape. Is this what you want? ---->

The difficulty in learning is not acquiring new knowledge but relinquishing the old.
appie21
20
Years of Service
User Offline
Joined: 12th Sep 2005
Location:
Posted: 4th Jun 2013 10:05
Yes your image is right!

And if the radial of the circle is smaller there are more cicles inside!
appie21
20
Years of Service
User Offline
Joined: 12th Sep 2005
Location:
Posted: 8th Jun 2013 20:35
Nobody
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 8th Jun 2013 21:23 Edited at: 8th Jun 2013 21:36
I can tell you how to do it, but it will take me a long time to program it.


1/ Use a distance formula to make sure that you are inside the big circle.

2/ Starting at the top scroll along by your Dot radius.

3/ Move down by your small Dot radius.

4/ Store all of the X/Y coordinates in a map .. Dim DotMap(Number,2)

5/ Make another dim for Picked numbers Dim Picked(Number)

6/ Use the Number in your rnd(Number)+1

7/ When the rnd is picked get the associated X/Y and place the dot.

8/ Picked(Number) = 1... picked is true.

9/ When you use RND() make sure that Picked(Number) = 0

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 8th Jun 2013 21:42
Something like this



I'm not a grumpy grandpa
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 9th Jun 2013 02:14 Edited at: 9th Jun 2013 02:49
I've coded the basics. Just need to add a distance check to the far edge of the small circles.


For choosing random circles without duplicates, an efficient solution is to create a list of all possible values and shuffle it:

Then just read off as many items from the shuffled list as you want.

The difficulty in learning is not acquiring new knowledge but relinquishing the old.
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Jun 2013 02:51


Enjoy your day.
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 9th Jun 2013 03:16
I was so close.
Here is Latch's function plugged into my program:


The difficulty in learning is not acquiring new knowledge but relinquishing the old.
appie21
20
Years of Service
User Offline
Joined: 12th Sep 2005
Location:
Posted: 10th Jun 2013 10:12
Thanks all!
You will hear from me!

Login to post a reply

Server time is: 2026-07-07 05:40:47
Your offset time is: 2026-07-07 05:40:47