Oxygen Basic

Information => Open Forum => Topic started by: JRS on April 14, 2013, 07:09:47 PM

Title: SW QB compatibility
Post by: JRS on April 14, 2013, 07:09:47 PM
Peter,

I noticed THIS (http://forum.basicprogramming.org/index.php/topic,2859.0.html) example on the Basic Programming forum. I'm just getting started with graphics programming and wondered if Simple Window could emulate some of the simple QB graphic examples I see floating around?

Would this example take too much of your time to convert to O2?

John
Title: Re: SW QB compatibility
Post by: Peter on April 15, 2013, 01:18:57 AM
Hi John,

Quote
Missing variable declares: sc w5
Quote
Missing + operator LoadBytes("maps/map" + m "-1.txt",map1)

You are really my mirror.
If I missing some Variables then complains not the Oxygen Compiler.  
On the other side, OxygenBasic does it for me!

But I'm lucky, it's running.

About this QB thing,  I will see whether it is doable.
Title: Re: SW QB compatibility
Post by: Peter on April 15, 2013, 02:42:17 AM
Hi John,

One must be seemingly dead, for a translation QB64  >  OxygenBasic.
But I am alive!  I will do it when I am  got a Zombie programmer later.
Title: Re: SW QB compatibility
Post by: Charles Pegge on April 15, 2013, 04:03:05 AM
The most ancient of Basics is supported: :)

Code: OxygenBasic
  1. 10 i=0
  2. 20 i=i+1 : if i>2 then goto 40
  3. 30 gosub 50 : goto 20
  4. 40 end
  5. 50 print i
  6. 60 ret
  7.  

which leads me to the idea that a program terminator switch would be very useful when testing and debugging programs (supporting Ctrl-C to end an infinite loop)

Charles
Title: Re: SW QB compatibility
Post by: Peter on April 15, 2013, 04:08:27 AM
Hi John,

I got this here, I don't know what is it doing.
There was a LINE command, which had too much parameter, I killed two of them!  Apparently the wrong parameter.  :D
Code: [Select]
include "sw.inc"
Window 640,480,1

'PI= 4 * ATN (1)
sys pas=1,col=12,r=65,con,z=10
sys a,w,k,m,n,j,x,r,x1,y,y1,py,px,x2,y2
dim PUN(29040)

Sub ESCALON
    a=j*2+1
    LINE PUN(a)-30, PUN(a), PUN(a), PUN(a), 1, RGB(255,255,255)
    LINE PUN(a), PUN(a), PUN(a), PUN(a)-21, 1, RGB(255,255,255)
    CIRCLE PUN(a),PUN(a),(pi*2*222)/360, 1,RGB(255,255,0)
    CIRCLE PUN(a)-8,PUN(a)-3,3, 1, RGB(25,255,0)
    CIRCLE PUN(a)-18,PUN(a)-13,3,1,RGB(25,255,0)
End Sub

Sub ALMACENAR
    CON = CON + 1
    a=con*2+1
    PUN(a) = PX
    PUN(a+1) = PY
End Sub

Sub PUNTOS
    sys g
    g = (N*2*PI)/360
    X = COS (g) * R
    Y = SIN (g) * R
End Sub

Sub LINEA_PUNTOS2
    sys dx,dy,hip,ang
    DX = ABS (X1 - X2) :DY = ABS (Y1 - Y2) :HIP = SQR (ABS((DX^2)+(DY^2))):ANG = ATN (DY / DX)
    FOR N = 0 TO HIP STEP PAS
    Y = SIN (ANG) * N:X = COS (ANG) * N
    IF X1 < X2 AND Y1 < Y2 THEN PX = X + X1 :PY = Y + Y1
    IF X1 < X2 AND Y1 > Y2 THEN PX = X + X1 :PY = Y1 - Y
    IF X1 > X2 AND Y1 < Y2 THEN PX = X + X2 :PY = Y2 - Y
    IF X1 > X2 AND Y1 > Y2 THEN PX = X1 - X :PY = Y1 - Y
    IF X1 = X2 AND Y1 < Y2 THEN PX = X + X2 :PY = Y2 - Y
    IF X1 = X2 AND Y1 > Y2 THEN PX = X + X2 :PY = Y2 + Y
    IF X1 < X2 AND Y1 = Y2 THEN PX = X2 - X :PY = Y2 + Y
    IF X1 > X2 AND Y1 = Y2 THEN PX = X2 + X :PY = Y2 + Y
    IF X1 = X2 AND Y1 = Y2 THEN PX = X1 :PY = Y1
    ALMACENAR
    NEXT
End Sub

Sub TRAYECTORIA2
FOR N = 270 TO 90 STEP - 1
    PUNTOS
    PX = X + 80
    PY = Y + 80
    ALMACENAR
NEXT
X1 = 170:Y1 = 145:X2 = 80:Y2 = 145
LINEA_PUNTOS2
FOR N = 270 TO 315
    PUNTOS
    PX = X + 170
    PY = Y + 210
    ALMACENAR
NEXT
X1 = 216:Y1 = 164:X2 = 414:Y2 = 348
LINEA_PUNTOS2
FOR N = 135 TO 90 STEP -1
    PUNTOS
    PX = X + 458
    PY = Y + 300
    ALMACENAR
NEXT
X1 = 548:Y1 = 365:X2 = 458:Y2 = 365
LINEA_PUNTOS2
'SEMICIRCULO SUPERIOR
FOR N = 450 TO 270 STEP -1
    PUNTOS
    PX = X + 548
    PY = Y + 300
    ALMACENAR
NEXT
X1 = 458:Y1 = 235:X2 = 548:Y2 = 235
LINEA_PUNTOS2
'ARCO INFERIOR SUPERIOR
FOR N = 90 TO 135
    PUNTOS
    PX = X + 458
    PY = Y + 170
    ALMACENAR
NEXT
'LINEA INCLINADA HACIA ABAJO
X1 = 414:Y1 = 218:X2 = 216:Y2 = 33
LINEA_PUNTOS2
FOR N = 315 TO 270 STEP -1
    PUNTOS
    PX = X + 170
    PY = Y + 80
    ALMACENAR
NEXT
X1 = 80:Y1 = 15:X2 = 170:Y2 = 15
LINEA_PUNTOS2
End Sub

FOR W = 1 TO 5
    TRAYECTORIA2
NEXT
FOR K = 1 TO 1452*Z
    CLS 0
    LINE 0,365,640,365,1, RGB(255,0,0)
    LINE 0,145,640,145,1, RGB(255,0,0)
    FOR M= 1 TO 1452
        a= m*2+1
        SetPixel PUN(a),PUN(a+1),RGB(0,255,0)
    NEXT
    FOR J= 1 + K TO 1452 + K  STEP 31
        ESCALON
    NEXT
    FOR W = 1 - K TO 360 - K  STEP 6
        G = (W*2*PI)/360
X = COS (G) * 63
Y = SIN (G) * 63
        CIRCLE X+ 80,Y + 80,3,1, RGB(0,255,255)
CIRCLE X+548,Y +300,3,1, RGB(0,255,255)
        CIRCLE 80, 80, 10,1,RGB(0,255,255)
CIRCLE 548,300,10,1,RGB(0,255,255)
    NEXT
Sync
NEXT

WaitKey
Quit

Code: [Select]
I have now this here.

include "sw.inc"
Window 640,480,1

sys pas=1,col=12,r=65,con,z=10
single a,w,k,m,n,j,x,r,k,g,x1,y,y1,py,px,x2,y2
dim PUN(29040)

Sub ESCALON
    a=j*2+1
    LINE PUN(a)-30, PUN(a), PUN(a), PUN(a), 1, RGB(255,255,255)
    LINE PUN(a), PUN(a), PUN(a), PUN(a)-21, 1, RGB(255,255,255)
    CIRCLE PUN(a),PUN(a),15*pi+(pi*2*222)/360, 1,RGB(255,255,0)
    CIRCLE PUN(a)-8,PUN(a)-3,3, 1, RGB(25,255,0)
    CIRCLE PUN(a)-18,PUN(a)-13,3,1,RGB(25,255,0)
End Sub

Sub ALMACENAR
    CON = CON + 1
    a=con*2+1
    PUN(a) = PX
    PUN(a+1) = PY
End Sub

Sub PUNTOS
    sys g
    g = (N*2*PI)/360
    X = COS (g) * R
    Y = SIN (g) * R
End Sub

Sub LINEA_PUNTOS2
    sys dx,dy,hip,ang
    DX = ABS (X1 - X2) :DY = ABS (Y1 - Y2) :HIP = SQR (ABS((DX^2)+(DY^2))):ANG = ATN (DY / DX)
    FOR N = 0 TO HIP STEP PAS
    Y = SIN (ANG) * N:X = COS (ANG) * N
    IF X1 < X2 AND Y1 < Y2 THEN PX = X + X1 :PY = Y + Y1
    IF X1 < X2 AND Y1 > Y2 THEN PX = X + X1 :PY = Y1 - Y
    IF X1 > X2 AND Y1 < Y2 THEN PX = X + X2 :PY = Y2 - Y
    IF X1 > X2 AND Y1 > Y2 THEN PX = X1 - X :PY = Y1 - Y
    IF X1 = X2 AND Y1 < Y2 THEN PX = X + X2 :PY = Y2 - Y
    IF X1 = X2 AND Y1 > Y2 THEN PX = X + X2 :PY = Y2 + Y
    IF X1 < X2 AND Y1 = Y2 THEN PX = X2 - X :PY = Y2 + Y
    IF X1 > X2 AND Y1 = Y2 THEN PX = X2 + X :PY = Y2 + Y
    IF X1 = X2 AND Y1 = Y2 THEN PX = X1 :PY = Y1
    ALMACENAR
    NEXT
End Sub

Sub TRAYECTORIA2
FOR N = 270 TO 90 STEP - 1
    PUNTOS
    PX = X + 80
    PY = Y + 80
    ALMACENAR
NEXT
X1 = 170:Y1 = 145:X2 = 80:Y2 = 145
LINEA_PUNTOS2
FOR N = 270 TO 315
    PUNTOS
    PX = X + 170
    PY = Y + 210
    ALMACENAR
NEXT
X1 = 216:Y1 = 164:X2 = 414:Y2 = 348
LINEA_PUNTOS2
FOR N = 135 TO 90 STEP -1
    PUNTOS
    PX = X + 458
    PY = Y + 300
    ALMACENAR
NEXT
X1 = 548:Y1 = 365:X2 = 458:Y2 = 365
LINEA_PUNTOS2
FOR N = 450 TO 270 STEP -1
    PUNTOS
    PX = X + 548
    PY = Y + 300
    ALMACENAR
NEXT
X1 = 458:Y1 = 235:X2 = 548:Y2 = 235
LINEA_PUNTOS2
FOR N = 90 TO 135
    PUNTOS
    PX = X + 458
    PY = Y + 170
    ALMACENAR
NEXT
X1 = 414:Y1 = 218:X2 = 216:Y2 = 33
LINEA_PUNTOS2
FOR N = 315 TO 270 STEP -1
    PUNTOS
    PX = X + 170
    PY = Y + 80
    ALMACENAR
NEXT
X1 = 80:Y1 = 15:X2 = 170:Y2 = 15
LINEA_PUNTOS2
End Sub

FOR W = 1 TO 5
    TRAYECTORIA2
NEXT
FOR K = 1 TO 1452*Z
    CLS 0
    LINE 0,365,640,365,1, RGB(255,0,0)
    LINE 0,145,640,145,1, RGB(255,0,0)
    'FOR M=1 TO 1452
    '    a= m*2+1
    '    SetPixel PUN(a),PUN(a+1),RGB(0,255,0)
    'NEXT
    FOR J= 1 + K TO 1452 + K  STEP 31
        ESCALON
    NEXT
    FOR W = 1 - K TO 360 - K  STEP 6
        G = (W*2*PI)/360
X = COS (G) * 63
Y = SIN (G) * 63
        CIRCLE X+ 80,Y + 80,3,1, RGB(0,255,255)
CIRCLE X+548,Y +300,3,1, RGB(0,255,255)
        CIRCLE 80, 80, 10,1,RGB(0,255,255)
CIRCLE 548,300,10,1,RGB(0,255,255)
    NEXT
Sync
NEXT

WaitKey
Quit

Title: Re: SW QB compatibility
Post by: Peter on April 15, 2013, 04:12:27 AM
Quote
The most ancient of Basics is supported:

Not true.
Where are Line, circle Pset and so on?

Charles,

You must not support ancient Basic dialects.  We have 2013 and have to be modern.
Those ancient Basic dialetcs are only for people who learn never to program.
The  syntax  hinders  they,  writing a program like Hello World.   
Title: Re: SW QB compatibility
Post by: Aurel on April 15, 2013, 05:28:34 AM
Quote
Where are Line, circle Pset and so on?
you know where... ;D

Yeah this old code is excellent for QB64  dudes :P
Title: Re: SW QB compatibility
Post by: JRS on April 15, 2013, 08:37:13 AM
Thanks Peter for your efforts with the QB compatibility for Simple Window. I agree that QB compatibility should remain in extension libraries like SW and not force modern Basic languages like O2 to service the past.

Do I need a new sw.dll / sw.inc to run these examples?

Title: Re: SW QB compatibility
Post by: Peter on April 15, 2013, 09:02:11 AM
actually not.
But here is an updated  sw

John,

I notice always that you put "SetFps" outside the main Loop.
This is wrong and has no effect.

Here is a small test program, shows you what happens.
Run it once with a inside SetFps and then with a outside SetFps.
Code: [Select]
include "sw.inc"
Window 640,480,1

sys x
'SetFps (80)

while Key(27)=0

cls (0)
Text 0,0,"FRAMES = " + GetFps, white
DrawPoint x,100,12,12, white
DrawPoint x+12,112,12,12, white
DrawPoint x,124,12,12, white

x +=1
if x>640 then x -=x

Redraw
SetFps (80)

wend
Quit

X
Title: Re: SW QB compatibility
Post by: JRS on April 15, 2013, 09:17:34 AM
Quote
I notice always that you put "SetFps" outside the main Loop.
This is wrong and has no effect.

When I converted the SokoMouse game and had SetFps() in the event loop, it used 100% of the CPU. Putting it outside the loop reduced the CPU usage to 17% with no adverse effects on the game. My assumption was that once you set the FPS rate, (never changing the value) SW shouldn't have to keep checking the rate for a change with each iteration of the loop. I thought that is what Sync was for.

Redraw is another mystery that I keep playing with from time to time to see what it does.

Title: Re: SW QB compatibility
Post by: Peter on April 15, 2013, 09:29:18 AM
Sync reduce the Cpu power and forces the program to run with 64 Frames per sec.
Redraw is for full games, takes the hole Cpu power.  You could write a wait command after Redaw ( Wait 1 ) and the Cpu power is 8% - 15%.

When a game is running in full Screen mode, why do you need lesser Cpu power?  You can't work with other windows.   
     
Title: Re: SW QB compatibility
Post by: JRS on April 15, 2013, 09:51:04 AM
Thanks for the explanation and hints.

I'll do some experimenting and try to find the right mix.

Title: Re: SW QB compatibility
Post by: Peter on April 15, 2013, 10:06:56 AM
Hi,

here is a small mosaic picture demo.
just click the left mousebutton and see what happens.
Code: [Select]
include "sw.inc"

Window 640, 480, 1

Sub BigPixel(sys x1,y1,x2,y2,w,h)
    sys x, y, r, g, b, color
    x = x1
    y = y1
    while y <= y2-h
    color = GetPixel x,y
    r = GetValueR color
    g = GetValueG color
    b = GetValueB color
    DrawPoint x, y, w, h, RGB(r,g,b)
    x = x + w
    if x >= x2 - w
       x = x1
       y = y + h
    end if
    wend   
End Sub

bild= LoadBmp "bmp/bild1.bmp",0
sys a
Text 160,100,"WAIT.....",0
Sync

DrawBmp bild,0,0,640,480,0
For a=1 to 34
    SetCaption "PIXELS ARE NOW " a + "x" + a
    DrawBmp bild,0,0,640,480,0
    BigPixel 0,0,640,480,a,a
    WaitMouse
Next

Quit

X
Title: Re: SW QB compatibility
Post by: JRS on April 15, 2013, 10:43:37 AM
(http://files.allbasic.info/O2/synctest.png)

I see that with each left click the resolution of the image changes. (like a screen MODE change in QB)

Was this the intent?

Title: Re: SW QB compatibility
Post by: Peter on April 15, 2013, 11:11:36 AM
Yes, that was it.

Is for ScriptBasic.
Code: [Select]
Include "sbsw.inc"

SUB VARIABLES
    z = 0
    s = 0
    tree = 0
    star = 0
    flow = 0
    weed = 0
END SUB
    
tree = SW_LoadBmp "tree/mytree.bmp",1
star = SW_LoadBmp "tree/starlight.bmp",3
flow = SW_LoadBmp "tree/flower.bmp",8
weed = SW_LoadBmp "tree/weed.bmp",1

SW_Window 320,240,1
VARIABLES

While SW_Key(27)=0
SW_cls 0
SW_Sprite tree,0,0,0
SW_DrawBmp flow, 0, 111,128,128,z
SW_DrawBmp flow,191,118,128,128,z+4
SW_DrawBmp star,40,0,200,60,s
SW_DrawBmp weed,0,208,320,32,0

z +=1
if z=4 then z=0
s +=1
if s=3 then s=0
SW_Sync
SW_SetFps (8)
Wend

SW_Quit

X
Title: Re: SW QB compatibility
Post by: JRS on April 15, 2013, 11:24:02 AM
Quote
Yes, that was it.

Is for ScriptBasic.

Peter's first SB program and he forgot to post a picture of his new kid. (must be all the excitement)

Thanks Peter!
Title: Re: SW QB compatibility
Post by: Peter on April 15, 2013, 11:43:38 AM
Hi,

Did you know that OxygenBasic knows LUA syntax.
Try this!

Code: [Select]
include "sw.inc"
Window 640,480,1

sys i
For y=0, 480, 30
    For x=0, 600, 40
        FillBox(x,y,40,30, RGB(i,i,i))
        i +=1
    Next
Next

WaitKey
Quit
Title: Re: SW QB compatibility
Post by: JRS on April 15, 2013, 12:33:48 PM
Peter's first ScriptBasic program.

Report Card:  D

(http://files.allbasic.info/ScriptBasic/swnoshow.png)

Code: [Select]
Include "sbsw.inc"

SUB VARIABLES
    z = 0
    s = 0
    tree = 0
    star = 0
    flow = 0
    weed = 0
END SUB
    
tree = SW_LoadBmp("tree/mytree.bmp",1)
star = SW_LoadBmp("tree/starlight.bmp",3)
flow = SW_LoadBmp("tree/flower.bmp",8)
weed = SW_LoadBmp("tree/weed.bmp",1)

SW_Window 320,240,1
VARIABLES

While SW_Key(27)=0
SW_cls 0
SW_Sprite tree,0,0,0
SW_DrawBmp flow, 0, 111,128,128,z
SW_DrawBmp flow,191,118,128,128,z+4
SW_DrawBmp star,40,0,200,60,s
SW_DrawBmp weed,0,208,320,32,0

z +=1
if z=4 then z=0
s +=1
if s=3 then s=0
SW_Sync
SW_SetFps (8)
Wend

SW_Quit

C:\SB22\games\pg_tree>scriba tree.sb
tree.sb(12): error &H77:syntax error during checking the line and also noting that the syntax error so serious that none of t
he other syntax defintions can match the current line
tree.sb(13): error &H77:syntax error during checking the line and also noting that the syntax error so serious that none of t
he other syntax defintions can match the current line
tree.sb(14): error &H77:syntax error during checking the line and also noting that the syntax error so serious that none of t
he other syntax defintions can match the current line
tree.sb(15): error &H77:syntax error during checking the line and also noting that the syntax error so serious that none of t
he other syntax defintions can match the current line

C:\SB22\games\pg_tree>scriba tree.sb

The above problem was cause due to not using x-func() syntax. The () aren't required if no assignment is being made.

I would have thought you would have at least tried your first program before submitting it for review.

SourceForge Project of the Month (http://sourceforge.net/blog/potm-201304/)

Running on Ubuntu 64 native. (see attached)


X
Title: Re: SW QB compatibility
Post by: Peter on April 15, 2013, 02:03:10 PM
Looks good.  :D

I think like OxygenBasic, ever simple.

I can't test. I have always a crash. It was just an idea, but a bad idea.
No time for learning about well placed brackets.
Title: Re: SW QB compatibility
Post by: JRS on April 15, 2013, 02:47:33 PM
Can you make it work in O2 so I can see what the problem is with the SB version?

Quote
I can't test. I have always a crash.

You said you had the SokoMouse game running in SB, what happen to now start causing crashes? SB has to be one of the easiest languages around to install and program with. I just don't understand the issues or lack of interest. If you are unable to get SB running by unzipping and pointing the system path to the SB bin directory, I'm astonished that you were able to create such a cool library like Simple Window.

Title: Re: SW QB compatibility
Post by: Peter on April 16, 2013, 01:48:18 AM
Quote
I'm astonished that you were able to create such a cool library like Simple Window.

Sometimes, I have little bit luck !

There isn't room for programming with ScriptBasic between all the other programming languages at the moment.
My favorites are Assembler C/C++/OxygenBasic/ThinBasic.

Other works are Music/ Drawing/ Natural science/ Sleeping/ Eating/ Reading/ Playing.
There are some things more,  but I can't remember at the moment.

I have only two hands for all this simple things, do you have more?
Title: Re: SW QB compatibility
Post by: Aurel on April 16, 2013, 02:44:34 AM
Quote
SB has to be one of the easiest languages around to install and program with

Unfortunately John is not ...
syntax is nice and clean and represent very well basic as BASIC
but as you say many many times SB is created for scipting and embeding ,right?
I know how much trouble i have to start and run some examples in SB on windows.
But this can be also my lack of knowlege to... :-\
Title: Re: SW QB compatibility
Post by: JRS on April 16, 2013, 07:55:43 AM
This is the OxygenBasic forum not the ScriptBasic Forum.

The Simple Window examples were written for O2 not SB.

There are more important things in life than playing games.

Thanks for everyones time.