Shop OBEX P1 Docs P2 Docs Learn Events
TV_Terminal_Demo; How can I use graphics.spin? — Parallax Forums

TV_Terminal_Demo; How can I use graphics.spin?

FritzFritz Posts: 2
edited 2007-03-20 14:13 in Propeller 1
Hi,
I have just started dealing with the spin language.

I want to·make some simple modifications·of the·tv_terminal_demo, so that I can draw a line (or something else) using the·graphics.spin object.·Therefore I·added·some test-code to the tv_terminal.spin object like:

PUB test(x_value, y_value)
····· gr.color(2)··········································· ' color changes -> OK
····· gr.width(3)·········································· ' width changes -> OK
····· gr.plot(x_value,y_value)·························' no output on the display??????
····· gr.line(x_value+30,y_value+30)··············' no output????
····· gr.text(120,120,string("Hello"))··············· ' no output????
····· dec(x_value)·········································' -> OK

Using this code I can change for example the color, but I can't use gr.plot(), gr.line() and·gr.text() the way I want to.

So, where is my mistake? How can I use all methods of the graphics.spin object in the tv_terminal_demo?

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-03-20 12:29
    You don't say what the rest of your code looks like, but quite a bit is required to get it running.· Here's a 'simple' example with code similar to yours.· Parts are adopted from another member's suggestions and code to set the tile colors, sorry, can't remember who.· See attached file.






    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    StampPlot - GUI and Plotting, and XBee Wireless Adapters
    Southern Illinois University Carbondale, Electronic Systems Technologies

    Post Edited (Martin Hebel) : 3/20/2007 12:33:48 PM GMT
  • potatoheadpotatohead Posts: 10,260
    edited 2007-03-20 13:40
    Make yourself a template program, by removing the graphics from the demo program. Then add your graphics commands in to see the result.

    Here is an example one, with the mouse left working, and some of the original variables left defined:

    
    ''*****************************
    ''*  Graphics Demo            *
    ''*  (C) 2005 Parallax, Inc.  *
    ''*****************************
    
    
    CON
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
      _stack = ($3000 + $3000 + 100) >> 2   'accomodate display memory and stack
    
      x_tiles = 16
      y_tiles = 12
    
      paramcount = 14       
      bitmap_base = $2000
      display_base = $5000
      
    
    VAR
    
      long  mousex, mousey
    
      long  tv_status     '0/1/2 = off/visible/invisible           read-only
      long  tv_enable     '0/? = off/on                            write-only
      long  tv_pins       '%ppmmm = pins                           write-only
      long  tv_mode       '%ccinp = chroma,interlace,ntsc/pal,swap write-only
      long  tv_screen     'pointer to screen (words)               write-only
      long  tv_colors     'pointer to colors (longs)               write-only               
      long  tv_hc         'horizontal cells                        write-only
      long  tv_vc         'vertical cells                          write-only
      long  tv_hx         'horizontal cell expansion               write-only
      long  tv_vx         'vertical cell expansion                 write-only
      long  tv_ho         'horizontal offset                       write-only
      long  tv_vo         'vertical offset                         write-only
      long  tv_broadcast  'broadcast frequency (Hz)                write-only
      long  tv_auralcog   'aural fm cog                            write-only
    
      word  screen[noparse][[/noparse]x_tiles * y_tiles]
      long  colors[noparse][[/noparse]64]
    
    
      
    
    OBJ
    
      tv    : "tv"
      gr    : "graphics"
      mouse : "mouse"
    
    
    PUB start | i, j, k, kk, dx, dy, pp, pq, rr, numx, numchr
    
      'start tv
      longmove(@tv_status, @tvparams, paramcount)
      tv_screen := @screen
      tv_colors := @colors
      tv.start(@tv_status)
    
      'init colors
      repeat i from 0 to 63
        colors[i] := $00001010 * (i+4) & $F + $2B060C02
    
      'init tile screen
      repeat dx from 0 to tv_hc - 1
        repeat dy from 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)
    
      'start mouse
      mouse.start(24, 25)
    
      repeat
    
        'clear bitmap
        gr.clear
    
     *****************************
     *put your commands here!    *
     *****************************
     
    
        'copy bitmap to display
        gr.copy(display_base)
    
        
        
    
    DAT
    
    tvparams                long    0               'status
                            long    1               'enable
                            long    %001_0101       'pins
                            long    %0000           'mode
                            long    0               'screen
                            long    0               'colors
                            long    x_tiles         'hc
                            long    y_tiles         'vc
                            long    10              'hx
                            long    1               'vx
                            long    0               'ho
                            long    0               'vo
                            long    0               'broadcast
                            long    0               'auralcog
    
    [/i]
    



    Essentially, you need the loop that clears the drawing screen, runs your commands, copies them to the display screen, then starts over. Without that, you won't see anything with these graphics objects. They are double buffered.

    It seems to me, you are putting your graphics commands in the wrong place too. The graphics.spin contains the primitives you need to draw lines, etc... the tv.spin actually drives the video, and another program will wrap that together to form a whole that displays stuff on your screen.

    Check out the graphics_demo.spin. I've stripped it down here, so you can just add the commands you want to explore and run it with your copy of the prop tool. In the OBJ section, you see mouse, tv and graphics defined to point to their respective spin program blocks. This is what you want to do with your sample graphics programs. Since nearly the entire works is software, there are a number of parameters to be managed. That's why stripping down one of the demos is a great place to start!

    If a copy - paste from the forum does not work, just edit your graphics_demo.spin to look similar to the one I posted here, and go for it. Worst case, remove one command at a time, until you have just the empty screen running!

    Post Edited (potatohead) : 3/20/2007 1:46:41 PM GMT
  • FritzFritz Posts: 2
    edited 2007-03-20 14:13
    Thanks for your help!

    It was problem concerning the scaling and the point of origin's location. It's solved now.

    The example codes are very helpful!
Sign In or Register to comment.