Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
lines
#11
HyperBASIC? looks like fb to me ;P


for qb 4.5:

Code:
Declare Sub DrawLine( colour As Integer, x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer )


Screen 13

DrawLine 15, 1, 1, 7, 7




Sub DrawLine( colour As Integer, x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer)

    Dim slope As Double,x As Double,y As Double
    slope = (y2 - y1) / (x2 - x1)
  
    x = x1+0.5
    y = y1+0.5
  
    If (Abs(slope) > 1) Then
      
        slope = (x2 - x1) / (y2 - y1)
        If (y1 < y2) Then
          
            While (Int(y) <= y2)
              
                PSet (Int(x),Int(y)),colour
                y = y + 1
                x = x + slope
            Wend
          
        Else
          
            While (Int(y) >= y2)
              
                PSet (Int(x),Int(y)),colour
                y = y - 1
                x = x - slope
            Wend
        End If
      
    ElseIf(x1 < x2) Then
      
      
      
        While(Int(x) <= x2)
          
            PSet (Int(x),Int(y)),colour
            x = x + 1
            y = y + slope
        Wend
      
    Else
      
        While(Int(x) >= x2)
          
            PSet (Int(x),Int(y)),colour
            x = x - 1
            y = y - slope
        Wend
    End If
End Sub


yeah, take that all n00bs who said i push fb on people, i can still go at it in qb with the best of em. =p
Reply
#12
well, this almost works:

Code:
screen 13,,,1
dim x as double
dim d as double
x = 50:y = 50
x2 = 120:y2 = 110
d = (x2-50)/(y2-50)
line (x,y)-(x2,y2),4
y = y-1
x = x-d
for i = 0 to 60
  y = y+1
  x = x+d
  locate 1,1:?x
  pset(x,y)
next
sleep
quote="whitetiger0990"]whitetiger is.. WHITE POWER!!! [/quote]
Here
Reply
#13
Try this:
Code:
screen 13,,,1
dim x as double
dim d as double
x = 50:y = 50
x2 = 120:y2 = 110
d = (x2-50)/(y2-50)
line (x,y)-(x2,y2),4
y = y-1
x = x-d
for i = 0 to 60
  y = y+1
  for sx=x to x+d
        pset(sx,y)
  next sx
  x = x+d  
next i
sleep

This is just a modification of the code posted. It may not apply to all cases.
I'm sure that if you stare at this long enough, you'll hit upon a better way to organize the code.
By the way, this is FB code. QB may draw lines differently.

edit. I just tried it with QB, and it does not work.
Reply
#14
Code:
DX=x2-x1
dy=y2-y1

L!=sqr(DX*dx+dy*dy)

NX!=DX/L!
NY!=dy/L!


For I=0 to L!

X1=x1+NX!
Y1=Y1+NY!
Pset(x1!,Y1!),15
Next I

This should work. My code was adapted from that to use integers only, although incorrectly I guess.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#15
I spent some time last night disassembling the line drawing routine from bcom45.lib last night. I didn't have time to pick out the fine details (weeding out all the code that clips the coordinates and checks for the memory geometry of the current screen mode is a bit difficult, plus the coordinate arguments are actually passed by two separate routines that set global variables before the general line routine is called), but it looks like it uses an error collection/correction scheme similar to Bresenham, but it is optimized to take advantage of the layout of screen memory. It works from the top of the line, down, adjusting a memory pointer up or down to move horizontally and adding to the pointer to advance in the vertical direction. The code looks like it has been optimized for speed in specific places and for size generally (Setting the es register to the screen memory segment is accomplished by a call to a subroutine that does nothing but load es from a memory location, apparently set by the screen mode setting routine, then immediately returns. Very slow.) so sorting out what does what is pain staking. Replicating this algorythm with individual PSET statement would be a little tricky, since the code itself doesn't actually track the x and y cooridnates. If anyone is interested, I'll keep working at it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)