Author Topic: Fun with lines.....  (Read 5686 times)

0 Members and 1 Guest are viewing this topic.

Offline relsoft

  • DBF Aficionado
  • ******
  • Posts: 3303
  • Karma: 47
    • View Profile
Fun with lines.....
« on: May 12, 2006 »
Basically additive blended lines.  This should be easier with OpenGL using belnding and forward kinematics.  
ie.

for each "tentacle"
Push
transform
pop

Enough rant. here's the demo:


Code: [Select]
'//640 x 480 madness!!!
'//Lines in mono
'//Relsoft 2004
'//v3cz0r is da man!
'//
defint a-z
'$include: 'tinyptc.bi'

type point3d
  Â  Â x  Â  Â  as single
  Â  Â y  Â  Â  as single
  Â  Â z  Â  Â  as single
  Â  Â sx  Â  Â as integer
  Â  Â sy  Â  Â as integer
  Â  Â color  as integer
end type

declare sub Rel_cls( buffer())
declare sub xpcopy (  dest() as integer,  source() as integer)
declare sub smooth(Â  buffer())
declare sub Rel_pset( buffer(), byval x as integer, byval y as integer, byval col as integer)
declare sub draw_line_B( buffer(), byval x as integer, byval y as integer, byval x2 as integer, byval y2 as integer, byval col as integer)

option explicit

const SCR_WIDTH = 320Â  * 2
const SCR_HEIGHT = 240 * 2
const SCR_SIZE = SCR_WIDTH*SCR_HEIGHT


const PI = 3.141593
const LENS = 256
const XMID = SCR_WIDTH \2
const YMID = SCR_HEIGHT \2


dim shared buffer( 0 to SCR_SIZE-1 ) as integer
dim shared points(3,2) as point3d


  Â  dim i as integer
  Â  dim sx as single
  Â  dim sy as single
  Â  dim sz as single
  Â  dim cx as single
  Â  dim cy as single
  Â  dim cz as single
  Â  dim xx as single
  Â  dim xy as single
  Â  dim xz as single
  Â  dim yx as single
  Â  dim yy as single
  Â  dim yz as single
  Â  dim zx as single
  Â  dim zy as single
  Â  dim zz as single
  Â  dim rx as single
  Â  dim ry as single
  Â  dim rz as single
  Â  dim ang as integer
  Â  dim angx as uinteger
  Â  dim angy as uinteger
  Â  dim angz as uinteger
  Â  dim ax as single
  Â  dim ay as single
  Â  dim az as single
  Â  dim rad as integer
  Â  dim x as single
  Â  dim y as single
  Â  dim z as single
  Â  dim dist as integer
  Â  dim ox as integer
  Â  dim oy as integer
  Â  dim tx as integer
  Â  dim ty as integer
  Â  dim r, g , b as integer



if( ptc_open( "freeBASIC v0.01 - RelGFX win demo(Relsoft)", SCR_WIDTH, SCR_HEIGHT ) = 0 ) then
end -1
end if

  Â  points(0,0).x = -1
  Â  points(0,0).y = -1
  Â  points(0,0).z = 0
  Â  points(1,0).x = -1
  Â  points(1,0).y = 1
  Â  points(1,0).z = 0
  Â  points(2,0).x = 1
  Â  points(2,0).y = 1
  Â  points(2,0).z = 0
  Â  points(3,0).x = 1
  Â  points(3,0).y = -1
  Â  points(3,0).z = 0

  Â  points(0,1).z = -1
  Â  points(0,1).y = -1
  Â  points(0,1).x = 0
  Â  points(1,1).z = -1
  Â  points(1,1).y = 1
  Â  points(1,1).x = 0
  Â  points(2,1).z = 1
  Â  points(2,1).y = 1
  Â  points(2,1).x = 0
  Â  points(3,1).z = 1
  Â  points(3,1).y = -1
  Â  points(3,1).x = 0

  Â  points(0,2).z = -1
  Â  points(0,2).x = -1
  Â  points(0,2).y = 0
  Â  points(1,2).z = -1
  Â  points(1,2).x = 1
  Â  points(1,2).y = 0
  Â  points(2,2).z = 1
  Â  points(2,2).x = 1
  Â  points(2,2).y = 0
  Â  points(3,2).z = 1
  Â  points(3,2).x = -1
  Â  points(3,2).y = 0


  Â  for i = 0 to 3
  Â  Â  Â  points(i,0).x =  points(i,0).x * 9.5
  Â  Â  Â  points(i,0).y =  points(i,0).y * 9.5
  Â  Â  Â  points(i,0).z =  points(i,0).z * 9.5
  Â  Â  Â  r = 4
  Â  Â  Â  g = 0
  Â  Â  Â  b = 1
  Â  Â  Â  points(i,0).color = r shl 16 or g shl 8 or b

  Â  Â  Â  points(i,1).x =  points(i,1).x * 9.5
  Â  Â  Â  points(i,1).y =  points(i,1).y * 9.5
  Â  Â  Â  points(i,1).z =  points(i,1).z * 9.5
  Â  Â  Â  r = 1
  Â  Â  Â  g = 0
  Â  Â  Â  b = 4
  Â  Â  Â  points(i, 1).color = r shl 16 or g shl 8 or b

  Â  Â  Â  points(i,2).x =  points(i,2).x * 9.5
  Â  Â  Â  points(i,2).y =  points(i,2).y * 9.5
  Â  Â  Â  points(i,2).z =  points(i,2).z * 9.5
  Â  Â  Â  r = 0
  Â  Â  Â  g = 4
  Â  Â  Â  b = 1
  Â  Â  Â  points(i, 2).color = r shl 16 or g shl 8 or b

  Â  next i


  Â  dim s as single
  Â  dim j,k, x1, x2, y1, y2 as integer
  Â  dim t as single, dt as single, ti as single, tt as single
  Â  dim sinc as single
  Â  sinc = .05

  Â  do
  Â  Â  dim counter as integer

  Â  Â  Rel_cls buffer()
  Â  Â  s = 0
  Â  Â  ti = timer * 0.008
  Â  Â  t = ti * 2.5 * (sin(timer/3150) + cos(timer/4150) + sin(timer/3140))
  Â  Â  dt = 0.00130 + 0.00024 * (sin(timer/140) * sin(timer/1240) * cos(timer/540))

  Â  Â  for counter = 0 to 200 step 1

  Â  Â  Â  ax = 4 * t
  Â  Â  Â  ay = 8 * t
  Â  Â  Â  az = 9 * t


  Â  Â  Â  cx = cos(ax)
  Â  Â  Â  sx = sin(ax)
  Â  Â  Â  cy = cos(ay)
  Â  Â  Â  sy = sin(ay)
  Â  Â  Â  cz = cos(az)
  Â  Â  Â  sz = sin(az)

  Â  Â  Â  xx = cy * cz
  Â  Â  Â  xy = sx * sy * cz - cx * sz
  Â  Â  Â  xz = cx * sy * cz + sx * sz

  Â  Â  Â  yx = cy * sz
  Â  Â  Â  yy = cx * cz + sx * sy * sz
  Â  Â  Â  yz = -sx * cz + cx * sy * sz

  Â  Â  Â  zx = -sy
  Â  Â  Â  zy = sx * cy
  Â  Â  Â  zz = cx * cy

  Â  Â  Â  ox = xmid
  Â  Â  Â  oy = ymid
  Â  Â  Â  for i = 0 to 3
  Â  Â  Â  Â  Â  for j = 0 to 2
  Â  Â  Â  Â  Â  Â  x  = points(i, j).x * s
  Â  Â  Â  Â  Â  Â  y  = points(i, j).y * s
  Â  Â  Â  Â  Â  Â  z  = points(i, j).z * s
  Â  Â  Â  Â  Â  Â  rx = (x * xx + y * xy + z * xz)
  Â  Â  Â  Â  Â  Â  ry = (x * yx + y * yy + z * yz)
  Â  Â  Â  Â  Â  Â  rz = (x * zx + y * zy + z * zz)
  Â  Â  Â  Â  Â  Â  dist = LENS - rz
  Â  Â  Â  Â  Â  Â  IF dist > 0 THEN
  Â  Â  Â  Â  Â  Â  Â  Â  tx = XMID + (rx * LENS / dist)
  Â  Â  Â  Â  Â  Â  Â  Â  ty = YMID - (ry * LENS / dist)
  Â  Â  Â  Â  Â  Â  Â  Â  points(i, j).sx = tx
  Â  Â  Â  Â  Â  Â  Â  Â  points(i, j).sy = ty  Â  Â  Â  Â  Â  Â  Â  Â  
  Â  Â  Â  Â  Â  Â  Â  Â  draw_line_b buffer(), tx, ty, ox, oy, points(i,j).color
  Â  Â  Â  Â  Â  Â  Â  Â  draw_line_b buffer(), tx, ty, xmid, ymid, points(i,2-j).color  Â  Â  Â  Â  Â  Â  Â  Â  
  Â  Â  Â  Â  Â  Â  Â  Â  draw_line_b buffer(), ox, oy, xmid, ymid, points(3-i,2-j).color
  Â  Â  Â  Â  Â  Â  Â  Â  ox = tx
  Â  Â  Â  Â  Â  Â  Â  Â  oy = ty
  Â  Â  Â  Â  Â  Â  END IF
  Â  Â  Â  Â  Â  next j
  Â  Â  Â  next i

  Â  Â  Â  Â  Â  s = s + sinc
  Â  Â  Â  Â  Â  t = t + dt

  Â  Â  next counter


  Â  Â  ptc_update @buffer(0)
  Â  loop until inkey$<>""


ptc_close






'*******************************************************************************************
'GFX subs/Funks
'
'*******************************************************************************************

private sub Rel_Pset( buffer(), byval x as integer, byval y as integer, byval col as integer)
  Â  Â  Â  if x > -1 and x <SCR_WIDTH and y > -1 and Y < SCR_HEIGHT then
  Â  Â  Â  Â  Â  buffer(y * SCR_WIDTH + x) = col
  Â  Â  Â  end if
end sub


private sub Rel_Cls( buffer())
  Â  dim p as integer ptr
  Â  dim s as integer
  Â  s = SCR_SIZE
  Â  p = @buffer(0)
  Â  asm
  Â  Â  Â  mov edi, dword ptr [p]
  Â  Â  Â  mov ecx, dword ptr [s]
  Â  Â  Â  xor eax, eax
  Â  Â  Â  rep stosd
  Â  end asm
end sub

private sub xpcopy (  dest() as integer,  source() as integer)
  Â  dim offset as long
  Â  for offset = 0 to  SCR_SIZE -1
  Â  Â  Â  dest( offset ) = source( offset )
  Â  next offset

end sub

private sub smooth(Â  buffer())
  Â  dim maxpixel as uinteger
  Â  dim offset as integer
  Â  dim pixel as uinteger
  Â  dim r as uinteger
  Â  dim g as uinteger
  Â  dim b as uinteger
  Â  dim nr as uinteger
  Â  dim ng as uinteger
  Â  dim nb as uinteger



  Â  maxpixel = ubound(buffer)
  Â  for offset = SCR_WIDTH to maxpixel-SCR_WIDTH
  Â  Â  Â  pixel = buffer(offset-1)
  Â  Â  Â  r = pixel shr 16
  Â  Â  Â  g = pixel shr 8 and 255
  Â  Â  Â  b = pixel and 255
  Â  Â  Â  nr = r shr 2
  Â  Â  Â  ng = g shr 2
  Â  Â  Â  nb = b shr 2
  Â  Â  Â  pixel = buffer(offset+1)
  Â  Â  Â  r = pixel shr 16
  Â  Â  Â  g = pixel shr 8 and 255
  Â  Â  Â  b = pixel and 255
  Â  Â  Â  nr = nr + ( r shr 2 )
  Â  Â  Â  ng = ng + ( g shr 2 )
  Â  Â  Â  nb = nb + ( b shr 2 )
  Â  Â  Â  pixel = buffer(offset+SCR_WIDTH)
  Â  Â  Â  r = pixel shr 16
  Â  Â  Â  g = pixel shr 8 and 255
  Â  Â  Â  b = pixel and 255
  Â  Â  Â  nr = nr + ( r shr 2 )
  Â  Â  Â  ng = ng + ( g shr 2 )
  Â  Â  Â  nb = nb + ( b shr 2 )
  Â  Â  Â  pixel = buffer(offset-SCR_WIDTH)
  Â  Â  Â  r = pixel shr 16
  Â  Â  Â  g = pixel shr 8 and 255
  Â  Â  Â  b = pixel and 255
  Â  Â  Â  nr = nr + ( r shr 2 )
  Â  Â  Â  ng = ng + ( g shr 2 )
  Â  Â  Â  nb = nb + ( b shr 2 )
  Â  Â  Â  buffer(offset) = nr shl 16 or ng shl 8 or nb
  Â  next i
end sub


private sub draw_line_B( buffer(), byval x as integer, byval y as integer, byval x2 as integer, byval y2 as integer, byval col as integer)

dim i as integer
dim slope as integer
dim eterm as integer
dim dx as integer
dim dy as integer
dim sx as integer
dim sy as integer
dim notclip as integer
dim temp as integer


const scrxmax = SCR_WIDTHÂ  - 1
const scrymax = SCR_HEIGHT - 1


I = 0
Slope = 0
Eterm = 0

IF (X2 - X) > 0 THEN
  Â  Â SX = 1
ELSE
  Â  Â SX = -1
END IF
Dx = ABS(X2 - X)


IF (Y2 - Y) > 0 THEN
  Â  Â SY = 1
ELSE
  Â  Â SY = -1
END IF
Dy = ABS(Y2 - Y)

IF (Dy > Dx) THEN
  Â  Â  Â  Slope = 1
  Â  Â  Â  temp = x
  Â  Â  Â  x = y
  Â  Â  Â  y = temp

  Â  Â  Â  temp = dx
  Â  Â  Â  dx = dy
  Â  Â  Â  dy = temp

  Â  Â  Â  temp = sx
  Â  Â  Â  sx = sy
  Â  Â  Â  sy = temp

END IF
Eterm = 2 * Dy - Dx

dim pixel, pixel2, r, g, b, nr, ng, nb as integer

pixel = col
FOR I = 0 TO Dx - 1
  Â IF Slope = 1 THEN
  Â  Â NotClip = (((Y < 0) + (X < 0) + (Y > scrxmax) + (X > scrymax)) = 0)
  Â  Â IF NotClip THEN
  Â  Â  Â  r = pixel shr 16
  Â  Â  Â  g = pixel shr 8 and 255
  Â  Â  Â  b = pixel and 255
  Â  Â  Â  pixel2 = buffer(x * SCR_WIDTH + y )
  Â  Â  Â  nr = pixel2 shr 16
  Â  Â  Â  ng = pixel2 shr 8 and 255
  Â  Â  Â  nb = pixel2 and 255
  Â  Â  Â  r = (r + nr)
  Â  Â  Â  if r > 255 then r = 255
  Â  Â  Â  g = (g + ng)
  Â  Â  Â  if g > 255 then g = 255
  Â  Â  Â  b = (b + nb)
  Â  Â  Â  if b > 255 then b = 255
  Â  Â  Â  buffer(x * SCR_WIDTH + y ) = r shl 16 or g shl 8 or b
  Â  Â end if
  Â ELSE
  Â  Â NotClip = (((X < 0) + (Y < 0) + (X > scrxmax) + (Y > scrymax)) = 0)
  Â  Â IF NotClip THEN
  Â  Â  Â  r = pixel shr 16
  Â  Â  Â  g = pixel shr 8 and 255
  Â  Â  Â  b = pixel and 255
  Â  Â  Â  pixel2 = buffer(y * SCR_WIDTH + x )
  Â  Â  Â  nr = pixel2 shr 16
  Â  Â  Â  ng = pixel2 shr 8 and 255
  Â  Â  Â  nb = pixel2 and 255
  Â  Â  Â  r = (r + nr)
  Â  Â  Â  if r > 255 then r = 255
  Â  Â  Â  g = (g + ng)
  Â  Â  Â  if g > 255 then g = 255
  Â  Â  Â  b = (b + nb)
  Â  Â  Â  if b > 255 then b = 255
  Â  Â  Â  buffer(y * SCR_WIDTH + x ) = r shl 16 or g shl 8 or b
  Â  Â end if
  Â END IF

  Â WHILE Eterm >= 0
  Â  Â  Y = Y + SY: Eterm = Eterm - 2 * Dx
  Â WEND
  Â X = X + SX: Eterm = Eterm + 2 * Dy
NEXTÂ  I
  Â  Â NotClip = (((X2 < 0) + (Y2 < 0) + (X2 > scrxmax) + (Y2 > scrymax)) = 0)
  Â  Â IF NotClip THEN
  Â  Â  Â  r = pixel shr 16
  Â  Â  Â  g = pixel shr 8 and 255
  Â  Â  Â  b = pixel and 255
  Â  Â  Â  pixel2 = buffer(y2 * SCR_WIDTH + x2 )
  Â  Â  Â  nr = pixel2 shr 16
  Â  Â  Â  ng = pixel2 shr 8 and 255
  Â  Â  Â  nb = pixel2 and 255
  Â  Â  Â  r = (r + nr)
  Â  Â  Â  if r > 255 then r = 255
  Â  Â  Â  g = (g + ng)
  Â  Â  Â  if g > 255 then g = 255
  Â  Â  Â  b = (b + nb)
  Â  Â  Â  if b > 255 then b = 255
  Â  Â  Â  buffer(y2 * SCR_WIDTH + x2 ) = r shl 16 or g shl 8 or b

  Â  Â end if

end sub

« Last Edit: May 12, 2006 by relsoft »
Challenge Trophies Won:

Offline relsoft

  • DBF Aficionado
  • ******
  • Posts: 3303
  • Karma: 47
    • View Profile
Re: Fun with lines.....
« Reply #1 on: May 12, 2006 »
Here's the pixel ver so that you can see the "tentacles".


Code: [Select]
'//640 x 480 madness!!!
'//Lines
'//Relsoft 2004
'//v3cz0r is da man!
'//
defint a-z
'$include: 'tinyptc.bi'

type point3d
     x      as single
     y      as single
     z      as single
     sx     as integer
     sy     as integer
     color  as integer
end type

declare sub Rel_cls( buffer())
declare sub xpcopy (  dest() as integer,  source() as integer)
declare sub smooth(  buffer())
declare sub Rel_pset( buffer(), byval x as integer, byval y as integer, byval col as integer)
declare sub draw_line_B( buffer(), byval x as integer, byval y as integer, byval x2 as integer, byval y2 as integer, byval col as integer)

option explicit

const SCR_WIDTH = 320  * 2
const SCR_HEIGHT = 240 * 2
const SCR_SIZE = SCR_WIDTH*SCR_HEIGHT


const PI = 3.141593
const LENS = 256
const XMID = SCR_WIDTH \2
const YMID = SCR_HEIGHT \2


dim shared buffer( 0 to SCR_SIZE-1 ) as integer
dim shared points(3,2) as point3d


    dim i as integer
    dim sx as single
    dim sy as single
    dim sz as single
    dim cx as single
    dim cy as single
    dim cz as single
    dim xx as single
    dim xy as single
    dim xz as single
    dim yx as single
    dim yy as single
    dim yz as single
    dim zx as single
    dim zy as single
    dim zz as single
    dim rx as single
    dim ry as single
    dim rz as single
    dim ang as integer
    dim angx as uinteger
    dim angy as uinteger
    dim angz as uinteger
    dim ax as single
    dim ay as single
    dim az as single
    dim rad as integer
    dim x as single
    dim y as single
    dim z as single
    dim dist as integer
    dim ox as integer
    dim oy as integer
    dim tx as integer
    dim ty as integer
    dim r, g , b as integer



if( ptc_open( "freeBASIC v0.01 - RelGFX win demo(Relsoft)", SCR_WIDTH, SCR_HEIGHT ) = 0 ) then
end -1
end if

    points(0,0).x = -1
    points(0,0).y = -1
    points(0,0).z = 0
    points(1,0).x = -1
    points(1,0).y = 1
    points(1,0).z = 0
    points(2,0).x = 1
    points(2,0).y = 1
    points(2,0).z = 0
    points(3,0).x = 1
    points(3,0).y = -1
    points(3,0).z = 0

    points(0,1).z = -1
    points(0,1).y = -1
    points(0,1).x = 0
    points(1,1).z = -1
    points(1,1).y = 1
    points(1,1).x = 0
    points(2,1).z = 1
    points(2,1).y = 1
    points(2,1).x = 0
    points(3,1).z = 1
    points(3,1).y = -1
    points(3,1).x = 0

    points(0,2).z = -1
    points(0,2).x = -1
    points(0,2).y = 0
    points(1,2).z = -1
    points(1,2).x = 1
    points(1,2).y = 0
    points(2,2).z = 1
    points(2,2).x = 1
    points(2,2).y = 0
    points(3,2).z = 1
    points(3,2).x = -1
    points(3,2).y = 0


    for i = 0 to 3
        points(i,0).x =  points(i,0).x * 19.5
        points(i,0).y =  points(i,0).y * 19.5
        points(i,0).z =  points(i,0).z * 19.5
        r = 18
        g = 0
        b = 12
        points(i,0).color = r shl 16 or g shl 8 or b

        points(i,1).x =  points(i,1).x * 19.5
        points(i,1).y =  points(i,1).y * 19.5
        points(i,1).z =  points(i,1).z * 19.5
        r = 8
        g = 18
        b = 0
        points(i, 1).color = r shl 16 or g shl 8 or b

        points(i,2).x =  points(i,2).x * 19.5
        points(i,2).y =  points(i,2).y * 19.5
        points(i,2).z =  points(i,2).z * 19.5
        r = 8
        g = 2
        b = 18
        points(i, 2).color = r shl 16 or g shl 8 or b

    next i


    dim s as single
    dim j,k, x1, x2, y1, y2 as integer
    dim t as single, dt as single, ti as single
    dim sinc as single
    sinc = .05
    dim as integer frame = 0
    do
      dim counter as integer     
      smooth(  buffer())
     
      s = 0
      ti = timer * 0.008
      t = ti * 1.5 *sin(timer/3150)
      dt = 0.00130 + 0.0024 * sin(timer/40)

      for counter = 0 to 100 step 1

        ax = 15 * t
        ay = 25 * t
        az = 20 * t


        cx = cos(ax)
        sx = sin(ax)
        cy = cos(ay)
        sy = sin(ay)
        cz = cos(az)
        sz = sin(az)

        xx = cy * cz
        xy = sx * sy * cz - cx * sz
        xz = cx * sy * cz + sx * sz

        yx = cy * sz
        yy = cx * cz + sx * sy * sz
        yz = -sx * cz + cx * sy * sz

        zx = -sy
        zy = sx * cy
        zz = cx * cy

        ox = xmid
        oy = ymid
        for i = 0 to 3
            for j = 0 to 2
              x  = points(i, j).x * s
              y  = points(i, j).y * s
              z  = points(i, j).z * s
              rx = (x * xx + y * xy + z * xz)
              ry = (x * yx + y * yy + z * yz)
              rz = (x * zx + y * zy + z * zz)
              dist = LENS - rz
              IF dist > 0 THEN
                  tx = XMID + (rx * LENS / dist)
                  ty = YMID - (ry * LENS / dist)
                  points(i, j).sx = tx
                  points(i, j).sy = ty
                  Rel_pset buffer(),tx, ty, points(i,j).color * 13
                  'draw_line_b buffer(), tx, ty, ox, oy, points(i,j).color
                  ox = tx
                  oy = ty
              END IF
            next j
        next i

            s = s + sinc
            t = t + dt

      next counter


      ptc_update @buffer(0)
    loop until inkey$<>""


ptc_close






'*******************************************************************************************
'GFX subs/Funks
'
'*******************************************************************************************

private sub Rel_Pset( buffer(), byval x as integer, byval y as integer, byval col as integer)
        if x > -1 and x <SCR_WIDTH and y > -1 and Y < SCR_HEIGHT then
            buffer(y * SCR_WIDTH + x) = col
        end if
end sub


private sub Rel_Cls( buffer())
    dim p as integer ptr
    dim s as integer
    s = SCR_SIZE
    p = @buffer(0)
    asm
        mov edi, dword ptr [p]
        mov ecx, dword ptr [s]
        xor eax, eax
        rep stosd
    end asm
end sub

private sub xpcopy (  dest() as integer,  source() as integer)
    dim offset as long
    for offset = 0 to  SCR_SIZE -1
        dest( offset ) = source( offset )
    next offset

end sub


private sub draw_line_B( buffer(), byval x as integer, byval y as integer, byval x2 as integer, byval y2 as integer, byval col as integer)

dim i as integer
dim slope as integer
dim eterm as integer
dim dx as integer
dim dy as integer
dim sx as integer
dim sy as integer
dim notclip as integer
dim temp as integer


const scrxmax = SCR_WIDTH  - 1
const scrymax = SCR_HEIGHT - 1


I = 0
Slope = 0
Eterm = 0

IF (X2 - X) > 0 THEN
     SX = 1
ELSE
     SX = -1
END IF
Dx = ABS(X2 - X)


IF (Y2 - Y) > 0 THEN
     SY = 1
ELSE
     SY = -1
END IF
Dy = ABS(Y2 - Y)

IF (Dy > Dx) THEN
        Slope = 1
        temp = x
        x = y
        y = temp

        temp = dx
        dx = dy
        dy = temp

        temp = sx
        sx = sy
        sy = temp

END IF
Eterm = 2 * Dy - Dx

dim pixel, pixel2, r, g, b, nr, ng, nb as integer

pixel = col
FOR I = 0 TO Dx - 1
   IF Slope = 1 THEN
     NotClip = (((Y < 0) + (X < 0) + (Y > scrxmax) + (X > scrymax)) = 0)
     IF NotClip THEN
        r = pixel shr 16
        g = pixel shr 8 and 255
        b = pixel and 255
        pixel2 = buffer(x * SCR_WIDTH + y )
        nr = pixel2 shr 16
        ng = pixel2 shr 8 and 255
        nb = pixel2 and 255
        r = (r + nr)
        if r > 255 then r = 255
        g = (g + ng)
        if g > 255 then g = 255
        b = (b + nb)
        if b > 255 then b = 255
        buffer(x * SCR_WIDTH + y ) = r shl 16 or g shl 8 or b
     end if
   ELSE
     NotClip = (((X < 0) + (Y < 0) + (X > scrxmax) + (Y > scrymax)) = 0)
     IF NotClip THEN
        r = pixel shr 16
        g = pixel shr 8 and 255
        b = pixel and 255
        pixel2 = buffer(y * SCR_WIDTH + x )
        nr = pixel2 shr 16
        ng = pixel2 shr 8 and 255
        nb = pixel2 and 255
        r = (r + nr)
        if r > 255 then r = 255
        g = (g + ng)
        if g > 255 then g = 255
        b = (b + nb)
        if b > 255 then b = 255
        buffer(y * SCR_WIDTH + x ) = r shl 16 or g shl 8 or b
     end if
   END IF

   WHILE Eterm >= 0
      Y = Y + SY: Eterm = Eterm - 2 * Dx
   WEND
   X = X + SX: Eterm = Eterm + 2 * Dy
NEXT  I
     NotClip = (((X2 < 0) + (Y2 < 0) + (X2 > scrxmax) + (Y2 > scrymax)) = 0)
     IF NotClip THEN
        r = pixel shr 16
        g = pixel shr 8 and 255
        b = pixel and 255
        pixel2 = buffer(y2 * SCR_WIDTH + x2 )
        nr = pixel2 shr 16
        ng = pixel2 shr 8 and 255
        nb = pixel2 and 255
        r = (r + nr)
        if r > 255 then r = 255
        g = (g + ng)
        if g > 255 then g = 255
        b = (b + nb)
        if b > 255 then b = 255
        buffer(y2 * SCR_WIDTH + x2 ) = r shl 16 or g shl 8 or b

     end if

end sub


private sub smooth(  buffer())
    dim maxpixel as integer
    dim offset as integer
    dim pixel as integer
    dim r as integer
    dim g as integer
    dim b as integer
    dim nr as integer
    dim ng as integer
    dim nb as integer



    maxpixel = ubound(buffer)
    for offset = SCR_WIDTH to maxpixel-SCR_WIDTH
        pixel = buffer(offset-1)
        r = pixel shr 16
        g = pixel shr 8 and 255
        b = pixel and 255
        nr = r shr 2
        ng = g shr 2
        nb = b shr 2
        pixel = buffer(offset+1)
        r = pixel shr 16
        g = pixel shr 8 and 255
        b = pixel and 255
        nr = nr + ( r shr 2 )
        ng = ng + ( g shr 2 )
        nb = nb + ( b shr 2 )
        pixel = buffer(offset+SCR_WIDTH)
        r = pixel shr 16
        g = pixel shr 8 and 255
        b = pixel and 255
        nr = nr + ( r shr 2 )
        ng = ng + ( g shr 2 )
        nb = nb + ( b shr 2 )
        pixel = buffer(offset-SCR_WIDTH)
        r = pixel shr 16
        g = pixel shr 8 and 255
        b = pixel and 255
        nr = nr + ( r shr 2 )
        ng = ng + ( g shr 2 )
        nb = nb + ( b shr 2 )
        buffer(offset) = nr shl 16 or ng shl 8 or nb
    next i
end sub
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Fun with lines.....
« Reply #2 on: May 12, 2006 »
Nice stuff, I like it.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Fun with lines.....
« Reply #3 on: May 12, 2006 »
Yet again, 2 really cool and smart effects. Nice one cheif. 8)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17427
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Re: Fun with lines.....
« Reply #4 on: May 12, 2006 »
Don't know which version I like better, they are both cool.

It reminds me of the old shadebob and shadeline demos on the Amiga, only much nicer colours and that the patterns move around in a nice way makes it better too.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline relsoft

  • DBF Aficionado
  • ******
  • Posts: 3303
  • Karma: 47
    • View Profile
Re: Fun with lines.....
« Reply #5 on: May 15, 2006 »
I found the effect in tinyptc's site and somehow understanding by looking at the fx on how to do it, I made my own.  Not the same effect thouhgh. But the same approach(I think) :*)
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17427
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Re: Fun with lines.....
« Reply #6 on: May 15, 2006 »
You've given me an idea that I will hopefully be able to put to good use, I'll credit you for the inspiration of course :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline relsoft

  • DBF Aficionado
  • ******
  • Posts: 3303
  • Karma: 47
    • View Profile
Re: Fun with lines.....
« Reply #7 on: May 15, 2006 »
No problem. Do as you wish mate. :*)
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17427
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Re: Fun with lines.....
« Reply #8 on: May 16, 2006 »
Got to code a line draw routine first :)
Shockwave ^ Codigos
Challenge Trophies Won: