A few Subs to make Color Graphics a bit easier
Here's a few subs I added to my Top Spin file to make working with the Color Palettes a bit easier
Here's an example of how they are called...
Hope this helps make the colors a bit easier to understand. I know it took me a day just to figure how the examples worked. All the information is there. You just have to look at the examples and the objects to find the details.
Basically, you can have 64 different palettes, and 192 tiles. Any Tile can point to any one of the Palettes you have defined. Each Palette defines 4 colors. So you could have a screen with up to 256 different colors. These functions make it a bit easier to understand and read/change you code.
Here is another little sub I wrote to place a Grid over your display to help define the tiles
·I normally have the line just before I do Gr.Copy call it if I have a button pressed, so I can bring it over the current version of what I have on the screen
All I can say is this Propeller is one awsome chip. I'll have a pretty cool sample video in the new few weeks that will show pretty good use of the Propeller's power and ease of use. I attached a screen sample.· ;-)
Jim
Pub SetAreaColor(X1,Y1,X2,Y2,ColorIndex)|DX,DY Repeat DX from X1 to X2 Repeat DY from Y1 to Y2 SetTileColor(DX,DY,ColorIndex) Pub SetTileColor( x, y, ColorIndex) screen[noparse][[/noparse]y * tv_hc + x] := display_base >> 6 + y + x * tv_vc + ((ColorIndex & $3F) << 10) Pub SetColorPalette(ColorIndex,Color1,Color2,Color3,Color4) colors[noparse][[/noparse]ColorIndex] := (Color1) + (Color2 << 8) + (Color3 << 16) + (Color4 << 24)
Here's an example of how they are called...
CON ' Colors CL_Black = $02 CL_Grey1 = $03 CL_Grey2 = $04 CL_Grey3 = $05 CL_Grey4 = $06 CL_White = $07 CL_Blue = $0A CL_DarkBlue = $3A CL_DarkGreen = $4A CL_Red = $48 CL_Brown = $28 CL_Yellow = $9E CL_Purple = $88 CL_DarkPurple = $EA ' Use Graphics_Palette to find more colors PUB Start.... SetColorPalette(0,CL_Black,CL_White,CL_Red,CL_Blue) SetColorPalette(1,CL_Black,$F8,CL_Red,CL_Blue) SetColorPalette(2,CL_Yellow,$F8,CL_Red,CL_Blue) SetColorPalette(3,CL_Black,CL_White,$48,$AA) ' Valentine One ' Can have up to 64 Color Palettes 'init tile screen SetAreaColor(0,0,TV_HC-1,TV_VC-1,0) ' Defaults all Screen to Color Palette #0 SetAreaColor(0, 0, 1,1,1) ' C0R0..C1..R1 to Palette #1 SetAreaColor(6,1,13,5,2) ' Sets Tiles C6R1..C15R5 to Palette #2 SetAreaColor(14,0,15,1,1) ' C14R0..C15R1 to Palette #1 SetAreaColor(6,6,11,8,3) ' C6R6..C11R8 to Palette #3
Hope this helps make the colors a bit easier to understand. I know it took me a day just to figure how the examples worked. All the information is there. You just have to look at the examples and the objects to find the details.
Basically, you can have 64 different palettes, and 192 tiles. Any Tile can point to any one of the Palettes you have defined. Each Palette defines 4 colors. So you could have a screen with up to 256 different colors. These functions make it a bit easier to understand and read/change you code.
Here is another little sub I wrote to place a Grid over your display to help define the tiles
Pub ShowTiles| x, y ' This Sub Will Draw a Grid Outlining each Tile gr.color(1) Repeat X From 0 to X_tiles-1 gr.Plot(X * 16,0) gr.line(X * 16,y_Tiles * 16) Repeat Y From 0 to y_Tiles-1 gr.Plot(0,Y*16) gr.line(X_Tiles * 16,Y * 16)
·I normally have the line just before I do Gr.Copy call it if I have a button pressed, so I can bring it over the current version of what I have on the screen
Main code....
if INA[noparse][[/noparse]1]==1 ShowTiles gr.copy(display_base) 'copy bitmap to display
All I can say is this Propeller is one awsome chip. I'll have a pretty cool sample video in the new few weeks that will show pretty good use of the Propeller's power and ease of use. I attached a screen sample.· ;-)
Jim
Comments
·This was the thing that was missing from thr Graphics unit!
· Excellent work! Thanks.
Attila
To save memory, just reserve the number of Palettes you are going to use. In my application I lowered it to 5 and saved ~58 Longs. I'm at the point that almost every long counts...· :-)
Jim
would you post the whole Spin-program with the grid !
Thanks
Bernd