This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-06-08 01:18:18

LEGOengineer261
Scratcher
Registered: 2011-11-16
Posts: 100+

Graph help. ASAP!!!

Hey, I made a graph (thats all I think I can call it, but its not really a graph) and I want it so in a short script it will be able to tell if the mouse is in one of these squares. Here's the pic. I would try to figure this out myself, but it could take a long time.  tongue  I figured someone else could do it alot faster, like some math-whiz.  smile
http://i1156.photobucket.com/albums/p56 … tGraph.gif
I I don't want it to check one at a time if it is in a box, I would rather have a shorter and faster script to check it, and the way it is spaced there should be a way to do that.
NOTE: The boxes are all 60x by 75x (x,y) and for x the border and middle empty spaces are 20 pixels, the others are 15 pixels in x, and for y the top and bottom (y border) empty spaces are 15 pixels, and the spaces in between are 10 pixels. I hope you know what I'm talking about, tell me if you do not understand something.  smile


http://i1156.photobucket.com/albums/p562/LEGOengineer261/IronmanSERIOUSBOSS.jpg

Offline

 

#2 2012-06-08 02:04:07

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Graph help. ASAP!!!

OK, you need two variables: rx and ry for rounded x and rounded y.

You might have to play around with this for a bit but hopefully this'll work:
rx = round(mousex+40/75)*75-40
ry = round(mousey+43/83)*83-43
That should at least give a close center for each rectangle.  Then to test if the mouse is actually in the rectangle:
abs(mousex-rx) < 30
abs(mousey-ry) < 37

EDIT:
This worked for the any mouse value less than 0, if the value is greater than zero, use 35 instead 40.

Last edited by AtomicBawm3 (2012-06-08 02:10:44)


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#3 2012-06-29 12:00:05

LEGOengineer261
Scratcher
Registered: 2011-11-16
Posts: 100+

Re: Graph help. ASAP!!!

AtomicBawm3 wrote:

OK, you need two variables: rx and ry for rounded x and rounded y.

You might have to play around with this for a bit but hopefully this'll work:
rx = round(mousex+40/75)*75-40
ry = round(mousey+43/83)*83-43
That should at least give a close center for each rectangle.  Then to test if the mouse is actually in the rectangle:
abs(mousex-rx) < 30
abs(mousey-ry) < 37

EDIT:
This worked for the any mouse value less than 0, if the value is greater than zero, use 35 instead 40.

Thanks! I'll try this as soon as I can...


http://i1156.photobucket.com/albums/p562/LEGOengineer261/IronmanSERIOUSBOSS.jpg

Offline

 

Board footer