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

#1 2011-12-22 16:37:57

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Reading Squeak Form width depth less than 8

This thread is explaining how to read forms with a depth less than 8 for ZeroLuck.

My JavaScript code is this:

Code:

// Sets color to an array of colors for the pixels. If the form does not contain any colors, use the built in array instead.
var colors = this.colors || squeakColors;

// Some variables I coppied from the Java code. I don't exactly know what they do.
var l = this.bits.length / this.height;
var i1 = (1 << this.depth) - 1;
var j1 = 32 / this.depth;

// Loop throught evevy pixel in the Form.
for(var y = 0; y < this.height; y++)
{
    for(var x = 0; x < this.width; x++)
    {
        var i2 = this.bits[y * l + (x - (x % j1)) / j1];
        var j2 = this.depth * (j1 - x % j1 - 1);
        var ci = i2 >> j2 & i1;        // This is the index of the color for the pixel in the color array.
        
        // Insert your pixel setting method here. aka, setPixel(x, y, colors[ci]);
        
        // This is just constructing an array of pixel values that will be pushed into the HTML5 canvas. You probably won't use it.
        var pi = (y * this.width + x) * 4;
        var c = colors[ci];
        if (c)
        {
            array[pi] = c.r;
            array[pi + 1] = c.g;
            array[pi + 2] = c.b;
            array[pi + 3] = c.a == 0 ? 0 : 255;
        }
    }
}

http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#2 2011-12-22 16:54:02

ZeroLuck
Scratcher
Registered: 2010-02-23
Posts: 500+

Re: Reading Squeak Form width depth less than 8

Thanks!!
This helps me very much!
But some questions:
1. Is the "bits" array  the less than 8 bit encoded bitmap array?
Or have I to split the encoded less than 8 bit bitmap to bits to get the "bits" array?

2.

Code:

var colors = this.colors || squeakColors;

What is the this.colors array? I know the "squeakColors" array, but how do you get the
"colors" array?
Is the colors array in the Form object stored too?

Thanks a lot!

ZeroLuck  big_smile

Last edited by ZeroLuck (2011-12-22 16:56:34)


http://3.bp.blogspot.com/-oL2Atzp0Byw/T465vIQ36dI/AAAAAAAAADo/1vqL4PvhkM0/s1600/scratchdachwiki.png

Offline

 

#3 2011-12-22 16:59:32

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: Reading Squeak Form width depth less than 8

1. The bits array is the decoded bitmap which should be an int array in Java.
2. The color array should be in the Form as the sixth field.


http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#4 2011-12-22 17:02:51

ZeroLuck
Scratcher
Registered: 2010-02-23
Posts: 500+

Re: Reading Squeak Form width depth less than 8

MathWizz wrote:

1. The bits array is the decoded bitmap which should be an int array in Java.
2. The color array should be in the Form as the sixth field.

Okay! Thanks!
I think I will be able to read the images now.
( I will try it tomorrow, because I live in germany and here it is over 5 hours later  big_smile  )


http://3.bp.blogspot.com/-oL2Atzp0Byw/T465vIQ36dI/AAAAAAAAADo/1vqL4PvhkM0/s1600/scratchdachwiki.png

Offline

 

#5 2011-12-22 17:04:16

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: Reading Squeak Form width depth less than 8

No problem.  big_smile


http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#6 2011-12-23 06:29:37

ZeroLuck
Scratcher
Registered: 2010-02-23
Posts: 500+

Re: Reading Squeak Form width depth less than 8

Okay reading the images works!

Another question:
Where can I find the x position and the y position from a Sprite in its array?
Because the name is item 10, the scripts are in item 12, costumes and sounds in 14...
But I can't find the position...

Last edited by ZeroLuck (2011-12-23 08:31:16)


http://3.bp.blogspot.com/-oL2Atzp0Byw/T465vIQ36dI/AAAAAAAAADo/1vqL4PvhkM0/s1600/scratchdachwiki.png

Offline

 

#7 2011-12-23 10:09:14

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: Reading Squeak Form width depth less than 8

It is a rectangle which is item 1.


http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#8 2011-12-23 10:20:01

ZeroLuck
Scratcher
Registered: 2010-02-23
Posts: 500+

Re: Reading Squeak Form width depth less than 8

MathWizz wrote:

It is a rectangle which is item 1.

I don't get it  sad
The sprite array looks like this:

Code:

[
   org.me.scratchplayer.Sprite@1f82ab4,
   124,
   3,
   [
      204,
      138,
      297,
      202,
   ],
   org.me.scratchplayer.Sprite@1bb9696,
   [
   ],
   [...],
]

(the Sprite has the position 70/50 )

And item 1 is "124"...,
item 3 looks like a Rectangle object, but the coordinates are false.

EDIT

item 3 is the Rectangle.
I got the cordinates so:

Code:

 Object[] pos = (Object[]) obj[3];
                    s.setPos(((Number) pos[0]).intValue() + (((Number)pos[2]).intValue() - ((Number)pos[0]).intValue()) /2, 
                            ((Number) pos[1]).intValue() + (((Number)pos[3]).intValue() -  ((Number)pos[1]).intValue()) /2);

Last edited by ZeroLuck (2011-12-27 08:26:56)


http://3.bp.blogspot.com/-oL2Atzp0Byw/T465vIQ36dI/AAAAAAAAADo/1vqL4PvhkM0/s1600/scratchdachwiki.png

Offline

 

Board footer