Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - TempodiBasic

Pages: [1] 2 3 ... 10
1
Hi
in pure QBasic
here a simple demonstration about how to do a scroll-list with selection of some elements.
The input of list is from a file, but it can be changed at your need.
The input of user is keyboard, but it can be expanded at your need to mouse and joystick.
The output is an ASCII boxed scrollable list, but it can be changed in graphic primitive or graphic images at your need.
 
in this case I use this method to show the files of a folder.

Code: QB64: [Select]
  1. DECLARE SUB AllList (Max AS INTEGER)
  2. Const Max = 500
  3. Dim F(1 To Max) As String, S(1 To Max) As String * 2
  4. n = 0
  5. NameFile$ = "filedir.tmp"
  6. On Error GoTo Nofile
  7. Color 7, 0
  8. Shell "dir  /b> " + NameFile$
  9. Open NameFile$ For Input As #1
  10.     n = n + 1
  11.     Line Input #1, F(n)
  12.     S(n) = "  "
  13.     If wide < Len(F(n)) Then wide = Len(F(n))
  14.  
  15. Kill NameFile$
  16. Upper = n
  17.  
  18. 'AllList Upper
  19. ChoiceList Upper, wide
  20.  
  21.  
  22. Nofile:
  23. Print " Error "; FileName$ + " not found!"
  24.  
  25.  
  26. Sub ChoiceList (Umax As Integer, wid As Integer)
  27.     Shared F() As String, S() As String * 2
  28.     a = 0
  29.     k$ = ""
  30.     If i = 0 Then i = 1: n = i
  31.     ' 183 · 186º 189 ½ 196 Ä 211 Ó 214  Ö
  32.  
  33.     Do
  34.         ' here is the output of list
  35.         Color 7, 0
  36.         If i < n Or i > (n + 15) Then n = i
  37.         Locate 4, 23
  38.         Print "Ö" + String$(wid + 3, "Ä") + "·"
  39.         For a = n To n + 15 Step 1
  40.             If a > Umax Then M$ = Space$(wid + 3) Else M$ = " " + F(a) + S(a) + Space$(wid - Len(F(a)))
  41.             If a = i Then Color 15, 0
  42.             Locate , 23
  43.             Print "º" + M$ + "º"
  44.             If a = i Then Color 7, 0
  45.         Next a
  46.         Locate , 23
  47.         Print "Ó" + String$(wid + 3, "Ä") + "½"
  48.         Locate , 23
  49.         Print Chr$(24) + Chr$(25) + " move, S select, D done"
  50.  
  51.  
  52.  
  53.         ' here is the user input from keyboard
  54.         Do
  55.             k$ = UCase$(InKey$)
  56.             ' it switches the selector
  57.             If k$ = "S" Then If S(i) = "  " Then S(i) = "<-" Else S(i) = "  "
  58.             ' down
  59.             If k$ = Chr$(0) + "P" Then If i < Umax Then i = i + 1
  60.             'up
  61.             If k$ = Chr$(0) + "H" Then If i > 1 Then i = i - 1
  62.             If k$ = "D" Then Exit Sub 'Return ' all selection has been done
  63.         Loop Until k$ <> ""
  64.     Loop
  65.     'Return
  66.  
  67. Sub AllList (UMax As Integer)
  68.     Shared F() As String, S() As String * 2
  69.     ' debug SUB to show the whole list
  70.     For a = 1 To UMax Step 1
  71.         Print F(a) + S(a)
  72.         If a Mod 15 = 0 Then Sleep 2
  73.     Next a
  74.  

Happy Coding in the New Year!

PS: QB64 beats QBasic for NOT get back a QBasic Parser bug:
If you DIM a string array suffix, if you SHARED that string array from into the SUB, you cannot use the suffix for define datatype but you must use AS.
Doing so you fall in Parser error that alert you; SUB shared variable isn't declared at main module! LOL

Instead QB64 recognizes that the same name with or without suffix  are the same if declared as the same type of data.
Here the issue of Qbasic showed in code.
Code: QB64: [Select]
  1. DIM Me$ (1 to 10)
  2.  
  3. 'main
  4.  
  5. SUB foo

2
Programs / A simple demo to show how to merge with transparency 2 images
« on: December 20, 2021, 10:16:06 am »
Hi Guys and Gals of QB64 Universe

on Discord there is this request.
I find it useful for sharing in a more stable place (the Forum).
Quote
There are alot of mentioning about transparency on putimage wiki, but cant find any examples Im looking for.
[11:43]
I mean if there is no thing for it internally, its no problem to use just multiple images with they own transparency in it. I was just thinking that there is since I remember seeing some things about transparency. But it could be for other things as wel

a bit of simple graphic functions of QB64 that mimic the AND/OR/XOR/PSET option of QB45 PUT graphic keyword.
In QB64 you needn't use the old graphic tecniques both for the more available graphic memory to use both for the simpler graphic keywords.

here I share a very simple demonstration about  how to merge 2 images with different grade of transparency

Code: QB64: [Select]
  1. Const w = 600, h = 600
  2. A1& = _NewImage(w, h, 32) ' first image THE SCREEN
  3. A2& = _NewImage(w, h, 32) ' second image to show on the screen
  4. A3& = _NewImage(w / 2, h / 2, 32) ' resizing the second image into a smaller image
  5. ' making background image of the screeen
  6. _Dest A1&
  7. Cls , _RGB32(100, 0, 0)
  8. Line (300, 300)-(400, 400), _RGB32(0, 0, 200, 255), BF
  9. ' making new image to paste with transparency to the SCREEN
  10. _Dest A2&
  11. Cls , _RGB32(0, 200, 0, 255)
  12. _PutImage , A2&, A3& ' save A2 in A3 changing its size
  13. _PutImage , A1&, A2& ' save a1 in a2 to restore background
  14.  
  15. Screen A1& ' it creates the screen
  16. For q = 1 To 255 Step 5
  17.     _PutImage , A2&, A1& ' it restores background to screen visible
  18.     Locate 1, 1: Print "Alpha channel source image: "; q ' onscreen output
  19.     _SetAlpha q, , A3& ' here it is changing transparency of A3&
  20.     _PutImage (200, 200)-(400, 400), A3&, A1& ' it puts A3& on the center of A1&
  21.     _Delay .2 'it waits to let you see changement
  22.     _Display ' it shows at the istant the changement
  23.     _Limit 10 ' it saves CPU work
  24.  

On the other side if you want only have the background transparent you must use an image with Black background that  it works as transparent color in QB64!
Moreover if you want  to make  transparent a specific color or range of colors you must use _SETALPHA keyword.

Good Coding

3
Programs / File managing in Qbasic mode
« on: December 02, 2021, 09:10:29 pm »
Hi
here an example about how to manage if file exists or not in Qbasic way...
have a fun...
Code: QB64: [Select]
  1. 'this code shows a feature/bug of Qbasic inherited by QB64
  2. ' to duplicate experience please run this code into QB64 or Qbasic in DOSBOX
  3.  
  4. ' part 1 creates a file with a strange name so that it is difficult
  5. ' to have it as real file in your pc
  6. On Error GoTo ThisFile
  7. filename$ = "1a2b3c4d.$$$"
  8. Killing = 0
  9. 'testing if file exists
  10. Open filename$ For Input As #1
  11. Print "File exists and opened "; filename$
  12. TakeFile$ = Input$(LOF(1), # 1)
  13. Print TakeFile$
  14. If Killing = -1 Then Kill filename$: Print "Deleted file "; filename$
  15.  
  16. ThisFile:
  17. ' the file doesn't exist so it creates that and puts some data into file
  18. Txt$ = "hello world"
  19. Open filename$ For Binary As #1
  20. Put #1, , Txt$
  21. Print "file created "; filename$
  22. ' it says if the file must be delete at the end of code
  23. Killing = -1
  24. ' return on the linecode of error
in QB64 you need only of _Fileexists https://www.qb64.org/wiki/FILEEXISTS

4
Hi
this is a thread for who loves mathematica and phylosophy, please go away towards other thread if you don't have this kind of love.

Introduction:
In the ancient greek a philosopher of the school of Parmenide from Elea (so they had been called Eleatics) uses logic thinking to bring the student to a logical deduction contrary to the experience of the life of every day.
We cannot move to reach a target because between we and the target there are infinite halfpaths. (First paradox)
We cannot hit with an arrow a target because the arrow cannot move towards target because its movement is the sum of infinitesimal state of standing stopped into a infinitesimal slice of time. (third paradox)


Coding:
Code: QB64: [Select]
  1. _Title "Paradox of Zenone: concepts of limit and infinitesimal"
  2. Const Limit = 400
  3. Dim As Single Sum, Lenght, cycle
  4.  
  5. Lenght = Limit / 2
  6. Sum = Sum + Lenght
  7.     cycle = cycle + 1
  8.     Lenght = Lenght / 2
  9.     Sum = Sum + Lenght
  10.     Print Sum, cycle
  11.  
  12. Loop While Sum < Limit
  13. Print cycle

we got 23....
while this one seems to be infinite
Code: QB64: [Select]
  1. _Title "Paradox of Zenone: concepts of limit and infinitesimal"
  2. Const Limit = 400
  3. Dim As Single Sum, Lenght, cycle
  4.  
  5. Lenght = Limit / 2
  6.     cycle = cycle + 1
  7.     Lenght = Lenght / 2
  8.     Sum = Sum + Lenght
  9.     Print Sum, cycle
  10.  
  11. Loop While Sum < Limit
  12. Print cycle

These arguments lead us to the mathematical concepts of limit and infinitesimal calculus.
In the while many ancient and modern phylosophers have tried to solve the Zenone's paradoxes without a mathematical approach.
here some solutions of these paradoxes
https://en.wikipedia.org/wiki/Zeno%27s_paradoxes#Proposed_solutions

5
QB64 Discussion / [fixed]A my first Debug session on FOR NEXT issue
« on: November 05, 2021, 11:16:55 pm »
Hi QB64 Community
Hi Qb64 developers Team

just to keep in live my toon character
I share with you this my experience got during Recursive session!
I fall on a simple FOR NEXT STEP loop!
Yes the easiest loop that we have to work repeating a block of instructions.

enviroment:
On Windows 8.1 Pro 64 bit, a HP notebook machine with Celeron 2.0 GHz and using QB64 2.0.1

the goal of the code:
change the STEP value of FOR NEXT loop to change the results of looping

the result of the code:
changing at some point of the loop the Stepper variable the FOR loop goes on with no change of output results.

tool of investigation:
Debug mode of QB64 v2.0.1

here code that shows the issue
Code: QB64: [Select]
  1. StartIndex = 2: stepperIndex = 2: DoneIndex = 20
  2. Print "StepperIndex is 2 but when index will be 18 it becomes -2"
  3. Print " so we expect to see index to decrement after 18 towards negative digits"
  4. For index = StartIndex To DoneIndex Step stepperIndex
  5.     Print index; "->"; index ^ 2;
  6.     _Delay .1
  7.     If index = 18 Then stepperIndex = -2 '<------------------------newline
  8.  
  9. Print "another try: the variable a grows up to 100 step 10 until"
  10. Print " it becomes 50, after this variable a should decrease step -10"
  11. a = 1: b = 100: c = 10
  12. For a = 1 To b Step c
  13.     Print a; " ";
  14.     If a = 50 Then c = -c
  15.  


here screenshots
  [ You are not allowed to view this attachment ]  
  [ You are not allowed to view this attachment ]  
  [ You are not allowed to view this attachment ]  
  [ You are not allowed to view this attachment ]  

who can test this issue?
Feedbacks ?

6
QB64 Discussion / Reporting some QB64 references for Italian programmers
« on: November 04, 2021, 12:39:04 pm »
Hi Qb64 community
it is clear from time ago that we are a  multicultural and multipurpuse community.

Nevertheless of continuose working of  Developers QB64 Team the requests grow up!
Too work for Our Angels of QB64!
Today playing with Bing I got these link to QB64 that can be surely useful for all those Italian coders or interested to be coder and with low knowledge of english language.

http://www.ansuitalia.it/Portale/articoli/36-informatica/2859-qb64-il-software-libero-per-programmare-in-qbasic-e-quickbasic.html

https://lumiroseblog.wordpress.com/computer-tech/programming-languages/

Good lecture and practice with QB64

7
Hi QB64 community
I remark this strange behaviour of SCREEN statement.
It is the same for versions 1.4 -1.5-2.0-2.0.1

reading the help in IDE and the wikiHelp on web I got these affirmations about SCREEN keyword
Quote
The SCREEN mode INTEGER values available today are 0 to 2 and 7 to 13 listed below.
QB64 can use a LONG _NEWIMAGE page or _LOADIMAGE file image handle value instead.
The empty comma disables color when any value is used. DO NOT USE! Include the comma ONLY when using page flipping.
If the SCREEN mode supports pages, the active page is the page to be worked on while visual page is the one displayed.
at this link http://www.qb64.org/wiki/index.php?title=SCREEN

So please help my buggy coder brain to understand this thing showed  by following screenshot
  [ You are not allowed to view this attachment ]  

As you can see it seems OK to type SCREEN with no parameter.
This let me think that internal code for SCREEN sets automatically to SCREEN 0 if the keyword has no following parameters, is it?

Waiting your thinking....

PS
I must test this code into QBASIC.

8
Programs / OneKey Binary Selection
« on: October 04, 2021, 07:20:55 pm »
Hi Boys and Gals

just to say
binary search is speeder than bubble sequential choice
so here my OneKey selector using a binary search

it lets me remember the textual game Guess the number!
Code: QB64: [Select]
  1. 'one key input  2021-10-04 TempoDiBasic
  2. ' Saint Francis is patron of this day
  3.  
  4. choice$ = "0123456789"
  5. choosen$ = ""
  6. getInput choice$, choosen$
  7. Print choice$, choosen$
  8. choice$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  9. choosen$ = ""
  10. getInput choice$, choosen$
  11. Print choice$, choosen$
  12. Input "Enter set of one character choice...", choice$
  13. choosen$ = ""
  14. getInput choice$, choosen$
  15. Print choice$, choosen$
  16.  
  17. Sub getInput (cho$, choo$) 'Static
  18.     Dim As Integer leng, tim, f1, s1
  19.     Dim As String FirstHalf, SecondHalf, f, s
  20.     leng = Len(cho$)
  21.     FirstHalf = Left$(cho$, Int(leng / 2))
  22.     SecondHalf = Right$(cho$, leng - Int(leng / 2))
  23.     If leng = 1 Then choo$ = cho$: Exit Sub
  24.     While leng > 1
  25.         Cls
  26.         If f = " " Then
  27.             f = "þ"
  28.             s = " "
  29.             f1 = 29
  30.             s1 = 15
  31.         Else
  32.             f = " "
  33.             s = "þ"
  34.             f1 = 15
  35.             s1 = 29
  36.         End If
  37.         Locate 2
  38.         Color f1
  39.         Print f + FirstHalf + f + "  ";
  40.         Color s1
  41.         Print s + SecondHalf + s
  42.         Locate 3
  43.         Color 15
  44.         Print "press spacebar to choose, wait 2 second to refuse"
  45.         tim = Int(Timer)
  46.         While InKey$ = "" And (Timer - tim <= 2)
  47.             If InKey$ = " " Then
  48.                 If f = " " Then getInput SecondHalf, choo$ Else getInput FirstHalf, choo$
  49.             End If
  50.             If Len(choo$) = 1 Then Exit Sub
  51.         Wend
  52.     Wend

my sub getInput at your service!
One suggestion, you must press and release the spacebar in 1 second to get the best result or you need to increase the time of autoselection if you want more slowly interaction.

9
QB64 Discussion / QB64 competitors... It is an hard life!
« on: September 27, 2021, 04:58:44 am »
Hi boys and girls of QB64
I'm writing here for my disappointment.
Yes because I see growing up this community and QB64 everyday.
The efforts (also made in hobbyistic manner) so professional both of developers both of you, people of QB64 community, are intensive and continuous.
Here the cause of my disappointment : the invisibility.
. https://www.slant.co/topics/9807/~basic-like-programming-languages
What is the cutoff for visibility?


10
Programs / Demo of Text in Opengl point by point
« on: September 26, 2021, 04:12:58 pm »
Hi
here a adjourned version of Text point by point in Opengl
now with no handy conversions of colors and dimensions from standard SCREEN and Opengl Screen.

Code: QB64: [Select]
  1. 'OpenGL text without mapping or font
  2.  
  3. Const True = -1, False = 0
  4. Const Black = _RGB32(0, 0, 0, 255), White = _RGB32(255)
  5. Const Red = _RGB32(230, 0, 0, 255), Green = _RGB32(0, 230, 0, 255)
  6. Const Blu = _RGB32(0, 0, 230, 255)
  7.  
  8. Dim Shared sXp As Integer, glXp As Single, sYp As Integer, glYp As Single
  9. Dim Shared glInit As Integer, sRc As Integer, sGc As Integer, sBc As Integer, sAc As Integer
  10.  
  11.  
  12. T = _NewImage(600, 400, 32)
  13. S = _NewImage(600, 400, 32)
  14. _Title "Demo2 of Text in OpenGL:point by point"
  15.  
  16. glRun = False
  17. sBkc = White
  18. sFgc = Green
  19. PrepareTxt "Hello"
  20.  
  21. ShowSourceTxt
  22. Print "Now a text in OpenGL"
  23. glInit = True
  24. glRun = True
  25.     _Limit 10
  26.  
  27. Sub PrepareTxt (txt As String)
  28.     _Dest T
  29.     Cls , Red
  30.     Color sFgc, sBkc
  31.     Locate 1, 1: Print txt
  32.     _Dest 0
  33.  
  34. Sub ShowSourceTxt
  35.     Screen T
  36.     _Delay 3
  37.     Screen S
  38.  
  39.  
  40.  
  41. Sub copyTxt (Xs As Integer, Ys As Integer, glFgc As _Unsigned Long, Size As Integer)
  42.     Dim WidhTxt As Integer, HeighTxt As Integer
  43.     WidhTxt = 40
  44.     HeighTxt = 12
  45.     _Source T
  46.     _Dest S
  47.  
  48.     For sXp = 0 To WidhTxt Step 1
  49.         For sYp = 1 To HeighTxt Step 1
  50.             If Point(sXp, sYp) = sFgc Then
  51.                 PaintPoint Xs + (sXp * Size), Ys + (sYp * Size), glFgc, Size
  52.             End If
  53.         Next sYp
  54.     Next sXp
  55.  
  56.  
  57. ' OpenGl-----------------------------
  58. Sub _GL ()
  59.     If glRun = False Then Exit Sub
  60.     If glInit Then InitGL
  61.     _glClear _GL_COLOR_BUFFER_BIT
  62.  
  63.     ' every time _GL runs it must set values for screen
  64.     _glMatrixMode _GL_MODELVIEW
  65.     _glTranslatef -1, 1, 0
  66.     _glScalef (1 / (_Width / 2)), (-1 / (_Height / 2)), 1
  67.  
  68.  
  69.  
  70.     copyTxt 1, 1, Green, 1
  71.     copyTxt 100, 200, Red, 2
  72.     copyTxt 200, 100, Black, 4
  73.  
  74. Sub InitGL
  75.     glInit = False
  76.     _glClearColor 0, 0, 0.8, 1
  77.     _glDisable _GL_MULTISAMPLE ' disable antialiasing method that hides one pixel
  78.     ' in Opengl Anti aliasing method is ON for default
  79.     _glFlush
  80.  
  81.  
  82. Sub PaintPoint (X As Single, Y As Single, glFgc As _Unsigned Long, Sizing As Integer)
  83.     Dim gXp As Single, gYp As Single, gRc As Single, gGc As Single, gBc As Single, gAc As Single
  84.     _glColor4ub _Red32(glFgc), _Green32(glFgc), _Blue32(glFgc), _Alpha32(glFgc) 'f gRc, gGc, gBc, gAc
  85.     _glPointSize Sizing
  86.     _glBegin _GL_POINTS
  87.     _glVertex2f X, Y
  88.     _glEnd
  89.  
  90.  

while here a clear example to make text in 3D using a matrix by SMcNeill
https://www.qb64.org/forum/index.php?topic=3254.msg125353#msg125353
Good watching

11
QB64 Discussion / ON ERROR RESUME_RETURN bug
« on: September 12, 2021, 02:04:08 pm »
Hi Boys and girls of QB64

thanks to Pete for his code that I have hugely modded to show the bug
thanks to vwbugsguy (on QB64 discord server) to show accidentaly this bug

copy paste and run this code...
Code: QB64: [Select]
  1. On Error GoTo errhandler
  2.  
  3. Locate -1, -1
  4. Print "This routine is buggy!"
  5.  
  6.  
  7. errhandler:
  8.  
what do you observ? That it runs well showing error code and then continuing its flow to the end of program!
  [ You are not allowed to view this attachment ]  
ok, but why can I  type RETURN statement that it is for closing the GOSUB subroutine at the end of error trap subroutine?
Why for parser and compiler it is ok? Is it right that the error trap subroutine has its end in the RESUME [NEXT] statement, isn't it?
So for now it is possible to close an Error trap subroutine using RETURN
Code: QB64: [Select]
  1. On Error GoTo errhandler
  2.  
  3. Locate -1, -1
  4. Print "This routine is buggy!"
  5.  
  6.  
  7. errhandler:
  8.  
and we get an error only on fly
  [ You are not allowed to view this attachment ]  
the same we get if we type before RETURN and after RESUME NEXT.
Yes the error on fly doesn't happens in the first code because the statement RETURN will never be executed.

Welcome discussion and opinions.
Happy coding in QB64

12
Hi guys and gals of QB64 community

after some feedbacks from you, my dear friends,
I try to do an OpenGl Tutorial for 2D graphic so all people interested can introduce themselves to programming OpenGl in QB64.

the goal is to produce a simple basic game with 2D graphic: PONG

Now I post the first step that consists of showing the settings of Opengl graphic.

As you can see watching at my code, there is NO loop in the main in this first demo.
Each line of code has its own comment, moreover there is a descriptive scheme of comparison between standard SCREEN and OpenGl SCREEN.

The help message for user has been made by standard PRINT output, because in OpenGl Text is another image to draw on the screen and this is not a basic step.

The only user's gameplay is press a key to quit the application.

Here attached the first demo.
 

13
QB64 Discussion / PMAP lacks precision
« on: August 29, 2021, 02:20:27 pm »
Hi boys and girls of QB64

trying to develope in alternative way my Pong OpenGl demo by using WINDOW and PMAP commands of QB64/QB
I got PMAP with loosing precision!
please try this code:
Code: QB64: [Select]
  1.  
  2. S = _NewImage(800, 600, 32)
  3. Window Screen(-1.0, -1.0)-(1.0, 1.0)
  4. ' translate screen left-top and lower-right into window system
  5. Print PMap(0, 2), PMap(0, 3), PMap(800, 2), PMap(600, 3)
  6.  
  7. 'translate window system left-top and lower-right into screen
  8. Print PMap(-1, 0), PMap(-1, 1), PMap(1, 0), PMap(1, 1)
  9.  
  10.  
  11.  

and here you can see the output
  [ You are not allowed to view this attachment ]  
Well it seems that we cannot use PMAP for NASA calculation.
Please gimme feedbacks.


14
Hi friends
here a demo that I was doing some time ago.
For now I post the essential module in which I show how to manage data and pass it to OpenGl function that are constrained into _GL() sub.

If I get some feedback of interest I'll complete all the demonstration to get the status of simple complete demo adding sounds, scores, etc etc etc.

Help instructions:
press Enter key to swap between Standard and OpenGl mode (you can recognize it from the shape of ball like hexagon) move pad of players with left/right arrows and A / S.

waiting feedbacks
Thanks to try

15
QB64 Discussion / file code of/about QB64 about FONT S01E02
« on: August 13, 2021, 04:20:04 am »
Hi
about how to use FONT in QB64
here QB64 code showed by Fellippe in His tutorial


Here link to QBreport of  FONT
https://www.youtube.com/watch?v=VxbLHoIKtqI&t=659s
https://www.youtube.com/watch?v=C94VYvvPlJ0&t=8s

for run without error the code you must use a path for a font that there is on your OS
or you must download and put the .TTF file in the same folder of .BAS

Pages: [1] 2 3 ... 10