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

#1 2007-06-03 21:52:53

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

off-by-one errors in touching-color

I made a program for testing the alignment of the pen and the touching-color sensor:

http://scratch.mit.edu/projects/kevin_karplus/10057

This indicates that the java implementation is correctly aligned, but the squeak implementation has a rather nasty off-by-one error in both x and y.

(The off-by-one error is why the arrays for the Simon game needed big pens:
http://scratch.mit.edu/projects/kevin_karplus/2158
)

Offline

 

#2 2007-06-04 11:58:25

natalie
Scratch Team
Registered: 2007-03-07
Posts: 100+

Re: off-by-one errors in touching-color

Thanks, Kevin. I'll make sure others here know...

Offline

 

#3 2007-06-04 12:26:42

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: off-by-one errors in touching-color

Ahh...  Perhaps that explains some of the behaviour in my Dancing Angels game.

Every angle checks to see if it is touching the black outline of another angel, and if it is, it hides.  In theory, then, angles would always disappear in pairs, but in practice, sometimes one gets left behind.

If one of them is sensign the wrong "spot", perhaps that's why.

Last edited by Mayhem (2007-06-04 12:32:27)


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#4 2007-06-04 14:38:07

slobasso
Scratcher
Registered: 2007-05-25
Posts: 14

Re: off-by-one errors in touching-color

There's not just a difference in sensing, drawing is somehow off too.

In my Artillery project...
http://scratch.mit.edu/projects/slobasso/8547

I had to move the fort sprites down one pixel because they appeared to be floating above the landscape in the JAVA version.

Offline

 

#5 2007-06-04 16:01:25

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: off-by-one errors in touching-color

I did not test to see whether the error was in drawing or in sensing. Either or both could be off. Icould write a test that distinguishes the two---I'll see if I have time tomorrow.

Offline

 

#6 2007-06-07 02:21:32

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: off-by-one errors in touching-color

I wrote a new test program
http://scratch.mit.edu/projects/kevin_karplus/11090
that determines that the problem is *not* with the touching-color block, but with the pen being offset.

Both the Java and the Squeak implementations have a range of (-240,-179) to (239,180)
which seems like a strange choice, since I would have expected either
   (-240,-180) (240,180)   (for a 481x361 stage)
or (-240,-180) (239, 179) (for a 480x360 stage)

Offline

 

#7 2007-06-07 12:41:38

slobasso
Scratcher
Registered: 2007-05-25
Posts: 14

Re: off-by-one errors in touching-color

I have found one of the problems is related to non-integral sprite positions.

See the following simple project for an example:

http://scratch.mit.edu/projects/slobasso/11248

Offline

 

#8 2007-06-07 12:53:27

slobasso
Scratcher
Registered: 2007-05-25
Posts: 14

Re: off-by-one errors in touching-color

It looks like the squeak version is doing the weird thing here of taking any fractional amount as a reason to move the sprite another pixel. A coordinate of 48 and 48.1 should probably produce the same visual position (this is what Java does). But the squeak version moves it.

Offline

 

#9 2007-06-07 13:04:50

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: off-by-one errors in touching-color

It is (probably) not just rounding errors, as even specifying integer positions causes the pen to be off by (-1,1) from the sprite.

Offline

 

#10 2010-03-24 15:47:07

simplizialkomplex
Scratcher
Registered: 2009-11-02
Posts: 5

Re: off-by-one errors in touching-color

The problem still seems to be around in 1.4 (squeak). Drawing a horizontal line at y=180 does nothing, but at y=179, the line appears at y=178. Which is weird, since I would have expected y=180 to draw a line at y=179....

Offline

 

Board footer