Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Generating random Draw.Object's in a specified area?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Leftover




PostPosted: Mon Nov 01, 2004 1:11 am   Post subject: Generating random Draw.Object's in a specified area?

It doesn't matter that much really, the program works the way it is supposed to so its not that big of a deal, but for class we were supposed to make a watermelon with 10 randomized seeds (IE. every time the program is run, the seeds are in a different area).

Now, I noticed you could only specify the area where the seeds are displayed in a square area really, or rectangular, but I was wondering, seeing as the piece of watermelon is a half circle, is there any way to actuially make the seeds randomly generate inside the pink part of the watermelon without hitting the green stuff or going above the limits of the pink watermelon?

Easier put, is there any way to randomly generate black dots within the confines of a half circle rather then a square / rectangle?

Here is my code and such so far for the basic thing (I know the drawing is bad, this was before I knew the co-ords and I was hacking to get locations of things right).

code:

setscreen ("graphics: 560; 400")

var x, x2, y2, y : int

Draw.FillOval (300, 250, 150, 150, 72)
Draw.FillOval (300, 250, 125, 125, 90)
Draw.FillBox (450, 250, 150, 450, 0)

for i : 1 .. 10
    randint (x, 200, 400)
    randint (x2, 10, 12)
    randint (y, 140, 240)
    randint (y2, 2, 4)
    Draw.FillOval (x, y, x2, y2, 255)
end for



watermelon.t
 Description:
My watermelon program :P

Download
 Filename:  watermelon.t
 Filesize:  477 Bytes
 Downloaded:  258 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
gigaman




PostPosted: Mon Nov 01, 2004 8:50 am   Post subject: (No subject)

the only thing i can think of is that you use if statemnts for something like if the randint x is greater than 100 and y is greater than half the watermelon then y minus whatever the hight of the pink is. i no that it's rough but it's the only way i can think of.
Tony




PostPosted: Mon Nov 01, 2004 8:58 am   Post subject: (No subject)

check for the overlap between rectangle confinement and a circle. If the random position matches both cases, it is within that half-circle Wink..

elipses are much trickier, I think a properly placed circle will do just fine in your case
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: