peter
19-04-2013, 19:56
Hi Eros,
Here is a Sdl Library for ThinBasic. Would be nice, if it runs with you.
It isn't finish yet, but some small works are possible.
As ever, no problems here with my computer, anything runs fine.
Demo1:
#INCLUDE "sdl.inc"
LoadWinIcon "img/acorn.bmp"
Screen 640,480,1
SetCaption "Hello Banana"
Long x, fnt, toy
Fnt = LoadFont "sdlfonts/choco.ttf",48
toy = LoadImage "img/toy.gif",1
While KEY(27)=0
ClsColor xRgb 0,0,255
SetText fnt,20,0,"Hello, my name is Peter.",xRgb(255,255,255)
Sprite toy,200,100,0
For x=0 To 639 Step 10
SetPoint x,400,4,6, Rgb(0,255,0)
Next
Rectangle 200,420,80,40,4,xRGB(255,200,0)
FillRect 300,420,80,40, xRGB(155,100,255)
Ellipse 440,440,40,20,4,xRGB(255,10,25)
Ellipse 520,440,20,20,2,xRGB(255,110,85)
DrawLine 0,64,639,64,2, xRGB(200,20,255)
Sync
Wend
Quit
Demo2:
#INCLUDE "sdl.inc"
Screen 320,240,1
SetCaption "FORMAT TEST"
Long zx, zy, bild, tizzi, angel, stars
bild = LoadImage "img/bild.jpg",1
tizzi= LoadImage "img/tizzi.png",1
angel= LoadImage "img/angel.bmp",1
stars= LoadTiles "img/star.tga",16,2
While Key(27)=0
Sprite bild,0,0,0
Sprite tizzi,32,0,0
Sprite angel,32,0,0
Tiles stars,0,0,zx,zy
Tiles stars,280,200,zx,zy
Sync()
zx +=1
If zx=16 Then
zx=0
zy +=1
If zy=2 Then zy=0
End If
Wend
Quit()
Demo3:
#INCLUDE "sdl.inc"
Screen 400,300,1
SetCaption "MANDEL DRAGON"
Double cRe,cIm,re,im,oldRe,oldIm,zoom,mx,my
Long maxIt,x,y,i,a,w,h,fnt
fnt = LoadFont "sdlfonts/font1.ttf",32
SetText fnt,100,100,"WAIT......", xRGB 255,255,255
Flip
maxIt= 255
zoom = 1
cRe = -0.7
cIm = 0.27015
w = GetWidth
h = GetHeight
For x=0 To w
For y=0 To h
re = 1.5 * (x-w*.5) / (.5*zoom*w) + mx
im = (y-h*.5) / (.5*zoom*h) + my
For i=0 To maxIt
oldRe = re
oldIm = im
re = oldRe * oldRe - oldIm * oldIm +cRe
im = 2 * oldRe * oldIm + cIm
If((re * re + im * im) >5) Then Exit For
Next
SetPoint x, y, 1,1, xRGB(i*7,i*8,i*4)
Next
Next
KeyWait()
Quit
Demo4:
#INCLUDE "sdl.inc"
Screen 400,400,1
SetCaption "MoonPlasma"
Long m1,m2,m4,m11,m22,y,x,r,g,b
For y=0 To 399
m11= m11+1
m1 = m1 +9
m2 = m1
m22= m11
For x=0 To 399
m4 = m4 +19
m2 = m2 +15
m22= m22+1
r = Abs(Sin(m1/100)+Sin(m2/100)+Sin((m1+m4)/600))*(255/3)
g = Abs(Sin((m22)/50) + Sin(m11/100))*250
b = Abs(Sin(x*y/100000)*200)
Setpoint x,y, 1,1,xRgb(r,g,b)
Next
Next
KeyWait
Quit
Demo5:
#INCLUDE "sdl.inc"
Single Pii= 3.141592654
Screen 640,480,1
SetCaption "Sierpinski Snowflake"
Function degrees(radians As Long) As Long
Return radians * Pii/180
End Function
Single x, y, c, r2, r3, a, x0, y0, u, v
Long ex, sx, sy, i
x=1 : y=0 : c=0.5 / Sqr(3) : r2= Sqr(3) /2 : r3= Sqr(3) /6 : ex=400 : sx=240 : sy=125
ClsColor xRGB(100,60,240)
For i=0 To 35000
a = Sin(degrees(Rand(0,45)))
If a > 0.5 Then
x0 = (0.5 * x) + (r3 * y)
y0 = (r3 * x) - (0.5 * y)
Else
x0 = (0.5 * x) - (r3 * y) + 0.5
y0 = (-r3 * x) - (0.5 * y) + r3
End If
x=x0
y=y0
SetPoint(x * (ex + sx), sy - (y * ex),4,2, Rgb 255,255,255)
u = (0.5 * x) - (r2 * y)
v = (-r2 * x) - (0.5 * y)
SetPoint(u * (ex + sx), sy - (v * ex),4,2, Rgb 250,250,250)
u = (-0.5 * x) + (r2 * y) + 1
v = (-r2 * x) - (0.5 * y)
SetPoint(u * (ex + sx), sy - (v * ex),4,2, Rgb 245,245,245)
Next
KeyWait
Quit
Demo6:
#INCLUDE "sdl.inc"
Screen 680,512,1
SetCaption "SNAKE"
Long px, j, tree, ball, weed
Dim x(10) As Long
Dim y(10) As Long
Dim d(10) As Long
tree = LoadImage("snake/tree.bmp",1)
ball = LoadImage("snake/ball.bmp",1)
weed = LoadImage("snake/weed.bmp",1)
For j=1 To 10
x(j) = j*32
y(j) = 0
d(j) = 1
Next
px=32
While Key(27)=0
ClsColor (0)
For j=1 To 10
Sprite ball,x(j),y(j),0
Next
For j=1 To 10
If d(j)=1 Then
If x(j) >0 Then
x(j) = x(j) -1
Else
d(j) =2
End If
End If
Next
For j=1 To 10
If d(j)=2 Then
If y(j) <480-32 Then
y(j) = y(j) +1
Else
d(j)=3
End If
End If
Next
For j=1 To 10
If d(j)=3 Then
If x(j) <640-32 Then
x(j) = x(j) +1
Else
d(j)=4
End If
End If
Next
For j=1 To 10
If d(j)=4 Then
If y(j) >0 Then
y(j) = y(j) -1
Else
d(j)=1
End If
End If
Next
Sprite tree,200,232,0
Sprite weed,0,464,0
Flip
SetFps (260)
Wend
Quit
Here is a Sdl Library for ThinBasic. Would be nice, if it runs with you.
It isn't finish yet, but some small works are possible.
As ever, no problems here with my computer, anything runs fine.
Demo1:
#INCLUDE "sdl.inc"
LoadWinIcon "img/acorn.bmp"
Screen 640,480,1
SetCaption "Hello Banana"
Long x, fnt, toy
Fnt = LoadFont "sdlfonts/choco.ttf",48
toy = LoadImage "img/toy.gif",1
While KEY(27)=0
ClsColor xRgb 0,0,255
SetText fnt,20,0,"Hello, my name is Peter.",xRgb(255,255,255)
Sprite toy,200,100,0
For x=0 To 639 Step 10
SetPoint x,400,4,6, Rgb(0,255,0)
Next
Rectangle 200,420,80,40,4,xRGB(255,200,0)
FillRect 300,420,80,40, xRGB(155,100,255)
Ellipse 440,440,40,20,4,xRGB(255,10,25)
Ellipse 520,440,20,20,2,xRGB(255,110,85)
DrawLine 0,64,639,64,2, xRGB(200,20,255)
Sync
Wend
Quit
Demo2:
#INCLUDE "sdl.inc"
Screen 320,240,1
SetCaption "FORMAT TEST"
Long zx, zy, bild, tizzi, angel, stars
bild = LoadImage "img/bild.jpg",1
tizzi= LoadImage "img/tizzi.png",1
angel= LoadImage "img/angel.bmp",1
stars= LoadTiles "img/star.tga",16,2
While Key(27)=0
Sprite bild,0,0,0
Sprite tizzi,32,0,0
Sprite angel,32,0,0
Tiles stars,0,0,zx,zy
Tiles stars,280,200,zx,zy
Sync()
zx +=1
If zx=16 Then
zx=0
zy +=1
If zy=2 Then zy=0
End If
Wend
Quit()
Demo3:
#INCLUDE "sdl.inc"
Screen 400,300,1
SetCaption "MANDEL DRAGON"
Double cRe,cIm,re,im,oldRe,oldIm,zoom,mx,my
Long maxIt,x,y,i,a,w,h,fnt
fnt = LoadFont "sdlfonts/font1.ttf",32
SetText fnt,100,100,"WAIT......", xRGB 255,255,255
Flip
maxIt= 255
zoom = 1
cRe = -0.7
cIm = 0.27015
w = GetWidth
h = GetHeight
For x=0 To w
For y=0 To h
re = 1.5 * (x-w*.5) / (.5*zoom*w) + mx
im = (y-h*.5) / (.5*zoom*h) + my
For i=0 To maxIt
oldRe = re
oldIm = im
re = oldRe * oldRe - oldIm * oldIm +cRe
im = 2 * oldRe * oldIm + cIm
If((re * re + im * im) >5) Then Exit For
Next
SetPoint x, y, 1,1, xRGB(i*7,i*8,i*4)
Next
Next
KeyWait()
Quit
Demo4:
#INCLUDE "sdl.inc"
Screen 400,400,1
SetCaption "MoonPlasma"
Long m1,m2,m4,m11,m22,y,x,r,g,b
For y=0 To 399
m11= m11+1
m1 = m1 +9
m2 = m1
m22= m11
For x=0 To 399
m4 = m4 +19
m2 = m2 +15
m22= m22+1
r = Abs(Sin(m1/100)+Sin(m2/100)+Sin((m1+m4)/600))*(255/3)
g = Abs(Sin((m22)/50) + Sin(m11/100))*250
b = Abs(Sin(x*y/100000)*200)
Setpoint x,y, 1,1,xRgb(r,g,b)
Next
Next
KeyWait
Quit
Demo5:
#INCLUDE "sdl.inc"
Single Pii= 3.141592654
Screen 640,480,1
SetCaption "Sierpinski Snowflake"
Function degrees(radians As Long) As Long
Return radians * Pii/180
End Function
Single x, y, c, r2, r3, a, x0, y0, u, v
Long ex, sx, sy, i
x=1 : y=0 : c=0.5 / Sqr(3) : r2= Sqr(3) /2 : r3= Sqr(3) /6 : ex=400 : sx=240 : sy=125
ClsColor xRGB(100,60,240)
For i=0 To 35000
a = Sin(degrees(Rand(0,45)))
If a > 0.5 Then
x0 = (0.5 * x) + (r3 * y)
y0 = (r3 * x) - (0.5 * y)
Else
x0 = (0.5 * x) - (r3 * y) + 0.5
y0 = (-r3 * x) - (0.5 * y) + r3
End If
x=x0
y=y0
SetPoint(x * (ex + sx), sy - (y * ex),4,2, Rgb 255,255,255)
u = (0.5 * x) - (r2 * y)
v = (-r2 * x) - (0.5 * y)
SetPoint(u * (ex + sx), sy - (v * ex),4,2, Rgb 250,250,250)
u = (-0.5 * x) + (r2 * y) + 1
v = (-r2 * x) - (0.5 * y)
SetPoint(u * (ex + sx), sy - (v * ex),4,2, Rgb 245,245,245)
Next
KeyWait
Quit
Demo6:
#INCLUDE "sdl.inc"
Screen 680,512,1
SetCaption "SNAKE"
Long px, j, tree, ball, weed
Dim x(10) As Long
Dim y(10) As Long
Dim d(10) As Long
tree = LoadImage("snake/tree.bmp",1)
ball = LoadImage("snake/ball.bmp",1)
weed = LoadImage("snake/weed.bmp",1)
For j=1 To 10
x(j) = j*32
y(j) = 0
d(j) = 1
Next
px=32
While Key(27)=0
ClsColor (0)
For j=1 To 10
Sprite ball,x(j),y(j),0
Next
For j=1 To 10
If d(j)=1 Then
If x(j) >0 Then
x(j) = x(j) -1
Else
d(j) =2
End If
End If
Next
For j=1 To 10
If d(j)=2 Then
If y(j) <480-32 Then
y(j) = y(j) +1
Else
d(j)=3
End If
End If
Next
For j=1 To 10
If d(j)=3 Then
If x(j) <640-32 Then
x(j) = x(j) +1
Else
d(j)=4
End If
End If
Next
For j=1 To 10
If d(j)=4 Then
If y(j) >0 Then
y(j) = y(j) -1
Else
d(j)=1
End If
End If
Next
Sprite tree,200,232,0
Sprite weed,0,464,0
Flip
SetFps (260)
Wend
Quit