Oxygen Basic

Programming => Example Code => Topic started by: Peter on September 19, 2015, 06:41:20 AM

Title: Sdl Update
Post by: Peter on September 19, 2015, 06:41:20 AM
Hello,
a bit updated.
Code: [Select]
include "sdl.inc"
window 640,480,1
LoadFont 1,"sdlfonts/vera.ttf",16
LoadFont 2,"sdlfonts/font6.ttf",32

TgaLoad  1,"tga/mouse.tga"

while key(27)=0
cls 0,0,0
SprPos 1,260,64,1,1
textcolor 255,255,255
text "MouseButton Test",220,16,1
text "Press a MouseButton",640/3,480/2,1
textcolor 231,187,122
if mousebutton()=1 then text "LEFT   BUTTON ",640/3,520/2,1
if mousebutton()=4 then text "RIGHT  BUTTON ",640/3,520/2,1
if mousebutton()=2 then text "MIDDLE BUTTON ",640/3,520/2,1

textcolor 128,162,269
text "ESCAPE ENDS THE TEST",140/2,580/2,2
redraw
wait 10
wend
Quit




[attachment deleted by admin]
Title: Re: Sdl Update
Post by: Peter on September 19, 2015, 06:42:23 AM
Sdl Example 10
Code: [Select]
include "sdl.inc"
window 640, 480, 1
LoadFont 1,"sdlfonts/font1.ttf",30
sys tl, i, x
string z= "WELCOME TO MY SDL LIBRARY...", letter
tl = len(z)
dim y(44) as single
dim angle(44) as single

for i=1 to tl
   angle(i) = 360-i*(360/tl)
   y(i) = 240
next

while Key(27)=0
cls 188,228,205
for x=1, tl
    angle(x) = angle(x) +1
    if angle(x) = 360 then angle(x)=0
    letter = mid(z,x,1)
    y(x) += cos(rad(angle(x)))*2
    color 255,255,255,255
    text letter,40+x*16,y(x),1
next
redraw
setfps 60
wend
winExit
Title: Re: Sdl Update
Post by: Peter on September 20, 2015, 07:36:09 AM
Hi,
Sdl Example 11:  Star Field
Code: [Select]
include "sdl.inc"
window 1024,768,1

int xStar[400]
int yStar[400]
int cStar[400]

for i=0 to 399
    xStar[i] = rand(0,1024)
    yStar[i] = rand(0,768)
    cStar[i] = rand(64,255)
next

for i=0 to 255
    color 0,0,i,255
    drawline(0,i+100,1023,i+100)
next
for i=0 to 255
    color 0,0,i,255
    drawline(0,600-i+10,1023,600-i)
next

for i=0 to 399
    color cStar[i],cStar[i],cStar[i],255
    fillcircle(xStar[i],yStar[i],1)
next
waitkey
Quit
Title: Re: Sdl Update
Post by: Peter on September 20, 2015, 09:19:58 AM
Hello,
Sdl Example 12: Golden Galaxia
Code: [Select]
include "sdl.inc"
window 512,512,1
loadfont 1,"sdlfonts/vera.ttf",16

single q  = 0.2         
single dq = 0.4         
single dt = 0.1         
single a1 = 1.2875
single a2 = 4.1201
single y[1000], x[1000], y2[1000], x2[1000]

int n   = 1000           
int bx1 = 100
int by1 = 80
int bw  = 256
int bh  = 256
int bx2 = 356
int by2 = 80
int o1, o2, count

function gasdev() as single
    u = 2 * rndF() - 1
    v = 2 * rndF() - 1
    r = u * u+v * v
    if r=0 or r >1 then return gasdev
    c = sqr(-2 * log(r) / r)
    return u*c
end function

sub init_gauss()
    for i=0 to n-1
        y[i] = gasdev() / 5
        x[i] = gasdev() / 5
    next
end sub

sub init_random()
    for i=0 to n-1
        y[i] = rndF()/1.4
        x[i] = rndF()/1.4
    next
end sub

for i=0 to n-1
    y[i] = (i+n/20)/(0.43*n+n/20)
    x[i] = 0
    x2[i]= 0
    y2[i]= y[i]
next

while key(27)=0
cls 0,0,0
textcolor 255,255,255
text "GOLDEN GALAXIA",180,16,1
meanx=0
for i=0 to n-1
    y[i] = y[i] - dt*(a1*sin(x[i]) + a2*sin(4*x[i]))
    x[i] = x[i] + y(i)*dt
    color 255,255,0,255
    fillcircle bx1+bw/2 + x[i]*bw/2, by1+bh/2 + y[i]*bh/5,2
    meanx = meanx + x[i]
next
meanx = meanx/n
o1 = bx1 + count / 3
o2 = by1 + bw + meanx * 150 + 50
count +=1
if count=1000 then count= -count
redraw
wait 10
wend
winExit
Title: Re: Sdl Update
Post by: Peter on September 21, 2015, 03:23:45 AM
Hi,
Sdl Example 13: Flower of life
Code: [Select]
include "sdl.inc"
window 640,480,1

float i,a
while key(27)=0
for i=0 tO 255
    color i,i,i,128
    setpixel 320+sin(i)*a,240+cos(i)*a
next
a +=.02
if a>=360 then a=-a
redraw
wend
Quit
Title: Re: Sdl Update
Post by: Peter on September 27, 2015, 03:35:45 PM
Hello,
Sdl Example 14: Surrealism
Code: [Select]
include "sdl.inc"
window 320,320,1
setcaption "Move Your Mouse Right,Left"

single r,var,theta,y,x,n,w,h,dx,dy
sys i,j,col

while Key(27)=0
n = xMouse()*40/ScrW
w = 16:h=16
dx= w/ScrW
dy= h/ScrH
x =-w/2

for i=0 to ScrW
    y=-h/2     
for j=0 to ScrH
    r=sqr(x*x)+(y*y)
    theta = atan(y,x)
    var = sin(n*cos(r)+5*theta)
    col = (var+1)*255/2
    color col,col,col,255
    drawpoint i,j,1
    y += dy
next
   x += dx
next
redraw
wait 10
wend
winExit



[attachment deleted by admin]
Title: Re: Sdl Update
Post by: Peter on September 28, 2015, 01:43:38 AM
Hi,
Sdl Example 15: Spiracle Tango
Code: [Select]
include "sdl.inc"
window 1024,768,1

sys w = scrW()/2
sys h = scrH()/2
single a=1, d=1, r, i

sub vec(single x, y, z)     
if z > 0 then return
if z = 0 then z = -0.01
ps = (1/z)*100 
sx = x * ps + w   
sy = y * ps + h 
fillcircle sx,sy,4
end sub

while key(27)=0
clsA 255,255,225,128
for i=1 to 1000
    color mod(i,190)+64,mod(i,190)+64,mod(i,190)+64,155
    vec cos(rad(i)*r)*12,sin(rad(i)*r)*6,-i/a
next
   
if a <=20 and d=1
   a = a+0.1
else
   d=2
endif       
   
if a >=0.5 and d=2
   a = a-0.1
else
   d=1
endif       
   
r = r+0.1
if r >=360 then r =-r

redraw
wait 20
wend
winExit
Title: Re: Sdl Update
Post by: Haim on September 28, 2015, 05:34:40 AM
Beautiful!
Thank you.
Best regards,
Title: Re: Sdl Update
Post by: Peter on September 28, 2015, 06:19:36 AM
Hello Haim  :D
Title: Re: Sdl Update
Post by: Peter on September 28, 2015, 07:39:22 AM
For my friend Haim,
he is the friendliest man in this forum.  :D

Sdl Example 16: Shield Plasma
Code: [Select]
'shield plasma by Peter Wirbelauer
include "sdl.inc"
window 320,240,1
cls 0,0,0

sys cList[32]
m = loadmusic "music/xp.mod"
playmusic (m)

sub cycling(sys d,i,f,b)
    if d=1
       t=cList[i]
       for e=i to f-1
           cList[e] = cList[e+1]
       next
       if b=1 then cList[f]=t
    else
       t=cList[f]
       for e=f to i+1 step -1
           cList[e] = cList[e-1]
       next
       if b=1 then cList[i]=t
    endif   
end sub

for i=0 to 15
    cList[i] = RGB(255,(i*16),0)
next
for i=0 to 15
    cList[i+16] = RGB(255,240-(i*16),0)
next

while key(27)=0
cycling(0,0,31,1)
for y=0 to 480
    yv1 = mod(y,32)
    c = cList[yv1]
    r = getR(c)
    g = getG(c)
    b = getB(c)
    color r,g,b,255
    thickline -1 ,cos(y),320,y,1
    thickline 320,cos(y), -1,y,1
next
redraw
wait 10
wend
winExit

[attachment deleted by admin]
Title: Re: Sdl Update
Post by: Peter on September 29, 2015, 11:23:33 AM
Hello,
Sdl Example 17: Butterfly
Code: [Select]
include "sdl.inc"
Window 800,800,1

single scale,ofs,flag,sp1,sd1,cm1,yy,xx,x,y,oldx,oldy
single theta,cv1,r,a
scale=80:ofs=400:flag=0:a=100*pi
TextColor 255,255,255
While Key(27)=0
      Color 255,255,255,255
      DrawString 20,20,"Press any key for alternative image"
      iF flag=0 then
         cv1=2:cm1=4:sp1=5:sd1=12
      End iF
      iF flag=1 then
         cv1=2.1:sp1=7:sd1=30:cm1=6
      End iF
      For theta=1 To a Step 0.010
          r=Exp(cos(theta))-cv1*cos(cm1*theta)+(sin(theta/sd1))^sp1
          x=r*cos(theta)
          y=r*sin(theta)
          yy=(x*scale)+ofs
          xx=(y*scale)+ofs
          iF theta=1 Then
             oldx=xx
             oldy=yy
          End iF
          iF theta <>0 Then
     AALine oldx,oldy,xx,yy
             oldx=xx
             oldy=yy
          End iF
      Next
      Redraw
      WaitKey
      Cls 0,0,0
      flag = flag xor 1
Wend
Quit
Title: Re: Sdl Update
Post by: Peter on September 29, 2015, 10:13:50 PM
Hi,
Sdl Example 18: Some Alpha Bars.
Code: [Select]
include "sdl.inc"
window 640,480,1
LoadFont 1,"sdlfonts/freemono.ttf",36
sys yr,yg=40,yb=80

sub RedCopper(sys y)
for i=64 to 255 step 10
    color i,0,0,140
    drawline 0,y,639,y
    y = y+1
next   
for i=255 to 64 step -10
    color i,0,0,140
    drawline 0,y,639,y
    y = y+1
next
end sub

sub GreenCopper(sys y)
for i=64 to 255 step 10
    color 0,i,0,140
    drawline 0,y,639,y
    y = y+1
next   
for i=255 to 64 step -10
    color 0,i,0,140
    drawline 0,y,639,y
    y = y+1
next
end sub

sub BlueCopper(sys y)
for i=64 to 255 step 10
    color 0,i,i,140
    drawline 0,y,639,y
    y = y+1
next   
for i=255 to 64 step -10
    color 0,i,i,140
    drawline 0,y,639,y
    y = y+1
next
end sub

while key(27)=0
for i=0 to 240
    color i+15,0,0,255
    drawline 0,i,640,i
    color 255-i,0,0,255
    drawline 0,i+240,640,i+240
Next
color 255,255,255,255
textcolor 255,255,255
text "BARS",296,200,1
RedCopper   yr
GreenCopper yg
BlueCopper  yb

yr = yr+1
yg = yg-1
yb = yb+1
if yr >=480 then yr=-64
if yg <=-64 then yg=480
if yb >=480 then yb=-64

redraw
wait 5
wend
winExit

[attachment deleted by admin]
Title: Re: Sdl Update
Post by: Haim on September 29, 2015, 11:01:06 PM
Thank you Peter,
Very nice!
Title: Re: Sdl Update
Post by: Peter on September 30, 2015, 06:04:46 AM
Thanks Haim.

Sdl Example 19: Fir Tree.
Code: [Select]
include "sdl.inc"
Window 440,460,1
loadfont 1,"sdlfonts/font5.ttf",40
cls 235,235,245

float rs, frad, xsh
int left, top, width, height, bpx=220, bpy=410, tpx, tpy
int x1, y1, x2, y2, ht, xs, aa, m=-100, tpxx, tpyy, bpxx, bpyy
tpx = bpx
color 130,100,0,255

for aa=-4 to 4
bpxx=bpx+aa
bpyy=bpy-390
drawline bpxx, bpy, bpx, bpyy
next
 
ra = 160
tpy = bpy-40
color 88,35,35,128
fillellipse 220,405,100,20
color 30,120,40,255

for ht=1 to 40
for xs=m to 100 step 40
xsh=xs/100 
rs = rand(0,3)/10
tpxx = tpx+(xsh*ra)
tpyy = tpy-rs*ra
drawline tpx, tpy, tpxx, tpyy
for aa=1 to 30
frad=rand(0,9)/10*ra
x1=tpx+(xsh*frad)
y1=tpy-rs*frad
x2=tpx+xsh*(frad+ra/5)
y2=tpy-rs*frad+(-rs+(rand(0,8)/10-0.4))*(ra/5)
drawline x1, y1, x2, y2
next
next
ra=ra-4
tpy=tpy-9
next
textcolor 0,0,255
text "Fir Tree",150,420,1
waitkey
winExit

[attachment deleted by admin]
Title: Re: Sdl Update
Post by: Aurel on September 30, 2015, 06:41:17 AM
hi Peter
i am wondering what is freakin sdl advantage over win api ?
Title: Re: Sdl Update
Post by: Peter on September 30, 2015, 07:33:55 AM
Quote
i am wondering what is freakin sdl advantage over win api ?

Hi Aurel,
is faster! 
Title: Re: Sdl Update
Post by: JRS on September 30, 2015, 02:50:17 PM
That should be enough to give Aurel a coronary.  :)
Title: Re: Sdl Update
Post by: Peter on September 30, 2015, 04:05:03 PM
Quote
That should be enough to give Aurel a coronary
  ;D

Hi John.
Title: Re: Sdl Update
Post by: Mike Lobanovsky on September 30, 2015, 08:09:28 PM
SDL is not faster than carefully chosen Windows DIB section APIs whereby pixel modifications are written directly into the DIB section's pixel data, rather than modifying the window canvas by brute force with the turtle slow SetPixel() API.

[UPD] Examining sdl.dll in a PE explorer, you can notice that SDL imports those DIB section APIs from the Gdi32.dll system library, i.e. its strategy in its MS Windows implementation is built around the DIB functionality I'm talking about. Which means there's nothing that prevents you from doing the exact same things directly in your O2 scripts thus sparing you over 400KB of SDL libraries' footprint both in memory and on your hard disk, and all the overhead of thousands of calls to SDL proxy functions in each frame that you draw on your screen.
Title: Re: Sdl Update
Post by: Aurel on September 30, 2015, 08:15:19 PM
Thanks Mike.  ;)

John is hi....ooooo he use pipe again  :o
ooooo no  ;D
Title: Re: Sdl Update
Post by: JRS on September 30, 2015, 08:27:22 PM
Quote
John is hi....ooooo he use pipe again

Nothing like that free Linux gold to mellow you out.  :-*
Title: Re: Sdl Update
Post by: Peter on October 01, 2015, 05:20:48 AM
Hi Mike.
Title: Re: Sdl Update
Post by: Mike Lobanovsky on October 01, 2015, 05:41:22 AM
Hi Peter. Hope you're doing well.
Title: Re: Sdl Update
Post by: JRS on October 02, 2015, 12:28:31 AM
If you guys are bored, I've kicked off the Script Ledger (http://www.scriptledger.org/forum) forum which is targeted towards scripting VBA and Script BASIC and Microsoft Office (Excel mostly) for accounting folks. Join us if you like.
Title: Re: Sdl Update
Post by: Peter on October 02, 2015, 02:01:31 AM
Hi,
Sdl Example20: Binary World.  :P
Code: [Select]
include "sdl.inc"
window 640,480,1
loadfont 1,"sdlfonts/digitmono.ttf",12

float i
while key(27)=0
cls 0,0,0
color 0,0,255,255
fillcircle 300,250,208
for i=0 to 360
    textcolor rand(128,255),rand(128,255),rand(128,255)
    text "O", 300+sin(i)*Rand(10,200),240+cos(i)*Rand(10,200),1
    text "1", 300+sin(i)*Rand(10,200),240+cos(i)*Rand(10,200),1
next
color 255,255,255,255
drawcircle 300,250,208
text "BINARY WORLD",250,8,1
redraw
setfps 4
wend   




[attachment deleted by admin]