Graphics.pix - how are images defined?
John Kauffman
Posts: 653
I am studying Graphics_demo.spin. The file named potato-commented-graphics-color.spin has been a big help for some questions. But there are still holes in my understanding.
The method Graphics.pix argument 4 is a pointer to DAT.
gr.pixarc(-80,-40,30,30,i<<10+k<<6,0,@pixdef2)
In this case it is for an image of a dog, as defined below
pixdef2 word 'dog
byte 1,4,0,3
word %%20000022
word %%02222222
word %%02222200
word %%02000200
I am unable to get even a start on understanding this, other than the crude observation that the pattern of 0 and 2 in the matrix sort of looks like the resulting dog. Can anyone point me to or provide a walk-through of what is happening?
Thanks.
The method Graphics.pix argument 4 is a pointer to DAT.
gr.pixarc(-80,-40,30,30,i<<10+k<<6,0,@pixdef2)
In this case it is for an image of a dog, as defined below
pixdef2 word 'dog
byte 1,4,0,3
word %%20000022
word %%02222222
word %%02222200
word %%02000200
I am unable to get even a start on understanding this, other than the crude observation that the pattern of 0 and 2 in the matrix sort of looks like the resulting dog. Can anyone point me to or provide a walk-through of what is happening?
Thanks.
Comments
What is going on in the example you posted, is a bitmap image definition. The "word &&" means two bits per character. Binary is one bit "%", so classic Chip style easily expands that another bit, "%%". Nice!
That's handy in the dat section you reference, because then each pixel is either encoded as "0, 1, 2, 3", with each character referring to the color index associated with that pixel. That's your dog defined as pixels right there.
In the comment above, the byte "x words, y words, x origin, y origin" are simply values used by graphics.spin to properly display the pixdef to the screen. One can make big images, or little ones, just by calling out how many words (16 bit) chunks there are in each direction.
Finally, the origin details how the image will be drawn, when invoked by the pix command, associated with pixdef.
This is a nice way to define a bitmap image, that is 4 color, and be able to just draw it anywhere on the graphics screen.
The dog is one word wide, so that's the "1", 4 words deep, "4", and it's origin is "0" in the X axis (horizontal), "3" in the Y axis, vertical.
My guess is the origin is upper left, unless one specifies otherwise. If it were me, I would define a small box, then draw it at known screen coordinates, and see just where the origin is --or trace through the code. Probably easier to just draw one, but that's me.