Shop OBEX P1 Docs P2 Docs Learn Events
Trying to understand using colors! — Parallax Forums

Trying to understand using colors!

HarleyHarley Posts: 997
edited 2010-08-30 15:13 in Propeller 1
Anyone have a clear explanation for this?

I've been using colors blindly it appears, but was looking at the Hydra volume and trying to relate the 'vgacolors' table (below) from PTP Paint demo with what's described on pg 239, 240 in Fig 14:4 and Table 14:2.

I don't get much of an agreement between the two. Are these referring to the same color codes?
DAT      
vgacolors               long
                        long    $F00CF00C       'blue background with yellow letters
                        long    $F0F00C0C
                        long    $08A808A8       'green
                        long    $0808A8A8
                        long    $50005000       'blue
                        long    $50500000
                        long    $FC00FC00       'white
                        long    $FCFC0000
                        long    $FF80FF80       'red/white
                        long    $FFFF8080
                        long    $FF20FF20       'green/white
                        long    $FFFF2020
                        long    $FF28FF28       'cyan/white
                        long    $FFFF2828
                        long    $00A800A8       'grey/black
                        long    $0000A8A8
                        long    $FFC03000       '16'Colors for Graphics  
spcl                    long    $F0FF9C0C       '17 'Color0  white
                        long    $F0C09C0C       '18 Color1  red
                        long    $F030000C       '19 Color2  green
                        long    $F000000C       '20 Color3  black
                        long    $FF0C9C0C       '21 fill screen
                        long    $000C9C0C       '22 clear screen
                        long    $FF0C9C0C       '23 line mode
                        long    $FF0C9C0C       '24 dots mode    
                        long    0                                 

And, with the 16 colors, is it just any 4 of the 16 that are allowed at any one time? Or is there a way to display all 16 colors on a screen?

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-08-22 01:24
    Harley, I can't answer about the Hydra book but I finally figured out "vgacolors." (At least enough to use them.)
    Here's what I understand. (Sorry if you already have figured this out, hopefully it will save someone some time.)
    Each set of colors for text color and background color are defined by to longs in the DAT section. The pattern of text color bytes and background color bytes is:

    long text, background, text, background
    long text, text, background, background
    CON
     
      #0, _LightBlue, _Blue, _White, _Red, _Green, _Yellow, _Purple, _Cyan, {
    }      _FRed,  _FGreen, _Orange, _Black  
     
    DAT
     
      colorPalette       byte $3C, $04, $FF, $80, $20, $F0, $CC, $28, $40, $10, $E0, $00 
     
     
    
    I use the following method to generate the pattern at runtime. This way I can use more than sixteen color combinations. I'm still limited to sixteen combinations per screen but when I change screens after a menu choice I can create a new set of colors to choose from. One reason I like this ability, is I can easily invert the colors of the text and the background to indicate cursor position. (The prefix "F" as in _FRed stands for faint (unsaturated).)

    Here's the method I use to built the patterns. I leave color 0 (light blue on dark blue) alone, so I never change more than 15 colors on a page (screen).
    PUB SetColor(text, background)
      if text == oldColorText and background == oldColorBackground
        print($111 + colorIndex - 1)                        ' use last color
      else
        gobalColor :=  byte[@colorPalette + text]
        gobalColor <<=  8
        gobalColor +=  byte[@colorPalette + background]
        gobalColor <<=  8
        gobalColor +=  byte[@colorPalette + text]
        gobalColor <<=  8
        gobalColor +=  byte[@colorPalette + background]
     
        longmove(@menuColors + (colorIndex * 8), @gobalColor, 1)
     
        gobalColor :=  byte[@colorPalette + text]
        gobalColor <<=  8
        gobalColor +=  byte[@colorPalette + text]
        gobalColor <<=  8
        gobalColor +=  byte[@colorPalette + background]
        gobalColor <<=  8
        gobalColor +=  byte[@colorPalette + background]
     
        longmove(@menuColors + (colorIndex * 8) + 4, @gobalColor, 1)
        print($111 + colorIndex++)
        colorIndex <#= $0E
        oldColorText := text
        oldColorBackground := background
     
    DAT
     
      vgacolors         long    $3C043C04       'lt blue on dark blue
                            long    $3C3C0404
     
      ' Colors below here can be changed by SetColor method.
      ' (I'm not sure if my color names are all correct.)
      ' It's not necessary to have colors listed here, just make sure there is space
      ' for SetColor to write information here.
     
      menuColors     long    $50005000       ' blue on black
                            long    $50500000
                            long    $FC00FC00       'whitish on black
                            long    $FCFC0000
                            long    $FF80FF80       'red/white
                            long    $FFFF8080
                            long    $FF20FF20       'green/white
                            long    $FFFF2020
                            long    $FF28FF28       'cyan/white
                            long    $FFFF2828
                            long    $00A800A8       'grey/black
                            long    $0000A8A8
                            long    $eC00eC00       'light purple
                            long    $eCeC0000
                            long    $cC00cC00       'purple
                            long    $cCcC0000
                            long    $FFe0FFe0       ' orange/white
                            long    $FFFFe0e0 
                            long    $e0cce0cc       ' purple/orange
                            long    $e0e0cccc
                            long    $FF20FF20       'white on green
                            long    $FFFF2020
                            long    $20FF20FF       'green on white
                            long    $2020FFFF
                            long    $30003000       'green on black
                            long    $30300000
                            long    $00300030       ' black on green
                            long    $00003030 
                            long    $0C000C00       'blue {$11E}
                            long    $0C0C0000 
     
    
    The method just takes the parameters of text color and background color and overwites the patterns in the DAT section. I make sure I print all text of one color combination together so I don't use up the sixteen possible color combinations with repeats. (Hence the oldColor variables.)

    You can display sixteen colors on the screen. I think PTP_Paint uses some of the colors to display buttons. Notice the colors at "spcl" don't follow the normal pattern illustrated above. You can change these to color patterns of your choosing. (I think changing them will mess up the "buttons" in PTP_Paint.)

    Sorry I can't help with the Hydra stuff. I'm going to buy that book one of these days (last time I placed an order with Parallax it was sold out).

    There is some reson for the values of each color. As the comments in the VGA object explain there is a binary code discribing the red, green and blue values.

    Duane
  • HarleyHarley Posts: 997
    edited 2010-08-22 09:43
    Duane, Thank you for your explanation on colors. That rather pieced it together better than I'd read before. Now to try to use your code in my program and try to display the 'many' colors. Too bad the Prop I is so limited in RAM! (Prop II is coming when???)

    Re: the Hydra book, it is filled with info; unfortunately the binding isn't very durable and it is a thick book too, making that worse. One has to use iit carefully. LIFE!!

    I didn't understand why those two longs

    long text, background, text, background
    long text, text, background, background

    are necessary. I'll have to ponder that for a while. Many thanks for your time.
  • RaymanRayman Posts: 14,889
    edited 2010-08-22 10:11
  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-08-22 12:18
    Rayman, I should have spent more time looking through your site. I just learned a lot. Like
    why those two longs
    The only reason I had was "because that's the way it will work." I'll need to spend some more time to understand what you present. Right now I usually want to know enough to get the Propeller to do what I want. I don't need to understand why it does what it does at this point in my life.

    Harley, make sure you check out the link Rayman gave. It explains a lot.

    Thanks for the tip about the Hydra book. I'll be hesitant to loan it out once I buy one. I'm often "pushing" my other Propeller books on to others. I just think Props are so fun and useful, I can't understand when others aren't as anxious to learn about the wonders of the Propeller chip as I am.

    Duane
  • HarleyHarley Posts: 997
    edited 2010-08-22 14:32
    @ Rayman, Seems I seen your site http://www.rayslogic.com/propeller/P...ing/Colors.htm long time back, but then it wasn't a very high priority for the tasks at hand then. And forgotten until now. Something to dig into and understand now. Thanks for the reference.
  • ericballericball Posts: 774
    edited 2010-08-23 11:02
    I haven't seen the code or document you are referring to, but on the Propeller the WAITVID instruction feeds the video generator two longs: four "color" bytes in the destination register and 16 or 32 color indexes (pixels) in the source register. The pixels select one of the color bytes and the video generator drives the 8 output pins (as controlled by VCFG and DIRA).

    Note: the ROM character bitmaps have two characters per word. So to select the even character you give the colors as FBFB (F=foreground color, B=background color), but for the odd character you give the colors as FFBB.
  • HarleyHarley Posts: 997
    edited 2010-08-23 19:20
    @ Duane

    I reviewed your 16 color code and note there are only 12 colors in the CON and DAT, but the vgacolors and menucolors total 16.
    CON
     
      #0, _LightBlue, _Blue, _White, _Red, _Green, _Yellow, _Purple, _Cyan, {
    }      _FRed,  _FGreen, _Orange, _Black  
     
    DAT
     
      colorPalette       byte $3C, $04, $FF, $80, $20, $F0, $CC, $28, $40, $10, $E0, $00
    

    Was there anything missing from them?

    I used all of your suggested code in a highly modified PTP Paint demo source. Right now I just put constants in a SetColor(text,background) call. Painful way to view all 16 colors, one at a time, but works.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-08-23 22:27
    Harley,

    I only listed 12 colors because that's all I'm using right now. I think there are 64 possible colors. I know I can use 16 different colors on one screen if I limit myself to text. I think there are different rules about colors with graphics. I took out all the graphics stuff from PTP_Paint.

    I'm not so sure I had 16 different colors on the screen at once. I had 16 different text and background combinations. I'll have to experiment some more and read Rayman's page about color.

    Colors can range from %00000000 ($00) to %11111100 ($FC). The first non black color is %00000100 ($04) (it still looks black to me). The last two bits are ignored (according to Rayman), the first two bits are the red value, the third and fourth bits are the green value and the fifth and sixth bits are the blue values (I learned this from one of the VGA objects, Rayman also has this information). So %00110000 ($30) is all green without any red or blue. So now you can add what ever colors (of the 64) you want to your pallette.

    Ah ha:idea:, that's why $FC and $FF look the same. The last two bits are ignored. Thanks Rayman. I understand a little more.

    I hope my ramblings aren't making things worse for you Harley. I'm very willing to answer questions, I'm just not sure I'm the one to ask. I am anxious to share what little I have learned.

    Propeller are a lot of fun. Thanks Chip.

    Duane
  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-08-23 22:38
    Duh (slaps self on head), to get all possible colors just keep adding 4.

    $00, $04, $08, $0C, $10, $14, $18, $1C, $20, $24, $28, $2C, $30, $34, $38, $3C, $40, $44, $48, $4C, $50, $54, $58, $5C, $60, $64, $68, $6C, $70, $74, $78, $7C, $80, $84, $88, $8C, $90, $94, $98, $9C, $A0, $A4, $A8, $AC, $B0, $B4, $B8, $BC, $C0, $C4, $C8, $CC, $D0, $D4, $D8, $DC, $E0, $E4, $E8, $EC, $F0, $F4, $F8, $FC

    Tah dah. All VGA colors. I should have already known that.
  • HarleyHarley Posts: 997
    edited 2010-08-24 09:26
    Thank you Duane,

    OK, I think I'm getting to understand a bit more about using colors. Before I just used whatever colors the source I was using w/modifications left it; because I just didn't understand what was going on. And, for instance, from the Hydra book, I didn't want to read ALL of that tome just to understand what I needed for my little 'slice' of the world. Though, maybe on the other hand, If I'd at least browsed every page I may have caught something of use (if by then it could all be recalled and pieced together to make sense).

    I'm working on displaying as many colors as I can. Will try to get a decent pic of that when done. But, don't hold your breath; the schedule this week is filled with appointments.
  • HarleyHarley Posts: 997
    edited 2010-08-24 18:02
    @Duane,

    I tried to create 16 color boxes. Yes, I get vertical rectangles on the LCD OK, but only two or 4 colors, depending on what I select in and out [gr.color(i) or SetColor(0, i)]. I had four colors at one time. Now only 2 colors.

    I must not be using your SetColor PUB properly.

    And, that CON set of colors, shouldn't it have some label to reference it sometime? Boy, am I ever 'lost in the woods' of color; and don't even have a compass or paddle!
    PUB colorBars16 | i
      gr.color(3)
      col := 3
      row := 0
      PrintStr(string("16-Colors mode"))
      repeat i from 0 to 15
        gr.color(i)
    '    SetColor(0, i)
        gr.box(-128 + i*16,-96,16,180)
        ms(700)
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-08-24 20:50
    Harley,

    Sorry, I haven't experimented with the colors using the graphics object. Plain text is enough for my needs right now. From my limited understanding of the material on Rayman's page, you're much more limited in the number of colors available per tile in graphics mode.

    I have a Hydra book on the way so ask me again in a year and hopefully I should be able to help.

    The color constants do have a label of sorts.
    CON
    #0, _LightBlue, _Blue, _White, _Red {snip}
    
    is the same as
    CON
    _LightBlue = 0
    _Blue = 1
    _White = 2
    _Red = 3
    
    So,
    SetColor(_Red, _White) 
    

    is the same as
    SetColor(3, 1)
    
    which calls the method
    PUB SetColor(text, background) {text is now set to 3 and background to 1}
     
      gobalColor := byte[@colorPalette + text] 
      ' takes the byte from the memory location 3 bytes after the first byte of the string named colorPalette.
      ' The third byte after the first is $80 (also known as the forth byte of the string, but we like to
      'number of memory locations starting with zero for cases such as this.)
     
    DAT
     
      colorPalette       byte $3C, $04, $FF, $80, $20
    
    I've call these variables strings but I'm not sure if that the right term.

    Do you know what the code
    gobalColor <<= 8
    gobalColor += byte[@colorPalete + background]
    
    does? My guess is you do, but if you'd like clarification, let me know.

    Sorry if I over simplified, or didn't clarify enough. Let me know if I should go into more detail with the memory location stuff. I'm afraid I'm not much help with using colors with graphics yet.

    Duane
  • HarleyHarley Posts: 997
    edited 2010-08-29 14:40
    OK, I think I've a bit better understanding re: colors. What I saw in the Hydra book threw me off what it was really saying. I saw "16 colors" and thought I could make 16 graphic boxes in 16 colors. That just didn't work.

    After reading and re-reading LaMothe's text over and over, it finally dawned on me there could only be 4 colors at any one time, though there was a pallete of 16 colors to choose any four from. 32 bit LONG holds 4 bytes for the 4 colors. That's it, dummy, 4 colors at any one time.

    So decided to not try graphics any more, just do text with background. Here's the result. An index from 0..15 is used for background and index-15 for text. Weird thing is when index goes from 6 to 7 the background on the LCD changes from original black to this light blue. I've yet to figure that one out. (I did note in Graphics object they mask color with 03 so only 4 colors could be used; changing that mask to 0F didn't work.)

    Now to play with the text/background color codes to improve the colors, if possible.
    640 x 480 - 39K
  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-08-30 07:27
    Harley,

    I'm working on a menu program for Rayman's PTP. I've almost got a demo finished. I've redone the SetColor method so you don't have to feed it like colored items together. It keeps track of earlier color sets so it doesn't repeat a text and background pair. I hope to have something to post today. I don't have any work to do today on my day job so I can spend most of the day working on this. This is text only I haven't tried using graphics yet.

    I'll probably head over to Kinko's (it's not called that any more) and have my Hydra book rebound. Your right about the bad binding. My wife and I could both hear the binding snap crackle and pop as I tried to carefully read it. I really like the content of the book.

    Duane
  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-08-30 15:13
    Here's my attempt at creating a menu system of Rayman's PTP. My PTP is connected with a second Propeller. I commented out the code using the second Propeller.

    I've been trying to come up with an easy way to create menus. This what I've come up with so far. The Color Menus have several levels. The LED Array menu doesn't have an exit (you'll have to reset the Prop).

    I am pleased with the way most of the menu information is contained in the DAT section. I also like the way it automatically keeps track of where the buttons are on each menu. There are still a couple things I'd like to smooth out. Like, how can I include what method I want a button to lead to in the DAT section?

    I like the way I can access lists of memory locations without the @@ operator.

    Let me know what you think.

    Harley, As I mentioned earlier, I've redone the SetColors method. It's more user friendly now.

    Check out the colors. There are lots of repeated colors but all 64 colors should be there somewhere.

    Most menus can be exited by pressing the top right corner. The blues menu leaves a really small area of the corner.

    It was nice to have a day to work on this.

    Duane

    PTP_TextMenu05b - Archive [Date 2010.08.30 Time 15.50].zip
Sign In or Register to comment.