Author Topic: SW QB compatibility  (Read 5946 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
SW QB compatibility
« on: April 14, 2013, 07:09:47 PM »
Peter,

I noticed THIS 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

Peter

  • Guest
Re: SW QB compatibility
« Reply #1 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.
« Last Edit: April 15, 2013, 01:27:02 AM by peter »

Peter

  • Guest
Re: SW QB compatibility
« Reply #2 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.

Charles Pegge

  • Guest
Re: SW QB compatibility
« Reply #3 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

Peter

  • Guest
Re: SW QB compatibility
« Reply #4 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

« Last Edit: April 15, 2013, 06:31:00 AM by peter »

Peter

  • Guest
Re: SW QB compatibility
« Reply #5 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.   
« Last Edit: April 15, 2013, 04:43:42 AM by peter »

Aurel

  • Guest
Re: SW QB compatibility
« Reply #6 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

JRS

  • Guest
Re: SW QB compatibility
« Reply #7 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?


Peter

  • Guest
Re: SW QB compatibility
« Reply #8 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
« Last Edit: April 15, 2013, 09:09:14 AM by peter »

JRS

  • Guest
Re: SW QB compatibility
« Reply #9 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.


Peter

  • Guest
Re: SW QB compatibility
« Reply #10 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.   
     
« Last Edit: April 15, 2013, 09:42:30 AM by peter »

JRS

  • Guest
Re: SW QB compatibility
« Reply #11 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.


Peter

  • Guest
Re: SW QB compatibility
« Reply #12 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

JRS

  • Guest
Re: SW QB compatibility
« Reply #13 on: April 15, 2013, 10:43:37 AM »


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

Was this the intent?


Peter

  • Guest
Re: SW QB compatibility
« Reply #14 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
« Last Edit: April 15, 2013, 11:17:27 AM by peter »