Shop OBEX P1 Docs P2 Docs Learn Events
Using Graphics.spin — Parallax Forums

Using Graphics.spin

James LongJames Long Posts: 1,181
edited 2007-03-05 07:00 in Propeller 1
Ok....I have to admit...I'm a little lost.

First let me explain what I'm trying to do.....then·maybe someone·can·help decide the best way to proceed.

I'm drawing things graphically on a screen. The screen is of equal porportion.(the pixels are of equal size)

I want to draw lines or small pie shaped peices around the inside of a circle. I do not want them to be drawn from the center...but start at a predetermined point from the center.· These will represent a dial type gauge.

I have tried several different methods to draw these...but my efforts have always ended up with a diagonal ellipse shape. I know it is my math....so you don't have to inform me of that.

I would like to use the graphics.spin or possibly a cordic to get the inner and outer starting/stopping point.

Anyone is welcome to help....I have seen some really neat thing with the propeller....but I really suck at graphics....at least so far.

I have looked at the graphics.spin....but I'm a little lost with the variables and instructions. I must be getting old.....it is getting harder to learn things, and I'm not joking. The light is just not coming on.

Thanks,

James L

Comments

  • potatoheadpotatohead Posts: 10,260
    edited 2007-01-03 03:41
    Can you post some code?
  • James LongJames Long Posts: 1,181
    edited 2007-01-03 04:32
    I would.....but everything I have uses a different method of figuring the inner circle points. That is why I ask for the help.

    I would like to use the generic graphics.spin code included with the propeller....but I have no idea how to even start.

    The code has very few notes.



    James L
  • AndreLAndreL Posts: 1,004
    edited 2007-01-03 04:40
    James,·I would say take some time and just read a good graphics book cover to cover. For what you are doing, you have to remember that you have the ideal image you are trying to render and the projected image on the screen device. In the case of the drawing circles and graphs you have to remember that the screen is NOT 1:1, so before rendering you need to multiply by an aspect ratio of the screen 4:5 for TV for example. The trick to graphics is to really KNOW what's going on, and you do that by running experiments and "see" what the results are. The propeller reference drivers tv.spin and graphics.spin are good for this since they allow you to draw lines, circles, etc. But, you have to remember the aspect ratio stuff else your results will look wrong.

    In general say you wanted to plot the points of a circle of radius R, located with center (x0, y0) you can always connect the dots later, and do this much faster, but the general idea is:

    For angle = 0 to 360 step 10

    x = R * cos ( angle )

    y = R * sin ( angle )

    plot ( x + x0, y + y0)

    next angle

    This pseudo code would draw 36 points around the center (x0, y0), but there are about 100 details about this that we need to address.

    1. Where is the center of the screen? Usually 99.99% of the time its (0,0) and located at the TOP-LEFT corner NOT in the center of the screen.

    2. What kind of coordinates are the screen and how does the plot function work? In most cases, the screen is an INTEGER matrix, and either Quadrant I or inverted Y Quadrant I (most common), thus Y increases downward NOT upward like a normal cartesian Quadrant I. And since the screen is integer the plot function usually truncates your coordinates... this is not good, thus before passing them into the function you might want to add (0.5) to round them, which gives better looking graphics OR write your OWN plot function that draws a cluster of pixels based on your desired pixels real center.

    3. What's the aspect ratio of the screen?

    So when you take all these things into consideration, then you will need a y-axis inversion, a translation to the "screen center" if you want the center of the screen to be (0,0) and not the top left corner, plus a x or y axis aspect ratio multiplier, and so forth. Its may seem complicated, but its all a series of steps to transform your desired image in mathematical space to an image in screen space. For example, the parallax drivers allow you to set the origin and to work with a quadrant I system rather than inverted. This is nice for rendering simple graphics, so you don't have to do the extra step yourself.


    Andre'
    ·
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-01-03 04:42
    James,

    I think I understand what you want. Try this code below and see if it is on the right track.

    Basically you provide two radii, using the 'arc' function with modes '0' and '1' you can draw
    from one radius point to the next radius point and step the Degree at what ever you desire.



    [b]CON[/b]
    
      [b]_clkmode[/b] = [b]xtal[/b]1 + [b]pll[/b]16x
      [b]_xinfreq[/b] = 5_000_000
      [b]_stack[/b] = ($3000 + $3000 + 100) >> 2   'accommodate display memory and stack
    
      x_tiles = 16
      y_tiles = 12
    
      paramcount = 14       
      bitmap_base = $2000
      display_base = $5000
    
    [b]VAR[/b]
      [b]long[/b]  tv_status     '0/1/2 = off/visible/invisible           read-only
      [b]long[/b]  tv_enable     '0/? = off/on                            write-only
      [b]long[/b]  tv_pins       '%ppmmm = pins                           write-only
      [b]long[/b]  tv_mode       '%ccinp = chroma,interlace,ntsc/pal,swap write-only
      [b]long[/b]  tv_screen     'pointer to screen (words)               write-only
      [b]long[/b]  tv_colors     'pointer to colors (longs)               write-only               
      [b]long[/b]  tv_hc         'horizontal cells                        write-only
      [b]long[/b]  tv_vc         'vertical cells                          write-only
      [b]long[/b]  tv_hx         'horizontal cell expansion               write-only
      [b]long[/b]  tv_vx         'vertical cell expansion                 write-only
      [b]long[/b]  tv_ho         'horizontal offset                       write-only
      [b]long[/b]  tv_vo         'vertical offset                         write-only
      [b]long[/b]  tv_broadcast  'broadcast frequency (Hz)                write-only
      [b]long[/b]  tv_auralcog   'aural fm cog                            write-only
    
      [b]word[/b]  screen[noparse][[/noparse]x_tiles * y_tiles]
      [b]long[/b]  colors[noparse][[/noparse]64]
    
    [b]OBJ[/b]
    
      tv    : "tv"
      gr    : "graphics"
    
    [b]PUB[/b] start | i,dx,dy,X,Y,R1,R2,Deg
    
      'start tv
      [b]longmove[/b](@tv_status, @tvparams, paramcount)
      tv_screen := @screen
      tv_colors := @colors
      tv.start(@tv_status)
    
      'init colors
      [b]repeat[/b] i [b]from[/b] 0 to 63
        colors[i] := $00001010 * (5+4) & $F + $2B060C02
    
      'init tile screen
      [b]repeat[/b] dx [b]from[/b] 0 to tv_hc - 1
        [b]repeat[/b] dy [b]from[/b] 0 to tv_vc - 1
          screen[noparse][[/noparse]dy * tv_hc + dx] := display_base >> 6 + dy + dx * tv_vc + ((dy & $3F) << 10)
    
      'start and setup graphics
      gr.start
      gr.setup(16, 12, 128, 96, bitmap_base)
    
      [b]repeat[/b]
        'clear bitmap
        gr.clear
    
        gr.colorwidth(1, 1)
    
        R1 := 40                    'Radius #1
        R2 := 60                    'Radius #2
        X := 0                      'X Center
        Y := 0                      'Y Center
            
        [b]repeat[/b] Deg [b]from[/b] 0 to 180 Step 10
          gr.arc(X, Y, R1, R1, DEG2PROP(Deg), 0, 1, 0)
          gr.arc(X, Y, R2, R2, DEG2PROP(Deg), 0, 1, 1)
    
        'copy bitmap to display
        gr.copy(display_base)
    
    
    [b]PUB[/b] DEG2PROP(Deg)               'Convert Deg to 13-bit Propeller angle
        [b]Result[/b] := (Deg * 1024)/45 
           
    
    [b]DAT[/b]
    
    tvparams                [b]long[/b]    0               'status
                            [b]long[/b]    1               'enable
                            [b]long[/b]    %001_0101       'pins
                            [b]long[/b]    %0000           'mode
                            [b]long[/b]    0               'screen
                            [b]long[/b]    0               'colors
                            [b]long[/b]    x_tiles         'hc
                            [b]long[/b]    y_tiles         'vc
                            [b]long[/b]    10              'hx
                            [b]long[/b]    1               'vx
                            [b]long[/b]    0               'ho
                            [b]long[/b]    0               'vo
                            [b]long[/b]    0               'broadcast
                            [b]long[/b]    0               'auralcog
    
    [/i]
    

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

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 1/4/2007 5:17:37 AM GMT
  • AndreLAndreL Posts: 1,004
    edited 2007-01-03 04:43
    And for a lot of graphics examples using SPIN and the reference driver "Game programming for the propeller powered hydra" uses nearly every graphics function in a real example, I do everything from point, lines, circles, particles, screen savers, 3D tunnels, color rotation, and so forth all using the parallax reference drivers.

    There is no "how to" when it comes to graphics, there are a billion ways to do anything, so you have to be VERY specific for what you want, seems you just need to see some examples. So if you can I would suggest the book since it has dozens of them that show these exact things you are stuck on.

    Andre'
  • James LongJames Long Posts: 1,181
    edited 2007-01-03 05:37
    Beau, AndreL

    Thanks....you do have a vast amount of knowledge that helps us unknowing get to where we are going.

    Hey!...I rhymed..

    No really. Beau ..I'll try that...and I think that is what I'm looking for by what I read in the code. This is not for a TV....but I think I can take the code....and decipher from there.

    AndreL

    I want to buy your book, I know it will come in handy. I guess I'll spring for it. Thanks for putting out a good starting point for us graphically challenged.



    James L
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-01-04 05:08
    James,

    Here is an alternative method that will accomplish the same task that does not use the 'arc' command. This would be useful if you wanted raw X/Y values to "send" to something
    other than a TV as you suggest that you are doing.


    [b]CON[/b]
    
      [b]_clkmode[/b] = [b]xtal[/b]1 + [b]pll[/b]16x
      [b]_xinfreq[/b] = 5_000_000
      [b]_stack[/b] = ($3000 + $3000 + 100) >> 2   'accomodate display memory and stack
    
      x_tiles = 16
      y_tiles = 12
    
      paramcount = 14       
      bitmap_base = $2000
      display_base = $5000
    
    [b]VAR[/b]
      [b]long[/b]  tv_status     '0/1/2 = off/visible/invisible           read-only
      [b]long[/b]  tv_enable     '0/? = off/on                            write-only
      [b]long[/b]  tv_pins       '%ppmmm = pins                           write-only
      [b]long[/b]  tv_mode       '%ccinp = chroma,interlace,ntsc/pal,swap write-only
      [b]long[/b]  tv_screen     'pointer to screen (words)               write-only
      [b]long[/b]  tv_colors     'pointer to colors (longs)               write-only               
      [b]long[/b]  tv_hc         'horizontal cells                        write-only
      [b]long[/b]  tv_vc         'vertical cells                          write-only
      [b]long[/b]  tv_hx         'horizontal cell expansion               write-only
      [b]long[/b]  tv_vx         'vertical cell expansion                 write-only
      [b]long[/b]  tv_ho         'horizontal offset                       write-only
      [b]long[/b]  tv_vo         'vertical offset                         write-only
      [b]long[/b]  tv_broadcast  'broadcast frequency (Hz)                write-only
      [b]long[/b]  tv_auralcog   'aural fm cog                            write-only
    
      [b]word[/b]  screen[noparse][[/noparse]x_tiles * y_tiles&#093;
      [b]long[/b]  colors[noparse][[/noparse]64&#093;
    
    [b]OBJ[/b]
    
      tv    : "tv"
      gr    : "graphics"
    
    [b]PUB[/b] start | i,dx,dy,X,Y,x1,y1,x2,y2,R1,R2,Deg
    
      'start tv
      [b]longmove[/b](@tv_status, @tvparams, paramcount)
      tv_screen := @screen
      tv_colors := @colors
      tv.start(@tv_status)
    
      'init colors
      [b]repeat[/b] i [b]from[/b] 0 to 63
        colors[noparse][[/noparse]i&#093; := $00001010 * (5+4) & $F + $2B060C02
    
      'init tile screen
      [b]repeat[/b] dx [b]from[/b] 0 to tv_hc - 1
        [b]repeat[/b] dy [b]from[/b] 0 to tv_vc - 1
          screen[noparse][[/noparse]dy * tv_hc + dx&#093; := display_base >> 6 + dy + dx * tv_vc + ((dy & $3F) << 10)
    
      'start and setup graphics
      gr.start
      gr.setup(16, 12, 128, 96, bitmap_base)
    
      [b]repeat[/b]
        'clear bitmap
        gr.clear
    
        gr.colorwidth(1, 1)
    
    
    
    
    
        R1 := 40                    'Radius #1
        R2 := 60                    'Radius #2
        X := 0                      'X Center
        Y := 0                      'Y Center
    
    'Method #1
    {
        [b]repeat[/b] Deg [b]from[/b] 0 to 180 Step 10
          gr.arc(X, Y, R1, R1, DEG2PROP(Deg), 0, 1, 0)
          gr.arc(X, Y, R2, R2, DEG2PROP(Deg), 0, 1, 1)
    }
    
    
    'Method #2
    
         [b]repeat[/b] Deg [b]from[/b] 0 to 180 Step 10
           x1 := X + (Cos(DEG2PROP(Deg))*R1)/65535
           y1 := Y + (Sin(DEG2PROP(Deg))*R1)/65535 
           x2 := X + (Cos(DEG2PROP(Deg))*R2)/65535
           y2 := Y + (Sin(DEG2PROP(Deg))*R2)/65535
           gr.plot(x1,y1)
           gr.line(x2,y2) 
    
    
    
        'copy bitmap to display
        gr.copy(display_base)
    
    
    
    
    
    
    [b]PUB[/b] DEG2PROP(Deg)               'Convert Deg to 13-bit Propeller angle
        [b]Result[/b] := (Deg * 1024)/45
    
    [b]PUB[/b] Cos(angle)                  'Cos angle is 13-bit ; Returns a 16-bit signed value
        [b]Result[/b] := sin(angle + $800)
    
    [b]PUB[/b] Sin(angle)                  'Sin angle is 13-bit ; Returns a 16-bit signed value
        [b]Result[/b] := angle << 1 & $FFE
        [b]if[/b] angle & $800
           [b]Result[/b] := [b]word[/b][noparse][[/noparse]$F000 - [b]Result[/b]&#093;
        [b]else[/b]
           [b]Result[/b] := [b]word[/b][noparse][[/noparse]$E000 + [b]Result[/b]&#093;
        [b]if[/b] angle & $1000
           -[b]Result[/b]
           
    [b]DAT[/b]
    
    tvparams                [b]long[/b]    0               'status
                            [b]long[/b]    1               'enable
                            [b]long[/b]    %001_0101       'pins
                            [b]long[/b]    %0000           'mode
                            [b]long[/b]    0               'screen
                            [b]long[/b]    0               'colors
                            [b]long[/b]    x_tiles         'hc
                            [b]long[/b]    y_tiles         'vc
                            [b]long[/b]    10              'hx
                            [b]long[/b]    1               'vx
                            [b]long[/b]    0               'ho
                            [b]long[/b]    0               'vo
                            [b]long[/b]    0               'broadcast
                            [b]long[/b]    0               'auralcog
    
    
    

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

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 1/4/2007 5:28:21 AM GMT
  • James LongJames Long Posts: 1,181
    edited 2007-01-04 13:40
    Beau,

    I have a question about the last post.
    x1 := X + (Cos(DEG2PROP(Deg))*R1)/65535
    This forumla has me somewhat confused.

    Where does the 65535 come from?· I mean I know it is a value needed for the calculation......but I'm lost as to it's significance.

    I'm intruiged by it ......

    But thanks ...that is exactly what I was looking for. I have tried to figure out that formula for a week.....and could never get my expected result.

    Edit:There is something else I notice......you use no external math object for any of this.

    Wow....I'm just a real newbie I guess. That is unbelievable. I have much to learn. I feel little......[noparse]:)[/noparse]

    Man...Parallax is great.......they are the bomb.

    James L

    Post Edited (James Long) : 1/4/2007 2:39:17 PM GMT
  • mcstarmcstar Posts: 144
    edited 2007-01-04 15:57
    I wanted to comment about AndreL and his book(s).· I haven't yet gotten the hydra book but, about 4 years ago I read, cover to cover, his Black Art of Windows Game Programming book.· I can tell you unequivically that I have used the CONCEPTS he discussed through code and discussion in that book countless times in my programming profession through the years.· Instead of just telling you·how to·write code or giving you some finished product to run, his books break down the process of understanding·the why and how behind the functions and tools and how they work.···It has served as a baisis of understanding for computer graphics for me over and over again.· Just last week I was talking to a fellow programmer who had run into challenges when attempting to draw some user controls in a windows forms application, and immediatlely·one of the lessons I learned from LaMothe's book came to mind.· I helped him quickly translated the concept from memory·into C# and he was off and running with a fresh approach.· I know Andre's style and his passion seems to be to teach as many people as possible how to make computers sing and dance.· We are fortunate that he visits these forums and is willing to share his knowledge with us.···I haven't bought this book yet, but I've got it on my list of books to buy and cannot wait until I've saved enough sheckels to hit the buy button.· Thanks AndreL for your work and commitment to this field over the years!
    ·
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-01-04 16:41
    James,

    The formula...

    x1 := X + (Cos(DEG2PROP(Deg))*R1)/65535

    ...Is basically what Andre was describing, except he is adding an offset when he·plots the points...

    x = R * cos ( angle )

    ...I have included an offset in the·formula before any points are plotted...

    x1 = x + cos ( angle ) * R

    where:
    "x" is the offset
    "R" is the radius
    "x1" is the computed location of X



    If you look at "DEG2PROP(Deg)", this basically converts a Deg value (0-360) into a 13-bit angle used by the Propeller (0-8191)
    Think of it as multiplying your degree value by 22.7555

    Now look at "Cos(DEG2PROP(Deg))", the Sin and Cos function take a 13-bit angle value and convert it into a 16-Bit signed Sin or Cos value.
    Remember a Sin or Cos value can only range from 1 to -1, with 16-bit resolution the Propeller returns a value from 65535 to -65535.
    This is where the divide by 65535 comes in, but first we want to multiply the Sin or Cos value by the Radius before we divide. Doing so
    gives us the best integer resolution for the final X or Y value.



    "There is something else I notice......you use no external math object for any of this. Wow....I'm just a real newbie I guess. That is unbelievable."

    That is because the Propeller has a pre-calculated (11-bit ) 1/4 Sin table already built-in, all you need to do in this circumstance is to look up the value.

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

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 1/4/2007 4:49:22 PM GMT
  • James LongJames Long Posts: 1,181
    edited 2007-01-04 17:56
    Beau,

    You wouldn't believe how many lines of code that you saved. Also not having to do a sin or cos call to a different object.

    I'm still extremely grateful.

    James L
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-01-04 21:00
    James,

    Glad that helped

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

    IC Layout Engineer
    Parallax, Inc.
  • James LongJames Long Posts: 1,181
    edited 2007-01-04 22:20
    Beau,

    Could I ask.....is the result of the formula a whole number???



    James L
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-01-04 23:10
    It is a signed integer. That is why you want to multiply the radius first before dividing 65535. Doing it the other way would result in a Zero value most of the time.

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

    IC Layout Engineer
    Parallax, Inc.
  • James LongJames Long Posts: 1,181
    edited 2007-01-05 14:37
    Beau,

    What would be the proper way to include the sine table without including the whole graphics object.

    The graphics object would be overkill....now that you instructed me the proper way to do the task.

    Thanks,

    James L
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-01-05 16:14
    James,
    Without the graphics driver, this is all you need to obtain Sine and Cosine from a Degree value...·
    [b]PUB[/b] DEG2PROP(Deg)               'Convert Deg to 13-bit Propeller angle
        [b]Result[/b] := (Deg * 1024)/45
    
    [b]PUB[/b] Cos(angle)                  'Cos angle is 13-bit ; Returns a 16-bit signed value
        [b]Result[/b] := sin(angle + $800)
    
    [b]PUB[/b] Sin(angle)                  'Sin angle is 13-bit ; Returns a 16-bit signed value
        [b]Result[/b] := angle << 1 & $FFE
        [b]if[/b] angle & $800
           [b]Result[/b] := [b]word[/b][noparse][[/noparse]$F000 - [b]Result[/b]]
        [b]else[/b]
           [b]Result[/b] := [b]word[/b][noparse][[/noparse]$E000 + [b]Result[/b]]
        [b]if[/b] angle & $1000
           -[b]Result[/b]
    
    



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

    IC Layout Engineer
    Parallax, Inc.
  • SailerManSailerMan Posts: 337
    edited 2007-01-05 16:20
    Since this thread is called Using Graphics.Spin I thought I'd ask this question.

    What is the Minimum code to use the "TV" and "Graphics" objects. I get a little confused on what is manditory to use the code and what is required to setup and run the objects.

    Can someone help?
    ·
  • James LongJames Long Posts: 1,181
    edited 2007-01-05 16:38
    Beau said...
    Without the graphics driver, this is all you need to obtain Sine and Cosine from a Degree value...·
    Well....I think......the signed integer is causing problems.....

    Well....something is causing problems.

    The LCD display I'm using is a real pain to dispay on....it takes a huge amout of serial communication to display just a line.

    But thanks....I'll keep hammering on...to see if I can find the problem......

    Edit: Could I use the following......:

    ·x1 := || 41 + (Sin(DEG2PROP(deg))* 245)/65535
    ·y1 := || 136 + (Cos(DEG2PROP(deg))* 245)/65535

    This would give me an absolute value....that should be available as x1[noparse][[/noparse]1] and such.

    I have to send everyting in byte form.....

    James L

    Post Edited (James Long) : 1/5/2007 5:29:11 PM GMT
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-01-05 18:39
    SailerMan,

    Much of what I outlined for James, is all that is necessary.....

    [b]CON[/b]
      [b]_clkmode[/b] = [b]xtal[/b]1 + [b]pll[/b]16x
      [b]_xinfreq[/b] = 5_000_000
      [b]_stack[/b] = ($3000 + $3000 + 100) >> 2   'accommodate display memory and stack
    
      x_tiles = 16
      y_tiles = 12
    
      paramcount = 14       
      bitmap_base = $2000
      display_base = $5000
    
    [b]VAR[/b]
      [b]long[/b]  tv_status     '0/1/2 = off/visible/invisible           read-only
      [b]long[/b]  tv_enable     '0/? = off/on                            write-only
      [b]long[/b]  tv_pins       '%ppmmm = pins                           write-only
      [b]long[/b]  tv_mode       '%ccinp = chroma,interlace,ntsc/pal,swap write-only
      [b]long[/b]  tv_screen     'pointer to screen (words)               write-only
      [b]long[/b]  tv_colors     'pointer to colors (longs)               write-only               
      [b]long[/b]  tv_hc         'horizontal cells                        write-only
      [b]long[/b]  tv_vc         'vertical cells                          write-only
      [b]long[/b]  tv_hx         'horizontal cell expansion               write-only
      [b]long[/b]  tv_vx         'vertical cell expansion                 write-only
      [b]long[/b]  tv_ho         'horizontal offset                       write-only
      [b]long[/b]  tv_vo         'vertical offset                         write-only
      [b]long[/b]  tv_broadcast  'broadcast frequency (Hz)                write-only
      [b]long[/b]  tv_auralcog   'aural fm cog                            write-only
    
      [b]word[/b]  screen[noparse][[/noparse]x_tiles * y_tiles]
      [b]long[/b]  colors[noparse][[/noparse]64]
    
    [b]OBJ[/b]
      tv    : "tv"
      gr    : "graphics"
    
    [b]PUB[/b] start | c,dx,dy
      'start tv
      [b]longmove[/b](@tv_status, @tvparams, paramcount)
      tv_screen := @screen
      tv_colors := @colors
      tv.start(@tv_status)
    
      'init colors
      [b]repeat[/b] c [b]from[/b] 0 to 63
        colors[noparse][[/noparse]c] := $2B069C92
    
      'init tile screen
      [b]repeat[/b] dx [b]from[/b] 0 to tv_hc - 1
        [b]repeat[/b] dy [b]from[/b] 0 to tv_vc - 1
          screen[noparse][[/noparse]dy * tv_hc + dx] := display_base >> 6 + dy + dx * tv_vc + ((dy & $3F) << 10)
    
      'start and setup graphics
      gr.start
      gr.setup(16, 12, 128, 96, bitmap_base)
    
      [b]repeat[/b]
        'clear bitmap
        gr.clear
    
    
        {Your Stuff goes here}
    
    
        'copy bitmap to display
        gr.copy(display_base)
    
    [b]DAT[/b]
    tvparams                [b]long[/b]    0               'status
                            [b]long[/b]    1               'enable
                            [b]long[/b]    %001_0101       'pins
                            [b]long[/b]    %0000           'mode
                            [b]long[/b]    0               'screen
                            [b]long[/b]    0               'colors
                            [b]long[/b]    x_tiles         'hc
                            [b]long[/b]    y_tiles         'vc
                            [b]long[/b]    10              'hx
                            [b]long[/b]    1               'vx
                            [b]long[/b]    0               'ho
                            [b]long[/b]    0               'vo
                            [b]long[/b]    0               'broadcast
                            [b]long[/b]    0               'auralcog
    
    
    

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

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 1/5/2007 6:50:45 PM GMT
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-01-05 18:54
    James Long,

    By adding 41, 136, or whatever, you are introducing an offset to either the X or the Y location. If this gets you out of the negative, then that's fine.
    It all depends on what you want to do with your data.

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

    IC Layout Engineer
    Parallax, Inc.
  • SailerManSailerMan Posts: 337
    edited 2007-01-05 19:58
    Beau,

    OK, so that is the basic outline for using graphics.. Thanks for your help.

    Regards,
    Eric
  • James LongJames Long Posts: 1,181
    edited 2007-01-06 00:59
    Beau,

    It was the absolute part I was asking about. The display I'm using doesn't seen to like signed integers. Although I found a major syntax error on my part.

    x1[noparse][[/noparse]0] should have been x1.byte[noparse][[/noparse]0] etc.

    I haven't tested with signed integers since I found the error....I've been taking a break......letting the bleading forehead scab over. Also thinking about a replacement keyboard. [noparse]:)[/noparse]

    James L
  • James LongJames Long Posts: 1,181
    edited 2007-01-06 02:39
    Beau,

    I thought I would give an update.....I have found the secret......but thanks for all the help. There was more to my problem than I first realised.



    Your formula works to the "T"......but I've encountered an interesting side effect.

    Here is my code snipette:

    ·repeat deg from 110 to 70 step 10
    ··· x1 :=·· 41 + (Sin(DEG2PROP(deg))* R1)/65535
    ··· y1 :=· 132 + (Cos(DEG2PROP(deg))* R1)/65535
    ··· serial.tx(Set_xhy)
    ··· serial.tx(x1.byte[noparse][[/noparse]1])
    ··· serial.tx(x1.byte[noparse][[/noparse]0])
    ··· serial.tx(y1.byte[noparse][[/noparse]0])
    ··· serial.tx(print_string)
    ··· serial.str(num.tostr(deg, Num#DEC))
    ··· serial.tx(0)··

    Here is what is wierd....the numbers written in the arc are backwards. I've tried to change the direction....but I can't.....it is quite funny. No matter what I do the 110 is where the 70 is to go.....

    But thanks for the graphics 101 lesson......I promise I'll repay the effort somehow.

    James L
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-01-06 03:09
    James,

    Curious... Where is "Zero" Deg?· Far left or far right?

    For your serial string output, try this to flip the result you are seeing.....

    ··· serial.str(num.tostr(180-deg, Num#DEC))

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

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 1/6/2007 3:28:02 AM GMT
  • James LongJames Long Posts: 1,181
    edited 2007-01-06 04:24
    Yep...that did it.....yeah....you the man.



    Actually it is far left. But....I must say but ...I'm using the screen on it's side. I know...what a wierd thing.



    I'll post a picture. when I get time.



    James L
  • TonyZTonyZ Posts: 13
    edited 2007-03-05 01:46
    Hi,
    I'm building a gps tracking project and with just the bare minimum in graphics.spin, if I throw in a fullserialduplex and some (not much) gps parsing code, I run out of memory. I would like to use a composite video ready lcd but i don't see how.
    any suggestions on how to get even a more bare minimum graphics.spin? reduce color depth?
    thanks.
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-03-05 07:00
    TonyZ,

    Most of the memory requirements are for the graphics bitmap... you could reduce the size somewhat by manually removing any graphics commands that you are not using in your application and likewise to the fullserialduplex object. I'm sure there are other options that I have not investigated that might provide a solution. I think Dennis Ferron recently figured out how to implement raster-based graphics rather than tile-based graphics. Using that method might give you the additional memory you are looking for.

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

    IC Layout Engineer
    Parallax, Inc.
Sign In or Register to comment.