Author Topic: more fun with lines  (Read 2525 times)

0 Members and 1 Guest are viewing this topic.

xteraco

  • Guest
more fun with lines
« on: May 16, 2006 »
heres something i did  a whle back... looks kinda riply or something...  its 2 files, you'll need to make then both in the same dir, then compile

pset_line.bas
Code: [Select]
'goal, draw a line to a specified point, and stop

declare sub pset_line(x1,y1,x2,y2)

type position
    x as integer
    y as integer
end type

dim startpoint as position
dim endpoint as position

screenres 800,600,32,2


sub pset_line(x1,y1,x2,y2)
    startpoint.x = x1
    startpoint.y = y1
    endpoint.x = x2
    endpoint.y = y2
for i = 1 to 5
pset (startpoint.x, startpoint.y)
if startpoint.x < endpoint.x then startpoint.x = startpoint.x + 1 :  i = 4 end if
if startpoint.y < endpoint.y then startpoint.y = startpoint.y + 1 : i = 4 end if
if startpoint.x > endpoint.x then startpoint.x = startpoint.x - 1 : i = 4 end if
if startpoint.y > endpoint.y then startpoint.y = startpoint.y - 1 : i = 4 end if
next
   
end sub


'main file.bas
Code: [Select]
'$include: 'pset_line.bas'
screenres 800,600,32,2
'pset_line(x,100,200,200)

SCREENRES 800,600,32,2
DEFSNG A-Z

CONST LENS = 256
CONST PI = 3.14

CENTX = 400: CENTY = 300

TYPE Cord3D
    X AS SINGLE
    Y AS SINGLE
    Z AS SINGLE
END TYPE

TYPE Cord2D
    X AS INTEGER
    Y AS INTEGER
END TYPE

DIM SHARED AS Cord3D PNT(8), Cam, Ang
DIM SHARED AS Cord2D SCR(8)
DIM SHARED AS INTEGER P1, P2 = 1

DIM SHARED FLASH(800*600*4+4)

PNT(1).X = -10: PNT(1).Y = 10: PNT(1).Z = 10
PNT(2).X = 10: PNT(2).Y = 10: PNT(2).Z = 10
PNT(3).X = 10: PNT(3).Y = -10: PNT(3).Z = 10
PNT(4).X = -10: PNT(4).Y = -10: PNT(4).Z = 10

PNT(5).X = -10: PNT(5).Y = 10: PNT(5).Z = -10
PNT(6).X = 10: PNT(6).Y = 10: PNT(6).Z = -10
PNT(7).X = 10: PNT(7).Y = -10: PNT(7).Z = -10
PNT(8).X = -10: PNT(8).Y = -10: PNT(8).Z = -10

Cam.X = 0
Cam.Y = 0
Cam.Z = 220

Ang.X = 0
Ang.Y = 0
Ang.Z = 0


BLX = 10
BLY = 10

FLS = 255
CV = 1

DO
    SCREENSET P2, P1
    SWAP P1, P2
    CLS

    FOR i = 1 TO 8
        X = PNT(i).X
        Y = PNT(i).Y
        Z = PNT(i).Z
       
        NY = Y * COS( Ang.X * PI / 180) - Z * SIN(Ang.X * PI / 180)
        NZ = Z * COS(Ang.X * PI / 180) + Y * SIN(Ang.X * PI / 180)
        Y = NY
        Z = NZ
       
        NZ = Z * COS(Ang.Y * PI / 180) - X * SIN(Ang.Y * PI / 180)
        NX = X * COS(Ang.Y * PI / 180) + Z * SIN(Ang.Y * PI / 180)
        X = NX
       
        NX = X * COS(Ang.Z * PI / 180) - Y * SIN(Ang.Z * PI / 180)
        NY = Y * COS(Ang.Z * PI / 180) + X * SIN( Ang.Z * PI / 180)
       
        RX = NX - Cam.X
        RY = NY - Cam.Y
        RZ = NZ + Cam.Z
       
        Dist = LENS - RZ
        IF Dist < 256 AND Dist > 0 THEN
            SCR(i).X = CENTX + (LENS * RX / Dist)
            SCR(i).Y = CENTY - (LENS * RY / Dist)
        END IF
    NEXT
    pset_LINE (SCR(1).X, SCR(1).Y,SCR(2).X, SCR(2).Y)
    pset_LINE (SCR(2).X, SCR(2).Y,SCR(3).X, SCR(3).Y)
    pset_LINE (SCR(3).X, SCR(3).Y,SCR(4).X, SCR(4).Y)
    pset_LINE (SCR(4).X, SCR(4).Y,SCR(1).X, SCR(1).Y)
   
    pset_LINE (SCR(5).X, SCR(5).Y,SCR(6).X, SCR(6).Y)
    pset_LINE (SCR(6).X, SCR(6).Y,SCR(7).X, SCR(7).Y)
    pset_LINE (SCR(7).X, SCR(7).Y,SCR(8).X, SCR(8).Y)
    pset_LINE (SCR(8).X, SCR(8).Y,SCR(5).X, SCR(5).Y)
   
    pset_LINE (SCR(5).X, SCR(5).Y,SCR(1).X, SCR(1).Y)
    pset_LINE (SCR(6).X, SCR(6).Y,SCR(2).X, SCR(2).Y)
    pset_LINE (SCR(7).X, SCR(7).Y,SCR(3).X, SCR(3).Y)
    pset_LINE (SCR(8).X, SCR(8).Y,SCR(4).X, SCR(4).Y)
   
    Ang.X += 1
    Ang.Y += 1
    Ang.Z += 1
   
   
   
    SLEEP 20
LOOP UNTIL INKEY$ <> ""


Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: more fun with lines
« Reply #1 on: May 16, 2006 »
Haha, A drunken cube. Neat one Xteraco.
Shockwave ^ Codigos
Challenge Trophies Won: