Oxygen Basic
Programming => Example Code => Topic started by: Aaron on March 10, 2014, 08:32:11 AM
-
Hi,
A Sdl check:
include "ss.inc"
OpenWindow 640,500,1
single a, b, c, d, e, f, newx, newy, t1, t2
sys r, w
Dim xy(2) as single
Sub Fern
r = Rnd(0,100)
iF r <= 10
a = 0
b = 0
c = 0
d = 0.16
e = 0
f = 0
ElseiF r > 1 and r <=86
a = 0.85
b = 0.04
c = -.04
d = 0.85
e = 0
f = 1.60
ElseiF r > 86 and r <=93
a = 0.2
b = -.26
c = 0.23
d = 0.22
e = 0
f = 0.16
Else
a = -.15
b = 0.28
c = 0.26
d = 0.24
e = 0
f = 0.44
End iF
newx = ((a * xy(1)) + (b * xy(2)) + e)
newy = ((c * xy(1)) + (d * xy(2)) + f)
xy(1) = newx
xy(2) = newy
Color(0,120,55,200)
SetPixel xy(1)*40+275,-xy(2)*40+450
End Sub
Cls 255,255,255
t1 = ticks
For w=0, 500000
Fern
Next
Redraw
t2 = ticks
t2 = (t2-t1)/1000
Color 0,0,0,255
DrawString 10,480,"Fern Points: " + str(w-1) + " Time: " + t2 + " secs"
WaitKey
CloseWindow
.
-
Im happy to report your latest SDL fern example ran fine under Wine.
.
-
Hi John,
Take your time and check this function:
SDL_Surface *surface
Function GetPixel(int x,y) as sys
sys pixel
pixel = surface.pixels
Return pixel[ (y * surface.w) + x]
End Function
I personally had no success, I only got wrong values here.
-
Hi,
A small primitive check.
include "ss.inc"
OpenWindow 320,240,1
h = GetHeight()/2
w = GetWidth ()/2
string prv[20] = {"DrawPoint","DrawCircle","FillCircle","DrawEllipse","FillEllipse","DrawRect","FillRect","DrawLine","ThickLine","DrawRoundRect","FillRoundRect"}
Color 255,255,255,255
DrawString 100, 0,"PRIMITIVE TEST"
DrawString 100,12," HIT A KEY"
WaitKey
Color 255,235,78,255
DrawString 100,50,prv[1]
DrawPoint w,h,2
WaitKey
Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[2]
DrawCircle w,h,40
WaitKey
Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[3]
FillCircle w,h,40
WaitKey
Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[4]
DrawEllipse w,h,40,20
WaitKey
Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[5]
FillEllipse w,h,40,20
WaitKey
Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[6]
DrawRect w,h,40,40
WaitKey
Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[7]
FillRect w,h,40,40
WaitKey
Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[8]
DrawLine w,h,w+40,h
DrawLine w,h,w-40,h
WaitKey
Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[9]
ThickLine w,h,w+40,h,4
ThickLine w,h,w-40,h,4
WaitKey
Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[10]
DrawRoundRect w,h,40,40,12
WaitKey
Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[11]
FillRoundRect w,h,40,40,6
WaitKey
Color 255,0,0,255
DrawString 95,h+60,"ARE YOU SURE?"
WaitKey
CloseWindow
-
Peter,
I'm only able to return the RRGGBB value from the main surface. To get the alpha value of a pixel, I had to create a new surface first and blit it to the main. Check out the gfx_GetPixel function in the Script BASIC GFX extension module source (https://bitbucket.org/ScriptBasic/c-basic/src/9334714f1599f7d748d2fa54021af20e415710c7/SBext/SDL_gfx/interface.c?at=master). Ignore the gfx_GetPixelRGBA function as it was a work in process that didn't pan out and I forgot to remove it before uploading to Bitbucket.
John
-
Hello,
Bounce with Vroby's SdlBasic.
The source code is into the bounce.exe.
It is slower than RubenDev. ;D
.
-
Peter,
I downloaded SDL BASIC but couldn't make much of the source. I couldn't find the source to the bounce demo anywhere. It's done in C++ which I have no interest in at the moment. I hope I made myself clear that I have no problems creating graphics on the main surface with the alpha attribute, I just can't find a way to retrieve the alpha value from a pixel on the main surface. The trick seems to be to initialize the format mask for alpha channel (seems to have been missed) but there is no SDL call I can find to do that after the surface has already been created.
John
-
I couldn't find the source to the bounce demo anywhere.
LOL!
Open the bounce.exe in an editor, (Notepad ) or another.
-
I am depressed, ;D
GetPixel is a dilemma, still no success with an alpha pixel.
I will change the strategy.
-
I plucked the code out of the EXE as you suggest. (PITA - why didn't you post the code?)
autoback(-2)
Function Rand(minZahl,maxZahl)
Dim result
maxZahl= (maxZahl-minZahl)+2
result = rnd(maxZahl)+minZahl
Return result-1
End Function
common cx[100],cy[100],cd[100],cr[100],cs[100]
common cr[100],cg[100],cb[100],ca[100]
For c=1 to 100
cx[c]=310
cy[c]=230
cd[c]=Rand(1,8)
cs[c]=Rand(20,30)
cr[c]=Rand(64,255)
cg[c]=Rand(64,255)
cb[c]=Rand(64,255)
ca[c]=Rand(64,255)
Next
Sub Circles()
For m=1 to 100
ink(Rgb(cr[m],cg[m],cb[m]))
FillCircle(cx[m],cy[m],cs[m])
Next
End Sub
Sub Bound()
For x=1 to 100
if cx[x] <=10 then
cd[x] = Rand(1,9)
cx[x] =10
end if
if cx[x] >=620 then
cd[x] = Rand(1,9)
cx[x] =620
end if
if cy[x] >=460 then
cd[x] = Rand(1,9)
cy[x] =460
end if
if cy[x] <=10 then
cd[x] = Rand(1,9)
cy[x] =10
end if
Next
End Sub
while Key(27)=0
paper(0)
cls()
for c=1 to 100
if cd[c]=1 then
cx[c]=cx[c]+1
Bound()
elseif cd[c]=2 then
cx[c]=cx[c]-1
Bound()
elseif cd[c]=3 then
cy[c]=cy[c]-1
Bound()
elseif cd[c]=4 then
cy[c]=cy[c]+1
Bound()
elseif cd[c]=5 then
cy[c]=cy[c]-1
cx[c]=cx[c]-1
Bound()
elseif cd[c]=6 then
cy[c]=cy[c]-1
cx[c]=cx[c]+1
Bound()
elseif cd[c]=7 then
cy[c]=cy[c]+1
cx[c]=cx[c]-1
Bound()
elseif cd[c]=8 then
cy[c]=cy[c]+1
cx[c]=cx[c]+1
Bound()
end if
Next
Circles()
screenswap
wend
-
Hi Peter
Where you see source code for bounce ???
There is just a exe file , i know that is source binded to the runtime but i dont know how to extract
source from this file .
Anyway when you say it is slower than RubenDev ...well it is very slow.
Peter do you have maybe ordinary fern example in SDLBasic that i can see how work?
-
Hi Aurel,
Yes, but I must search.
-
(PITA - why didn't you post the code?)
Too much work. ;D
-
I step in that trap often trying to make you look good. :o :-*
-
Peter do you have maybe ordinary fern example in SDLBasic that i can see how work?
Hi Aurel,
here is it,
SetDisplay(640, 500, 32, 1)
Function Rand(minZahl,maxZahl)
Dim result
maxZahl= (maxZahl-minZahl)+2
result = rnd(maxZahl)+minZahl
Return result-1
End Function
common a=0, b=0, c=0, d=0, e=0, f=0, newx=0, newy=0, r=0, wa=0
Dim xy[2]
Sub Fern
r = Rand(0,100)
iF r <= 10 then
a = 0
b = 0
c = 0
d = 0.16
e = 0
f = 0
ElseiF r > 1 and r <=86 then
a = 0.85
b = 0.04
c = -.04
d = 0.85
e = 0
f = 1.60
ElseiF r > 86 and r <=93 then
a = 0.2
b = -.26
c = 0.23
d = 0.22
e = 0
f = 0.16
Else
a = -.15
b = 0.28
c = 0.26
d = 0.24
e = 0
f = 0.44
End iF
newx = ((a * xy[1]) + (b * xy[2]) + e)
newy = ((c * xy[1]) + (d * xy[2]) + f)
xy[1] = newx
xy[2] = newy
ink(0x00D237)
SetPixel(xy[1]*40+275,xy[2]*40+50)
End Sub
ink(0x1C1C1C)
Cls()
for wa=0 to 100000
Fern
next
screenswap()
SetCaption("Fern Points: " & str(wa))
WaitKey(27)
-
Thank you Peter but i don't get it what is wrong with this freakin SDL basic
i simply can't run program fern ..
look into screenshot...
.
-
Hi Aurel,
Save fern.sdlbas only in C:\SdlBasic.
Open the editor and click on "open". Load now "c:\sdlbasic\fern.sdlbas".
After that, click on the green arrow.
-
thanks ..
so must be on C....oh ::)