Oxygen Basic
Programming => Example Code => Topic started by: Aaron on March 06, 2014, 07:01:59 AM
-
Hello,
It is true, Gdiplus is slow.
Here is a star field what actually should run with 64 frames.
I only got 32 frames, and my computer is not lame.
It is the same like OpenGl, much work and as prize snails tempo.
include "gp.inc"
OpenWindow 800,600,1
sys xstar[500]
sys ystar[500]
sys speed[500]
sys xres=800, yres=600, i, fz
single v
For i=1, 500
xstar[i] = Rnd(1,xRes-2)
ystar[i] = Rnd(1,yRes-2)
speed[i] = Rnd(1,4)
Next
phx = LoadImage "png/phoenix.png",10
while KeyDown(27)=0
SetCaption "Frames " + GetFps
clsColor ARGB(100,0,0,0)
DrawImage phx,350,250,fz
For i=1, 500
DrawPoint xstar[i],ystar[i],2, ARGB(255,Rnd(64,255),255,255)
xstar[i] += speed[i]
if xstar[i] > xRes then
xstar[i] = 0
ystar[i] = Rnd(1, yRes-2)
speed[i] = Rnd(1, 4)
end if
Next
v +=.2
if v >=1
v=0
fz +=1
if fz=10 then fz=0
end if
Sync
wend
CloseWindow
.
-
Alpha Circles.
Something like ScriptBasic.
include "gp.inc"
OpenWindow 640, 480 ,1
SetSmoothMode 2
sys rx[512],ry[512],rz[512]
sys rr[512],rg[512],rb[512],ra[512]
clscolor ARGB(255,0,0,0)
For i=1, 512
rx[i] = Rnd(0, 600)
ry[i] = Rnd(0, 440)
rz[i] = Rnd(4, 64)
rr[i] = Rnd(32,255)
rg[i] = Rnd(32,255)
rb[i] = Rnd(32,255)
ra[i] = Rnd(25,240)
Next
For i=1, 512
FillCircle rx[i], ry[i], rz[i], ARGB(ra[i], rr[i], rg[i], rb[i])
Next
WaitKey
CloseWindow
-
Some of those smaller circles look like squares. :o
(http://files.allbasic.info/O2/o2gdiwine_alpha_circles.png)
-
Some of those smaller circles look like squares.
LOL, but not here! ;D
.
-
I copied the GDI & GdiPlus DLL's from XP to Wine but it didn't make a difference. Here is my XP version which looks great. I'm not going to be testing any more of your GDI based examples under Wine going forward.
(http://files.allbasic.info/O2/xpalphacircles.png)
-
Include "gp.inc"
OpenWindow 640,480,1
font = LoadFont "verdana",16,1
clscolor ARGB(255,0,0,0)
image = LoadImage "png/rip-basic.png",1
DrawImage image,40,100,0
RotateFlipImage image,350,100,4
DrawText font,200,0,"Rip Gdiplus Image Test", ARGB(255,255,255,255)
WaitKey
CloseWindow
.
-
Once again: Gdiplus Fern.
include "gp.inc"
OpenWindow 640,500,1
SetSmoothMode 2
single a, b, c, d, e, f, newx, newy
single xy[2]
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
SetPixel xy[1]*40+275,xy[2]*40+50, ARGB(255,0,210,55)
End Sub
ClsColor ARGB(255,8,8,8)
Redraw
For w=1 to 100000
Fern
Next
SetCaption "Fern Points: " + w-1
WaitKey
CloseWindow
.
-
Great stuff Peter!
(http://files.allbasic.info/O2/o2wine_fern.png)
FYI The BBC origin coordinates are reversed and your examples will be upside down using the BBC examples.
Can you convert the graph demo from a BBC plot / scaled example to GDI?
-
To John...
I see that you trying to set alpha chanel in your SDL adventure ...did you
look here..
http://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlsetalpha.html
#include "SDL.h"
int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha);
and it looks to me that you then need to blit changes ...
i just guessing.... ::)
-
As mention earlier in this thread (http://www.oxygenbasic.org/forum/index.php?topic=993.msg8373#msg8373), the SDL_SetAlpha has no effect trying to return an alpha value on the initial surface.
interface.c (SDL window create function)
videoflags = SDL_SWSURFACE | SDL_SRCALPHA | SDL_RESIZABLE | SDL_DOUBLEBUF;
IF ((screen = SDL_SetVideoMode(width,height,video_bpp,videoflags)) EQ NULL ) THEN
PRINT_FILE (stderr, "Couldn't set %ix%i %i bpp video mode: %s\n",width,height,video_bpp,SDL_GetError());
exit(2);
END_IF
SDL_SetAlpha(screen, SDL_SRCALPHA, 0);
-
I was able to get Peter's converted BBC fern example working with ScriptBasic GFX.
FWIW: The problem I had initially was I was sending floating point values to the X/Y arguments of gfx::PixelRGBA. INTs resolved the issue.
(http://files.allbasic.info/ScriptBasic/gfx/sbgfxu64_fern_inverted.png)
' ScriptBasic GFX - Fern
IMPORT gfx.inc
s = gfx::Window(640,500,"ScriptBasic GFX Fern")
RANDOMIZE(gfx::Time())
SPLITA STRING(3,"0") BY "" TO xy
SUB Fern
r = RND() % 100
IF r <= 10 THEN
a = 0
b = 0
c = 0
d = 0.16
e = 0
f = 0
ELSE IF r > 1 AND r <=86 THEN
a = 0.85
b = 0.04
c = -.04
d = 0.85
e = 0
f = 1.60
ELSE IF 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
gfx::pixelRGBA s, INT(xy[1]*40+275), INT(xy[2]*40+50), 0, 210, 55, 255
END SUB
ts = gfx::Time()
FOR w=1 TO 100000
Fern
NEXT
te = gfx::Time()
gfx::stringColor s, 20, 15, "Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0xffffffff
gfx::Update
WHILE gfx::KeyName(1) <> "+escape"
WEND
gfx::Close
Here is a screen shot of the fern example running under the ScriptBasic BBC extension module. This disproves David & Richard's theory that SDL is too slow to use. My guess is that trying to emulate hardware from the early 80s and promoting the limitations as nostalgic features comes with a price.
(http://files.allbasic.info/ScriptBasic/SDL/sbbbc_fern.png)
-
Amazing Fractal. You can also tweak the params to get different plant species :)