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

Username:   Password: 
 RegisterRegister   
 whatdotcolour
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Mr. T




PostPosted: Sun Nov 06, 2005 2:34 pm   Post subject: whatdotcolour

In my program, I implemented a flexible array so that the user could keep on making more and more new boxes. However, when I try to use whatdotcolour to see if a newly created box is touching a previously created box, whatdotcolour doesn't pick up anything. Is this a Turing defficiency or am I just doing something incorrectly? Furthermore, aside from whatdotcolour, is there another way (possibly using Math.Distance) to compare the locations of two elements in the same flexible array? If so, sample code would be appreciated.
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Sun Nov 06, 2005 2:53 pm   Post subject: (No subject)

For whatdotcolour to work, there must be something on the screen. It will not work if you have something like this:

loop
cls
whatdotcolour
drawscreen
end loop

instead you should be doing this:

loop
cls
drawscreen
whatdotcolour
end loop

This is a probable cause to your problem, otherwise it would be good to see the code.

Math.Distance is the way to go, just compare the edges of each box in a loop, something like so:

for a : 1 .. upper (box)
for b : 1 .. upper (box)
check box a's borders compared to box b's
end for
end for

Hope this helps, sorry I can't be of more assistance (example code) but I don't have too much time right now.
Mr. T




PostPosted: Sun Nov 06, 2005 3:00 pm   Post subject: Alex's Opinion

The number of boxes is continuously increasing, which means I would need to continually increase the amount of for loops...how's that possible?
[Gandalf]




PostPosted: Sun Nov 06, 2005 3:37 pm   Post subject: (No subject)

What? No. I may be misunderstanding you, but that is what upper (box) is for. Every time you increase the amount of boxes, they will be taken into account the next time that loop structure is executed. I have no idea why you would want to increase the amount of for loops...
Cervantes




PostPosted: Sun Nov 06, 2005 4:28 pm   Post subject: Re: Alex's Opinion

Pwned wrote:
The number of boxes is continuously increasing, which means I would need to continually increase the amount of for loops...how's that possible?

The two for loops are constant. They compare every box against every other box.

And you wouldn't want to use Math.Distance for boxes. Use it for circles, but for boxes just use some condition checking (if x1 >= x2 etc.)
Mr. T




PostPosted: Sun Nov 06, 2005 6:04 pm   Post subject: Alex's Opinion

How would I put an exception into that process whereas the box checks every other box, EXCLUDING itself?
Cervantes




PostPosted: Sun Nov 06, 2005 8:13 pm   Post subject: (No subject)

Using the indeces of the for loops that [Gandalf] set up, you would do this:
code:
if a not= b then
Albrecd




PostPosted: Tue Nov 08, 2005 1:46 pm   Post subject: (No subject)

or you could use:

code:
if X_box >= X_otherbox and X_box <= X_otherbox + /*the width of the other box*/ and Y_box >= Y_otherbox and Y_box <= Y_otherbox + /* the height of the other box*/ then
drawbox = false
else
drawbox = true
Sponsor
Sponsor
Sponsor
sponsor
do_pete




PostPosted: Tue Nov 08, 2005 1:53 pm   Post subject: (No subject)

Quote:
Code:
if X_box >= X_otherbox and X_box <= X_otherbox + /*the width of the other box*/ and Y_box >= Y_otherbox and Y_box <= Y_otherbox + /* the height of the other box*/ then
drawbox = false
else
drawbox = true

You forgot the end if and it should be drawbox:=false instead of drawbox=false
MysticVegeta




PostPosted: Tue Nov 08, 2005 2:05 pm   Post subject: (No subject)

PseudoCode is meant to give an error.
Cervantes




PostPosted: Tue Nov 08, 2005 3:57 pm   Post subject: (No subject)

Regardless, the fact remains that Pwned is dealing with an array of boxes. He needs for loops (or possibly recursion) to compare each box to each other box.
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  [ 11 Posts ]
Jump to:   


Style:  
Search: