Menu

Ploting a line on 255 by 255 aray

Help
Paul Haug
2017-03-23
2017-03-23
  • Paul Haug

    Paul Haug - 2017-03-23

    I have the numbers displays on my vintage crt clock working, now I need to plot lines (Hours,Min,Sec) .
    (See pic below)
    For the line draw requirement.....
    It is basically a two dimensional array of 255 by 255, with X0,Y0 at the top left and X255, Y255 at the bottom right.
    My high school/college math skills have faded into the past, so some hints would be appreciated.
    So given two points, each defined by an X,Y position, need to plot a straight line.
    Example, given x0=23, y0=45 as start point, x1=233, y1=111, plot a line ?
    .
    EDIT: The crt display does not have blanking enabled (Z axis) at this time, so faint traces can be seen as the beam is moved across the screen.

    ..2nd EDIT: Using PIC16F886 at 20 Mhz..

     

    Last edit: Paul Haug 2017-03-24
  • Anobium

    Anobium - 2017-03-24

    Wow. Well done.

    I would hijack the GLCD routines. This will then work for you.

    What is your pixel write routine?

     
  • Anobium

    Anobium - 2017-03-24

    Thinking about this.

    I would recommned taking the GLCD for the Nokia Display and use this one as the basis of your driver.
    I supports text only and graphics - these are two different options.
    Then, you get all the capabilities of GLCD - lines, pixels, text etc. etc.

    When we write GLCD drivers - we do this. :-)

     
  • jackjames

    jackjames - 2017-03-24

    You have to calculate the equation:
    y-y1 = ((y2-y1)/(x2-x1))(x-x1).

     
  • Anobium

    Anobium - 2017-03-24

    Here is the code to for a line from GLCD.H. You would replace the PSET call - you do not need LineColour as this is optional.

    But, if you want Lines, Text (at differerent sizes) etc etc leveraging the existing GLCD would be very simple.

    #define GLCDLine Line
    Sub Line(In LineX1 as word, In LineY1 as word, In LineX2 as word, In LineY2 as word, Optional In LineColour as word = GLCDForeground)
    
          dim LineStepX as integer
          dim LineStepY as integer
          dim LineDiffX, LineDiffY as integer
          dim LineDiffX_x2, LineDiffY_x2 as integer
          dim LineErr as integer
    
    
    
          LineDiffX = 0
          LineDiffY = 0
          LineStepX = 0
          LineStepY = 0
          LineDiffX_x2 = 0
          LineDiffY_x2 = 0
          LineErr = 0
    
    
          LineDiffX =  LineX2 -   LineX1
          LineDiffY =  LineY2 -   LineY1
    
          if (LineDiffX > 0) then
                  LineStepX = 1
          else
                  LineStepX = -1
          end if
    
          if (LineDiffY > 0) then
              LineStepY = 1
           else
              LineStepY = -1
          end if
    
          LineDiffX = LineStepX * LineDiffX
          LineDiffY = LineStepY * LineDiffY
    
          LineDiffX_x2 = LineDiffX*2
          LineDiffY_x2 = LineDiffY*2
    
          if ( LineDiffX >= LineDiffY) then
    
              LineErr = LineDiffY_x2 - LineDiffX
    
              do while (   LineX1 <>  LineX2 )
    
                  PSet (   LineX1,   LineY1, LineColour )
                  LineX1 += LineStepX
                  if ( LineErr < 0) then
                      LineErr += LineDiffY_x2
                  else
                      LineErr += ( LineDiffY_x2 - LineDiffX_x2 )
                      LineY1 += LineStepY
                  end if
              loop
    
              PSet (   LineX1,   LineY1, LineColour )
          else
    
              LineErr = LineDiffX_x2 - LineDiffY
              do while (   LineY1 <>  LineY2)
                  PSet (   LineX1,   LineY1, LineColour )
                  LineY1 += LineStepY
                  if ( LineErr < 0) then
                      LineErr += LineDiffX_x2
                   else
                      LineErr += ( LineDiffX_x2 - LineDiffY_x2 )
                      LineX1 += LineStepX
                  end if
              loop
              PSet (   LineX1,   LineY1, LineColour )
    
          end if
    
    
    
    end sub
    
     
  • Paul Haug

    Paul Haug - 2017-03-24

    Thanks Anobium, the pixal plot is a lookup table for each number consisting of two bytes per pixal, one for horz position, one for vertical position, each number will uses about 80 bytes. Noy elegant, but works fr now. I may use the number/letter from the GLCD.H after I find it and understand it.
    How do I find a listing/description of the various public .H libraries. I have created my own local .H for my LCD.

     
  • Anobium

    Anobium - 2017-03-24

    your 'include' folder of your installation.

     
  • Paul Haug

    Paul Haug - 2017-03-26

    Want to thank all of you for the help. I have the line drawing software modified to work with my CRT display. I spent several days trying to work out the operating details of this GLCD firmware and I finally have it. It is great how it plots from any point to any other point, perfect for my clock hands as it works in all quadrants.
    Yes, I am re-inventing the wheel, since this project is available in kit form, but for me it is a challenge, sort of like a game, with the reward being a personal accomplishment, and educational.
    Paul
    Below is a test of some lines with the orig point always at the screen center. Refresh is so fast, no visable flicker.

     

    Last edit: Paul Haug 2017-03-26
  • William Roth

    William Roth - 2017-03-27

    Nice

     
  • stan cartwright

    stan cartwright - 2017-03-29

    A plot and line in "basic" for 128x64. Change plot.
    ;
    ;x1,y1 start line x2,y2 end line
    line:
    if x1<x2 then:sx="1:dx=x2-x1:else" sx="-1:dx=x1-x2:endif" if="" y1\<y2="" then="" :sy="1:dy=y2-y1:else" sy="-1:dy=y1-y2:endif" dx="">dy then:er=dx:else er=dy:endif dx=dx+dx:dy=dy+dy:py=y1:px=x1 if dx>dy then
    do
    ;plot
    pixel=py And 7
    ptr=py And $F8 << 4 Or px
    @ptr=1<<pixel or="" @ptr="" row="py">>3
    hi2cout (0,SSD1306_PAGEADDR)
    hi2cout (0,row)
    hi2cout (0,7)
    hi2cout (0,SSD1306_COLUMNADDR)
    hi2cout (0,px)
    hi2cout (0,127)
    hi2cout (64,@ptr)
    ;
    er=er-dy
    if er>32767 then
    er=er+dx:py=py+sy
    endif
    px=px+sx
    loop while px<>x2
    else
    do
    ;plot
    pixel=py And 7
    ptr=py And $F8 << 4 Or px
    @ptr=1<<pixel or="" @ptr="" ;="" screen="" byte="" row="py">>3
    hi2cout (0,SSD1306_PAGEADDR)
    hi2cout (0,row)
    hi2cout (0,7)
    hi2cout (0,SSD1306_COLUMNADDR)
    hi2cout (0,px)
    hi2cout (0,127)
    hi2cout (64,@ptr) ;plot pixel on screen
    ;
    er=er-dx
    if er>32767 then
    er=er+dy:px=px+sx
    endif
    py=py+sy
    loop while py<>y2
    endif
    return</pixel></pixel></x2>

     

    Last edit: stan cartwright 2017-03-29
  • stan cartwright

    stan cartwright - 2017-03-29

    That's not what I pasted but if I edit it is?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.