Shop OBEX P1 Docs P2 Docs Learn Events
TV Graphics colors — Parallax Forums

TV Graphics colors

RobertWRobertW Posts: 66
edited 2009-03-13 03:43 in Propeller 1
I am trying to understand how the colors are defined.· I have taken the Graphics_Demo.spin as a starting point and made some modifications.· From reading other post on the Forum,·I can see how the following code fills in the colors array:

· 'init colors
· repeat i from 0 to 63
··· colors[noparse][[/noparse]i] := $00001010 * (i+4) & $F + $2B060C02

With is, when I use: gr.color(0), gr.color(1), ..., gr.color(3) I can generate 4 different colors on the screen.· But when I try anything·greater than·a '3' in the gr.colors(x)·operation, the screen just shows black.· If I am understanding the other posts,·only seeing 4 colors is due to each array location containing 4 colors.· I don't understand how I can access the other·color arrays that were defined at the begining of the program.

I am trying to design a model railroad layout display starting with a simple oval.· The oval is broken into 8 different segments that would show the status of that particular section of track (white = no train, green = clear to proceed red = occupied, etc.).

Any help would be appreciated, thank you.

Comments

  • JomsJoms Posts: 279
    edited 2009-03-05 22:11
    I don't know if I can help with the question about the colors but PLEASE keep us updated on how it goes. I am just starting the same project as you though. At the moment I am working on controlling buttons that have an LCD display in them for the menus, they will go along side the screen.

    The end goal I have is to build a screen like you are talking about that will show a layout of the track and the different sections of the track will change colors depending on where the train is and which way the switches are flipped.

    I am sure there are other people out there with the same idea....
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-03-05 22:39
    ·RobertW,

    See if this breakdown makes a little more sense.· The demo uses the value of·· ' i·'·· to create a color gradient for the purpose of the demo.
    In the example below, I have replaced the gradient with a fixed value for Color 0,1,2, and 3.

        'init colors
        repeat i from 0 to 63
          colors[noparse][[/noparse]i] := $02_9D_BB_2A
    {
                      Color 3
                      ││ Color 2
                      ││ ││ Color 1
                      ││ ││ ││ Color 0
                      ││ ││ ││ ││
        colors[noparse][[/noparse]i] := $02_9D_BB_2A
     
    Examples: (See Palette Demo for other available colors)
      BB RED
      2A Dark BLUE
      02 BLACK
      5B GREEN
      9D YELLOW
      CD PINK        
      FC PURPLE
      BC ORANGE
      04 GREY
      3C Light BLUE
        
    }
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • RobertWRobertW Posts: 66
    edited 2009-03-05 22:51
    Thank you Beau. I saw you post a similar explaination on another thread. My question then is (if I understand it correctly), if I have 64 color arrays (colors[noparse][[/noparse]0], ..., colors[noparse][[/noparse]63]) with colors loaded into them, how do I select a different array, say, colors, etc. In the Graphics_Palatte.spin demo, I see where the array is being filled but I don't understand how each tile is getting the 'next' color in the rows and columns. Am I, pardon the pun, going down the wrong track? Maybe there is an easier way to go about what I am looking for?
  • RaymanRayman Posts: 14,826
    edited 2009-03-06 02:08
    Look at the bottom of this page:

    http://www.rayslogic.com/propeller/Programming/GraphicsDemo.htm

    I think that might answer your question...
  • WNedWNed Posts: 157
    edited 2009-03-06 03:07
    Thanks Rayman!
    I had just started splashing around in the graphics demo yesterday and so needed the information on that page you linked to.
    Edit: Actually, the whole site looks pretty invaluable.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "They may have computers, and other weapons of mass destruction." - Janet Reno

    Post Edited (WNed) : 3/6/2009 3:12:34 AM GMT
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-03-06 07:47
    RobertW,

    With the TV graphics, there are a total of 192 graphics-tiles that form a 12 x 16 tile array.· Each graphics-tile is 16 pixels wide by 16 pixels high.· Since there are only 64 available color-tiles you don't have enough color-tiles to fill up all of the graphics-tiles with a unique color-tile.· The solution is to double up with some of the color-tiles.· So for this example I will assign 4 graphics-tiles to 1 color-tile... we'll call it a "quad-tile".

    Example 1:
         'init tile screen
         repeat graphics_tiles from 0 to 191
           dx := graphics_tiles // x_tiles
           dy := graphics_tiles /  x_tiles
           case graphics_tiles
                0  :  i :=  1  'Assign graphics_tile  0 to color_tile 1
                1  :  i :=  1  'Assign graphics_tile  1 to color_tile 1
                16 :  i :=  1  'Assign graphics_tile 16 to color_tile 1
                17 :  i :=  1  'Assign graphics_tile 17 to color_tile 1
     
                2  :  i :=  2  'Assign graphics_tile  2 to color_tile 2
                3  :  i :=  2  'Assign graphics_tile  3 to color_tile 2
                18 :  i :=  2  'Assign graphics_tile 18 to color_tile 2
                19 :  i :=  2  'Assign graphics_tile 19 to color_tile 2
     
                4  :  i :=  3  'Assign graphics_tile  4 to color_tile 3
                5  :  i :=  3  'Assign graphics_tile  5 to color_tile 3
                20 :  i :=  3  'Assign graphics_tile 20 to color_tile 3
                21 :  i :=  3  'Assign graphics_tile 21 to color_tile 3
                
                other:  i := 0
                
           screen[noparse][[/noparse]dx + dy * tv_hc] := i << 10 + display_base >> 6 + dx * tv_vc + dy
    
    


    ...Ok, in Example1, this just covers the first three "quad-tiles".· To do this for all 48 quad-tiles in this fashion would require a rather large chunk of code, but hopefully you get the idea, and see a pattern.

    Figure 1:
      0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  <--- First graphics-tile line
     16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  <--- Second graphics-tile line
     32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  <--- Third graphics-tile line
    .
    .
    .
    176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191  <--- Last graphics-tile line
    

    Looking at Example 1 at the 'case' pattern and comparing it to Figure 1, you can see that in order to assign the quad-tile to the color-tile 1 you must specify the graphics tiles 0,1,16, and 17 ... likewise for the second quad-tile 2,3,18, and 19 ... and the third quad-tile 4,5,20, and 21.
    I mention earlier that this method would require a large portion of code, it's mainly to understand and see what's going on.· A second method, I have come up with fills all 48 quad-tiles and associates them to the corresponding color-tile.· This method is a little bit harder to follow, but it does use an algorithm to generate the same sequence of patterns you see in Example 1 and uses a relatively small amount of code ... i.e. [noparse][[/noparse]0,1,16, and 17], [noparse][[/noparse]2,3,18, and 19], [noparse][[/noparse]4,5,20, and 21], etc.··

    Example 2:
         'init tile screen
         repeat graphics_tiles from 0 to 191
    ''Silly Bit swapping to get a quad-graphics-tile to increment properly 
           temp1 := (graphics_tiles & |<4)>>4    '<-- Read Bit 4
           temp2 := (graphics_tiles & |<1)>>1    '<-- Read Bit 1
           temp3 := graphics_tiles & %1110_1101  '<-- Mask Out Bits 1 and 4
           temp3 := Temp3 | temp2 << 4 | temp1 << 1 '<-- Swap Bits 1 and 4
           dx := temp3 // 16                     '<-- Calculate dx
           dy := temp3 /  16                     '<-- Calculate dy
    ''Silly math to get the quad-graphics-tile color assignment correct
    ''  (This section is more for Human readability and association to the screen)
           temp1 := (graphics_tiles / 4)+1   '<-- Get initial color assignment
           temp2 :=  graphics_tiles / 32     '<-- Detect boundary
           temp1 := ((temp1 * 2)-1) // 16    '<-- Increment color by ODD numbers
           if temp1 > 7                      '<--   Unless color value is greater than 7
              temp1 -= 7                     '<--   Then increment by EVEN numbers               
           i := temp1 + temp2*8              '<-- Adjust color wrap-around boundary
    ''Finally write the color data to the display database                    
           screen[noparse][[/noparse]dx + dy * tv_hc] := i << 10 + display_base >> 6 + dx * tv_vc + dy
    
    



    I hope that this has helped, and not further confused the matter.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 3/6/2009 8:50:25 PM GMT
  • RobertWRobertW Posts: 66
    edited 2009-03-12 21:40
    I think I better understand how the 64 color tiles can be assigned to the 192 graphics tiles. Let's say I am only looking to use 8 different colors. Is it possible to only define a few color tiles or do I have to define all 64 tiles? Based on Beau's top most explaination, could I have 2 color tiles:

    colors[noparse][[/noparse]0] := $BB_2A_5B_02
    || || || ||
    || || || Color 0 (Black)
    || || Color 1 (Green)
    || Color 2 (Dark Blue)
    Color 3 (Red)

    colors := $9D_CD_FC_BC
    || || || ||
    || || || Color 0 (Orange)
    || || Color 1 (Purple)
    || Color 2 (Pink)
    Color 3 (Yellow)

    If yes, how can I change which color tile is being used? For example, if I have a straight line drawn on the screen, and based on a certain condition I would like the line to be green and based on another condition, the line would need to be yellow, which is defined in a different color tile. How would this be done? I have figured out how to draw a line and pull a particular color out of the color tile but, as best as I inderstand the demo program, I am limited to only the 4 colors defined in the color tile. I know that more colors are possible since the demo draws a few graphics with a range of colors but don't know enough on how to get there.

    Again, any help is appreciated. Thank you.
  • JetfireJetfire Posts: 34
    edited 2009-03-12 22:07
    You may want to try to the graphics driver I made, 8bc. Usage is very similar to graphics, but makes working with colors much easier. You don't have to set up the tiles or be limited to four colors per tile. You just choose the color to draw with, then the draw command.
  • RobertWRobertW Posts: 66
    edited 2009-03-12 22:41
    Jetfire,

    Thanks for the link. I will give your program a try. I would still like to learn how to use the graphics.spin program but in the interest of time. I will be sure to see if I can get your program to do what I am looking for. Thanks again.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-03-13 03:15
    RobertW,
    ·
    "...do I have to define all 64 tiles? Based on Beau's top most explanation, could I have 2 color tiles?" - No, you do not need to define all 64 color-tiles.· If there are only a few colors that you will be using, then you only need to define the color tiles·you will be using up to 64 of them.
    ·
    "If yes, how can I change which color tile is being used?" - You can redefine just that section of graphics tiles where your line is or you can redefine all 192 graphics tiles by running the " 'init tile screen " once again with the adjusted parameters.
    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • RobertWRobertW Posts: 66
    edited 2009-03-13 03:43
    Beau,

    Thank you for the additional information. I will give it a try.
Sign In or Register to comment.