5:01 am GMT
Examples
Examples » QBasic/QuickBASIC
'/Water on top of Plasma. :*)
'/Just found out that the more pixels you sample the better the ripple looks.
'/So I sampled 8 instead of just 4.
'/The plasma uses sine additions so no pal rotation is done. :*)
'/This would run inside the Ide but compile for speed.
'/Relsoft My 11,2003
DEFINT A-Z
REM $DYNAMIC
CONST PI = 3.14151693#
CONST Xmax% = 319 'Viewport dimensions
CONST Ymax% = 199 'Small means fast
CONST XmaxM1% = Xmax% - 1
CONST YmaxM1% = Ymax% - 1
CONST XmaxP1% = Xmax% + 1
CONST YmaxP1% = Ymax% + 1
Xm& = Xmax% + 1
Ym& = Ymax% + 1
Xmm& = Xmax%
Size& = ((Xm& * Ym&) \ 2)
DIM Texture%(Size&)
DIM w1%(Size&)
DIM w2%(Size&)
DIM Lsin1%(-1024 TO 1024)
DIM Lsin2%(-1024 TO 1024)
DIM Lsin3%(-1024 TO 1024)
DIM Ly&(Ymax%)
FOR i% = -1024 TO 1024
Lsin1%(i%) = SIN(i% / (32)) * 128 'Movement to left
Lsin2%(i%) = SIN(i% / (64)) * 128 'Horiz bands
Lsin3%(i%) = SIN(i% / (64)) * 128 'Vertical bands
NEXT i%
FOR i% = 0 TO Ymax%
Ly&(i%) = i% * Xmm&
NEXT i%
wseg1% = VARSEG(w1%(0))
wseg2% = VARSEG(w2%(0))
woff1& = VARPTR(w1%(0))
woff2& = VARPTR(w2%(0))
Tseg% = VARSEG(Texture%(0))
Toff& = VARPTR(Texture%(0))
CLS
SCREEN 13
RANDOMIZE TIMER
FOR i% = 0 TO 255
OUT &H3C8, i%
OUT &H3C9, INT(32 - 31 * SIN(i% * PI / 32))
OUT &H3C9, INT(32 - 31 * SIN(i% * PI / 64))
OUT &H3C9, INT(32 - 31 * SIN(i% * PI / 128))
NEXT i%
Frames& = 0
T# = TIMER
DO
Frames& = Frames& + 1
IF Frames& AND 1 THEN
DEF SEG = wseg1%
ty% = 2 + INT(RND * YmaxM1% - 3) 'Rain
tx% = 2 + INT(RND * XmaxM1% - 3)
IF tx% > 1 AND ty% > 1 AND tx% < XmaxM1% AND ty% < YmaxM1% THEN
POKE woff1% + Ly&(ty%) + tx%, 255
END IF
T! = TIMER 'Your finger
x% = INT(COS(T! * .8) + SIN(T!) * 140)
y% = INT(SIN(T! + .2) * SIN(T! * .2) * 90)
xx% = x% + Xmax% \ 2
yy% = y% + Ymax% \ 2
IF xx% > 1 AND yy% > 1 AND xx% < XmaxM1% AND yy% < YmaxM1% THEN
POKE woff1% + Ly&(yy%) + xx%, 255
POKE woff1% + Ly&(200 - yy%) + (320 - xx%), 255
END IF
END IF
GOSUB Plasma
off1& = woff1% + Xmax% + 1
off2& = woff2% + Xmax% + 1
'Water simulation
FOR y% = 1 TO YmaxM1%
FOR x% = 1 TO XmaxM1%
DEF SEG = wseg1%
c% = PEEK(off1& + 1) + PEEK(off1& - 1) + PEEK(off1& + Xmax%) + PEEK(off1& - Xmax%)
c% = c% + PEEK(off1& + XmaxM1%) + PEEK(off1& - XmaxM1%) + PEEK(off1& + XmaxP1%) + PEEK(off1& - XmaxP1%)
DEF SEG = wseg2%
c% = (c% \ 4 - PEEK(off2&))
c% = ABS(c% - c% \ 256)
POKE off2&, c%
off1& = off1& + 1
off2& = off2& + 1
NEXT x%
off1& = off1& + 1
off2& = off2& + 1
NEXT y%
offs& = 0
off1& = woff1% + Xmax% + 1
off2& = woff2% + Xmax% + 1
'Refraction
FOR y% = 1 TO YmaxM1%
FOR x% = 1 TO XmaxM1%
DEF SEG = wseg1%
Xoff% = PEEK(off1& - 1) - PEEK(off1& + 1)
Yoff% = PEEK(off1& - Xmax%) - PEEK(off1& + Xmax%)
xt% = x% + Yoff% \ 4
yt% = y% + Xoff% \ 4
IF xt% > 0 AND yt% > 0 AND xt% < Xmax% AND yt% < Ymax% THEN
DEF SEG = Tseg%
c% = PEEK(Ly&(yt%) + xt% + Toff&)
ELSE
c% = 0
END IF
DEF SEG = &HA000
POKE offs& + x%, c%
off1& = off1& + 1
NEXT x%
offs& = offs& + 320
off1& = off1& + 1
NEXT y%
SWAP wseg1%, wseg2% 'Magic
LOOP UNTIL INKEY$ <> ""
DEF SEG
CLS
SCREEN 0
WIDTH 80
PRINT "FPS:"; Frames& / (TIMER - T#)
PRINT "Water on Plasma by Relsoft"
c$ = INPUT$(1)
END
Plasma:
DEF SEG = Tseg%
Ptr& = Toff&
counter& = (counter& + 1) AND &H7FFFFFFF
FOR y% = 0 TO Ymax%
yy% = (y% + counter&) AND 1023
FOR x% = 0 TO Xmax%
xx% = (x% + counter&) AND 1023
c% = Lsin3%(x% + y%) + Lsin1%(xx%) + Lsin2%(yy%)
POKE Ptr& + x%, c%
NEXT x%
Ptr& = Ptr& + Xmax%
NEXT y%
RETURN
This category contains 2
examples, and has been viewed 30527 times.
- Plasma - An example of Plasma in QuickBASIC by Relsoft (9122 views)
- Dangerous Example - A simple QBasic example (7724 views)
|