Computer Science Canada whatdotcolour |
Author: | Mr. T [ 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. |
Author: | [Gandalf] [ Sun Nov 06, 2005 2:53 pm ] |
Post 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. |
Author: | Mr. T [ 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? |
Author: | [Gandalf] [ Sun Nov 06, 2005 3:37 pm ] |
Post 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... |
Author: | Cervantes [ 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.) |
Author: | Mr. T [ 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? |
Author: | Cervantes [ Sun Nov 06, 2005 8:13 pm ] | ||
Post subject: | |||
Using the indeces of the for loops that [Gandalf] set up, you would do this:
|
Author: | Albrecd [ Tue Nov 08, 2005 1:46 pm ] | ||
Post subject: | |||
or you could use:
|
Author: | do_pete [ Tue Nov 08, 2005 1:53 pm ] |
Post 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 |
Author: | MysticVegeta [ Tue Nov 08, 2005 2:05 pm ] |
Post subject: | |
PseudoCode is meant to give an error. |
Author: | Cervantes [ Tue Nov 08, 2005 3:57 pm ] |
Post 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. |