PDA

View Full Version : How do you use more than 4 colors with the graphics object



Nerd2
06-01-2010, 12:32 AM
I need to have about 8 colors in the graphics object. For different color boxes and text. This is part of the code I'm using.



COLOR_0 = (COL_Black << 0) 'Background
COLOR_1 = (COL_Blue<< 8) ' Button Background
COLOR_2 = (COL_White << 16) ' Text
COLOR_3 = (COL_red << 24)

repeat i from 0 to 64
colors := COLOR_3 | COLOR_2 | COLOR_1 | COLOR_0

gr.colorwidth(2,0) 'Color,Font Size
gr.text(10,30,string("Tempature Control")) 'Left&Right,Up&Down
gr.text(10,-25,string("Current Temp")) 'Left&Right,Up&Down

potatohead
06-01-2010, 01:11 AM
Are you talking about the Parallax one?

If so, that one works off of tiles. The screen array contains a list of addresses, along with a color palette reference, which points to the sets of colors in the colors array.

The upper bits of the address point to 64 byte aligned HUB memory addresses. By default they are in sequence to make a bitmap display. You can put sets of colors that you want to use in the colors array, then assign them to the tiles, which are 16 pixels wide. Within any tile, composed of 16 pixels horizontally, and 16 or 32 vertically, depending on how you configure that driver, you get 4 colors. If you plan your display carefully, you can get a lot of colors on the screen, so long as no more than 4 of them occupy a given tile.

Just change the lower bits in the screen array longs to point to your palette entries. The colors array is composed of 64 longs, each referenced by the lower bits of the screen array long, which defines where in memory, and what color a given tile image comes from.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness! (http://propeller.wikispaces.com/)
8x8 color 80 Column NTSC Text Object (http://obex.parallax.com/objects/550/)
Safety Tip: Life is as good as YOU think it is!

Nerd2
06-01-2010, 01:24 AM
I am using the Parallax one. I'm sorry but I'm not very familiar with the propeller. I don't know what a screen array is? I did find out that the palette entries are

' each palette entry is a LONG arranged like so: color 3 | color 2 | color 1 | color 0
COLOR_0 = (COL_Black << 0) 'Background
COLOR_1 = (COL_Blue<< 8) ' Button Background
COLOR_2 = (COL_White << 16) ' Text
COLOR_3 = (COL_red << 24)

Post Edited (Nerd2) : 5/31/2010 6:31:11 PM GMT

potatohead
06-01-2010, 02:24 AM
Give me a bit. I think it's time to strip that object down to just the colors and tiles. Probably will make it easier.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness! (http://propeller.wikispaces.com/)
8x8 color 80 Column NTSC Text Object (http://obex.parallax.com/objects/550/)
Safety Tip: Life is as good as YOU think it is!

potatohead
06-01-2010, 07:48 AM
Almost done! I'm commenting the Parallax Reference Graphics object, and adding a few methods for quick 'n dirty color and screen changes.

This question comes up enough that it's more than time to do this. :)

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness! (http://propeller.wikispaces.com/)
8x8 color 80 Column NTSC Text Object (http://obex.parallax.com/objects/550/)
Safety Tip: Life is as good as YOU think it is!

Nerd2
06-01-2010, 07:56 AM
Thanks so much for your help

potatohead
06-01-2010, 08:22 AM
Ok, here it is. Read through this version, and try the supplied additional methods. I think color and tiles will be considerably easier now.

:)

I did this on HYBRID, returning to the default Demoboard settings. You should be able to run this by putting it in the same folder as the other Parallax demo programs, running it instead of graphics_demo.spin

If it doesn't work, double check the settings, and of course, if you've got a different board, you need to update the clock, pins and mode. I've included the HYBRID changes as comments, so it's easy to see where things need to change for different boards.

@Nerd2 -->No probs. It's funny. About half of us caught the Propeller fever, ran this object, then asked WTF?!? on the colors and tiles. No worries. I think this will help some with that question. Chip's driver is pretty great actually. It's just complicated in places to show the cool stuff off, and I think that gets in the way of just using the thing sometimes. It was for me, early on.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness! (http://propeller.wikispaces.com/)
8x8 color 80 Column NTSC Text Object (http://obex.parallax.com/objects/550/)
Wondering how to set tile colors in the graphics_demo.spin? (http://forums.parallax.com/attachment.php?attachmentid=70768)
Safety Tip: Life is as good as YOU think it is!

Post Edited (potatohead) : 6/1/2010 2:30:39 AM GMT

potatohead
06-01-2010, 11:44 AM
Well? Did this hit the mark?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness! (http://propeller.wikispaces.com/)
8x8 color 80 Column NTSC Text Object (http://obex.parallax.com/objects/550/)
Wondering how to set tile colors in the graphics_demo.spin? (http://forums.parallax.com/attachment.php?attachmentid=70768)
Safety Tip: Life is as good as YOU think it is!

Nerd2
06-01-2010, 08:37 PM
I haven't had time yet to sit down and read through it but it looks very helpful.

Nerd2
06-02-2010, 01:45 AM
Is there a way I can use the colorwidth command to point to the palette so I can easily change the color of text and boxes. What I'm making requires boxes to change color back and forth.

potatohead
06-02-2010, 03:04 AM
Not really. Actually maybe. It depends on the shapes and how they align with the tiles.

For all your graphics commands, you get 4 colors, period. They are 00, 01, 10, 11, or 0, 1, 2, 3.

Think of the graphics as being 4 color graphics, always. In fact, it's very helpful to use one of the grey scale palette entries I provided. Draw all of your graphics in the grey scale, being careful to align them with the tiles.

The reason for the tile alignment, is color assignment can only be done on a tile by tile basis. The same color graphics will appear as different colors on the screen, depending on what palette is assigned to the tile in which they appear. The palettes can be changed to flash, or cycle colors too.

Depending on what the graphics look like, it may be possible to just toggle a palette color from one value to the other value, in effect, flashing the box on the screen.

If you post up either your spin work in progress, or some graphical depiction of what the screen is like, getting to the right options will probably be a lot easier.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness! (http://propeller.wikispaces.com/)
8x8 color 80 Column NTSC Text Object (http://obex.parallax.com/objects/550/)
Wondering how to set tile colors in the graphics_demo.spin? (http://forums.parallax.com/attachment.php?attachmentid=70768)
Safety Tip: Life is as good as YOU think it is!

Nerd2
06-02-2010, 03:35 AM
Here is what I'm doing. I'm a volunteer firefighter and I drive a 1998 blazer. My blazer is still in good condition so I don't want to put a bunch of switches in it with ugly labels. I have a light bar with alley lights, and takedowns. I also have 4 lights in my grill that flash back and forth. I also have two lights in the front of the mirrors. I want the propeller to control all of this and display what is on using a lcd monitor. To control the lights I took a keyboard apart and soldered wires where the numpad switches are. For example the number 7 key on the keypad turns everything on. In the picture that I uploaded shows it working with only 4 colors. The takedown lights should be white and the text should be white also the headlights should be yellow. I will need the color blue later. One other problem is I can't get the text to display clear to the edge of the screen there is like a half inch border all around. In the picture the bumper looks white it is really gray.

potatohead
06-02-2010, 08:40 AM
Nice. This is going to be possible. I've some travel and a night in a hotel room this evening. I'll come back to this, as I'm taking my Propeller with me. It's easy to get colors to change, either by drawing, or tweaking the palette entries.

If there is time, I'll write a few lines to show how it's done, and you can rock on from there.

The text has to do with the resolution you've chosen, and the display showing almost all of the NTSC frame. There is a "safe area" border that the Parallax driver honors, because many displays don't render the entire TV picture. I think this can be adjusted.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness! (http://propeller.wikispaces.com/)
8x8 color 80 Column NTSC Text Object (http://obex.parallax.com/objects/550/)
Wondering how to set tile colors in the graphics_demo.spin? (http://forums.parallax.com/attachment.php?attachmentid=70768)
Safety Tip: Life is as good as YOU think it is!