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.


Messages - Support

Pages: 1 ... 18 19 [20] 21 22 ... 59
286
What's New / ScriptBasic GFX
« on: February 25, 2014, 03:26:29 PM »
I have created a ScriptBasic extension module from the SDL_gfx library. Attached are the binary and examples for Ubuntu 64 bit and Windows 32 bit. This version is primary for testing the SDL_gfx interface. It only supports the main screen surface at this time. The next installment will have a surface management system which any function can act upon. This will be the lead-in to sprites. The current source to the ScriptBasic GFX extension module is on the C BASIC Bitbucket Repository and can be built using the ScriptBasic 2.1 header files. SDL 1.2 installed is a prerequisite.



Code: Script BASIC
  1. ' ScriptBasic GFX - Alpha Circles
  2.  
  3. IMPORT gfx.inc
  4.  
  5. scrn = gfx::Window(640, 480, "ScriptBasic GFX - Alpha Circles")
  6. ' Random Value Arrays
  7. RANDOMIZE(gfx::Time())
  8. FOR i = 0 TO 512
  9.   rx[i] = RND() % 640
  10.   ry[i] = 60 + RND() % 480 - 80
  11.   rz[i] = RND() % 64
  12.   rr[i] = RND() AND  255
  13.   rg[i] = RND() AND  255
  14.   rb[i] = RND() AND  255
  15.   af = rx[i] / 640
  16.   ra[i] = INT(255 * af)
  17. NEXT
  18.  
  19. ts = gfx::Time()
  20. FOR i = 0 TO 512
  21.   gfx::filledCircleRGBA scrn, rx[i], ry[i], rz[i], rr[i], rg[i], rb[i], ra[i]
  22. NEXT
  23. te = gfx::Time()
  24. gfx::stringColor scrn, 20, 15, "Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0xffffffff
  25. gfx::Update
  26. WHILE gfx::KeyName(1) <> "+escape"
  27. WEND
  28. gfx::Close
  29.  



Code: Script BASIC
  1. ' ScriptBasic GFX - Alpha Thick Line
  2.  
  3. IMPORT gfx.inc
  4.  
  5. scrn = gfx::Window(640, 480, "ScriptBasic GFX - Alpha Thick Line")
  6. ' Random Value Arrays
  7. RANDOMIZE(gfx::Time())
  8. FOR i = 0 TO 512
  9.   rx[i] = RND() % 640
  10.   ry[i] = 60 + RND() % 480 - 80
  11.   lw[i] = 2 + RND() % 7
  12.   rr[i] = RND() AND  255
  13.   rg[i] = RND() AND  255
  14.   rb[i] = RND() AND  255
  15.   af = rx[i] / 640
  16.   ra[i] = INT(255 * af)
  17. NEXT
  18. ts = gfx::Time()
  19. FOR i = 0 TO 512 STEP 5
  20.   gfx::thickLineRGBA scrn, rx[i], ry[i], rx[i+1], ry[i+1], lw[i], rr[i], rg[i], rb[i], ra[i]
  21. NEXT
  22. te = gfx::Time()
  23. gfx::stringColor scrn, 20, 15,"Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0xffffffff
  24. gfx::Update
  25. WHILE gfx::KeyName(1) <> "+escape"
  26. WEND
  27. gfx::Close
  28.  




Code: Script BASIC
  1. ' ScriptBasic GFX - Alpha Bezier Curve
  2.  
  3. IMPORT gfx.inc
  4.  
  5. ' Random Value Arrays
  6. scrn = gfx::Window(640, 480, "ScriptBasic GFX - Alpha Bezier")
  7. RANDOMIZE(gfx::Time())
  8. FOR i = 0 TO 512
  9.   rx[i] = RND() % 640/2
  10.   rxx[i] = 640/2 + rx[i]  
  11.   ry[i] = 60 + RND() % 480 - 80
  12.   lw[i] = 2 + RND() % 7
  13.   rr[i] = RND() AND  255
  14.   rg[i] = RND() AND  255
  15.   rb[i] = RND() AND  255
  16.   af = rx[i] / 640
  17.   ra[i] = INT(255 * af)
  18. NEXT
  19. ts = gfx::Time()
  20. FOR i = 0 TO 512-3 STEP 3
  21.   a1[0] = rxx[i]
  22.   a1[1] = rxx[i + 1]
  23.   a1[2] = rxx[i + 2]
  24.   a2[0] = ry[i]
  25.   a2[1] = ry[i + 1]
  26.   a2[2] = ry[i + 2]
  27.   gfx::bezierRGBA scrn, a1, a2, 3, 100, rr[i], rg[i], rb[i], ra[i]
  28. NEXT
  29. te = gfx::Time()
  30. gfx::stringColor scrn, 20, 15,"Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0xffffffff
  31. gfx::Update
  32. WHILE gfx::KeyName(1) <> "+escape"
  33. WEND
  34. gfx::Close
  35.  



Code: Script BASIC
  1. ' ScriptBasic GFX - Alpha Polygon
  2.  
  3. IMPORT gfx.inc
  4.  
  5. ' Random Value Arrays
  6. scrn = gfx::Window(640, 480, "ScriptBasic GFX - Alpha Polygon")
  7. RANDOMIZE(gfx::Time())
  8. FOR i = 0 TO 512
  9.   rx[i] = RND() % 640/2
  10.   rxx[i] = 640/2 + rx[i]  
  11.   ry[i] = 60 + RND() % 480 - 80
  12.   lw[i] = 2 + RND() % 7
  13.   rr[i] = RND() AND  255
  14.   rg[i] = RND() AND  255
  15.   rb[i] = RND() AND  255
  16.   af = rx[i] / 640
  17.   ra[i] = INT(255 * af)
  18. NEXT
  19. ts = gfx::Time()
  20. FOR i = 0 TO 128-5 STEP 5
  21.   a1[0] = rxx[i]
  22.   a1[1] = rxx[i + 1]
  23.   a1[2] = rxx[i + 2]
  24.   a1[3] = rxx[i + 3]
  25.   a1[4] = rxx[i + 4]    
  26.   a2[0] = ry[i]
  27.   a2[1] = ry[i + 1]
  28.   a2[2] = ry[i + 2]
  29.   a2[3] = ry[i + 3]
  30.   a2[4] = ry[i + 4]    
  31.   gfx::polygonRGBA scrn, a1, a2, 5, rr[i], rg[i], rb[i], 255
  32. NEXT
  33. te = gfx::Time()
  34. gfx::stringColor scrn, 20, 15,"Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0xffffffff
  35. gfx::Update
  36. WHILE gfx::KeyName(1) <> "-escape"
  37. WEND
  38. gfx::Close
  39.  



Code: Script BASIC
  1. ' ScriptBasic GFX - Textured Polygon
  2.  
  3. IMPORT gfx.inc
  4.  
  5. scrn = gfx::Window(640, 480, "ScriptBasic GFX - Texured Polygon")
  6. a1[0] = 640/4
  7. a1[1] = 640/2
  8. a1[2] = a1[0] + a1[1]
  9. a2[0] = 480/4*3
  10. a2[1] = 480/4
  11. a2[2] = a2[0]
  12. gfx::texturedPolygon scrn, a1, a2, 3, "texture.bmp", 0, 0
  13. gfx::Update
  14. WHILE gfx::KeyName(1) <> "+escape"
  15. WEND
  16. gfx::Close
  17.  



Code: Script BASIC
  1. ' ScriptBasic GFX - Fonts & Rotation
  2.  
  3. IMPORT gfx.inc
  4. DECLARE SUB LoadFont ALIAS "loadstring" LIB "t"
  5.  
  6. font_5x7 = LoadFont("Fonts/5x7.fnt")
  7. font_6x10 = LoadFont("Fonts/6x10.fnt")
  8. font_7x13 = LoadFont("Fonts/7x13.fnt")
  9. font_9x15 = LoadFont("Fonts/9x15.fnt")
  10. font_10x20 = LoadFont("Fonts/10x20.fnt")
  11.  
  12. scrn = gfx::Window(640, 480, "ScriptBasic GFX - Font & Rotation")
  13. gfx::FontRotation 0
  14. gfx::SetFont font_5x7, 5, 7
  15. gfx::stringColor scrn, 20, 20,"Font 5x7" & CHR(0), 0xffffffff
  16. gfx::SetFont font_6x10, 6, 10
  17. gfx::stringColor scrn, 20, 30,"Font 6x10" & CHR(0), 0xffffffff
  18. gfx::SetFont font_7x13, 7, 13
  19. gfx::stringColor scrn, 20, 40,"Font 7x13" & CHR(0), 0xffffffff
  20. gfx::SetFont font_9x15, 9, 15
  21. gfx::stringColor scrn, 20, 55,"Font 9x15" & CHR(0), 0xffffffff
  22. gfx::SetFont font_10x20, 10, 20
  23. gfx::FontRotation 2
  24. gfx::stringColor scrn, 110, 70,"Font 10x20" & CHR(0), 0xffffffff
  25. gfx::Update
  26. WHILE gfx::KeyName(1) <> "+escape"
  27. WEND
  28. gfx::Close
  29.  



Code: Script BASIC
  1. ' ScriptBasic GFX - Frame rate controlled circles
  2.  
  3. IMPORT gfx.inc
  4.  
  5. scrn = gfx::Window(640, 480, "ScriptBasic GFX - FPS Circles")
  6. ' Random Value Arrays
  7. RANDOMIZE(gfx::Time())
  8. FOR i = 0 TO 512
  9.   rx[i] = RND() % 640
  10.   ry[i] = 60 + RND() % 480 - 80
  11.   rz[i] = RND() % 64
  12.   rr[i] = RND() AND  255
  13.   rg[i] = RND() AND  255
  14.   rb[i] = RND() AND  255
  15.   af = rx[i] / 640
  16.   ra[i] = INT(255 * af)
  17. NEXT
  18. gfx::SDL_initFramerate
  19. i = 0
  20. REPEAT
  21.   gfx::filledCircleRGBA scrn, rx[i], ry[i], rz[i], rr[i], rg[i], rb[i], 255
  22.   i += 1
  23.   IF i > 512 THEN i = 0
  24.   gfx::Update
  25.   gfx::SDL_framerateDelay
  26.   gfx::stringColor scrn, 20, 15,"FPS: " & gfx::SDL_getFramerate() & CHR(0), 0xffffffff  
  27. UNTIL gfx::KeyName(0) = "+escape"
  28. gfx::Close
  29.  



Code: Script BASIC
  1. ' ScriptBasic GFX - Alpha Pie
  2.  
  3. IMPORT gfx.inc
  4.  
  5. scrn = gfx::Window(640, 480, "ScriptBasic GFX - Alpha Pie")
  6. ' Random Value Arrays
  7. RANDOMIZE(gfx::Time())
  8. FOR i = 0 TO 512
  9.   rx[i] = RND() % 640
  10.   ry[i] = 60 + RND() % 480 - 80
  11.   rz[i] = RND() % 100
  12.   a1[i] = RND() % 360
  13.   a2[i] = RND() % 360
  14.   rr[i] = RND() AND  255
  15.   rg[i] = RND() AND  255
  16.   rb[i] = RND() AND  255
  17.   af = rx[i] / 640
  18.   ra[i] = INT(255 * af)
  19. NEXT
  20. ts = gfx::Time()
  21. FOR i = 0 TO 512 STEP 2
  22.   gfx::filledPieRGBA scrn, rx[i], ry[i], rz[i], a1[i], a2[i], rr[i], rg[i], rb[i], ra[i]
  23. NEXT  
  24. te = gfx::Time()
  25. gfx::stringColor scrn, 20, 15,"Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0xffffffff
  26. gfx::Update scrn
  27. WHILE gfx::KeyName(1) <> "+escape"
  28. WEND
  29. gfx::Close
  30.  

I created a gfx.inc module IMPORT file for the ScriptBasic GFX extension module.

Code: Script BASIC
  1. MODULE GFX
  2.  
  3. DECLARE SUB    ::Window                    ALIAS     "gfx_Window"                    LIB  "gfx"
  4. DECLARE SUB    ::Close                     ALIAS     "gfx_Close"                     LIB  "gfx"
  5. DECLARE SUB    ::Update                    ALIAS     "gfx_Update"                    LIB  "gfx"
  6. DECLARE SUB    ::ClearScreen               ALIAS     "gfx_ClearScreen"               LIB  "gfx"
  7. DECLARE SUB    ::SDL_SetClipRect           ALIAS     "gfx_SDL_SetClipRect"           LIB  "gfx"
  8. DECLARE SUB    ::Time                      ALIAS     "gfx_Time"                      LIB  "gfx"
  9. DECLARE SUB    ::Shift                     ALIAS     "gfx_Shift"                     LIB  "gfx"
  10. DECLARE SUB    ::Rotate                    ALIAS     "gfx_Rotate"                    LIB  "gfx"
  11. DECLARE SUB    ::GetKey                    ALIAS     "gfx_GetKey"                    LIB  "gfx"
  12. DECLARE SUB    ::WaitKey                   ALIAS     "gfx_WaitKey"                   LIB  "gfx"
  13. DECLARE SUB    ::KeyName                   ALIAS     "gfx_KeyName"                   LIB  "gfx"
  14. DECLARE SUB    ::Mouse                     ALIAS     "gfx_Mouse"                     LIB  "gfx"
  15. DECLARE SUB    ::pixelColor                ALIAS     "gfx_pixelColor"                LIB  "gfx"
  16. DECLARE SUB    ::pixelRGBA                 ALIAS     "gfx_pixelRGBA"                 LIB  "gfx"
  17. DECLARE SUB    ::hlineColor                ALIAS     "gfx_hlineColor"                LIB  "gfx"
  18. DECLARE SUB    ::hlineRGBA                 ALIAS     "gfx_hlineRGBA"                 LIB  "gfx"
  19. DECLARE SUB    ::vlineColor                ALIAS     "gfx_vlineColor"                LIB  "gfx"
  20. DECLARE SUB    ::vlineRGBA                 ALIAS     "gfx_vlineRGBA"                 LIB  "gfx"
  21. DECLARE SUB    ::rectangleColor            ALIAS     "gfx_rectangleColor"            LIB  "gfx"
  22. DECLARE SUB    ::rectangleRGBA             ALIAS     "gfx_rectangleRGBA"             LIB  "gfx"
  23. DECLARE SUB    ::roundedRectangleColor     ALIAS     "gfx_roundedRectangleColor"     LIB  "gfx"
  24. DECLARE SUB    ::roundedRectangleRGBA      ALIAS     "gfx_roundedRectangleRGBA"      LIB  "gfx"
  25. DECLARE SUB    ::boxColor                  ALIAS     "gfx_boxColor"                  LIB  "gfx"
  26. DECLARE SUB    ::boxRGBA                   ALIAS     "gfx_boxRGBA"                   LIB  "gfx"
  27. DECLARE SUB    ::roundedBoxColor           ALIAS     "gfx_roundedBoxColor"           LIB  "gfx"
  28. DECLARE SUB    ::roundedBoxRGBA            ALIAS     "gfx_roundedBoxRGBA"            LIB  "gfx"
  29. DECLARE SUB    ::lineColor                 ALIAS     "gfx_lineColor"                 LIB  "gfx"
  30. DECLARE SUB    ::lineRGBA                  ALIAS     "gfx_lineRGBA"                  LIB  "gfx"
  31. DECLARE SUB    ::aalineColor               ALIAS     "gfx_aalineColor"               LIB  "gfx"
  32. DECLARE SUB    ::aalineRGBA                ALIAS     "gfx_aalineRGBA"                LIB  "gfx"
  33. DECLARE SUB    ::thickLineColor            ALIAS     "gfx_thickLineColor"            LIB  "gfx"
  34. DECLARE SUB    ::thickLineRGBA             ALIAS     "gfx_thickLineRGBA"             LIB  "gfx"
  35. DECLARE SUB    ::circleColor               ALIAS     "gfx_circleColor"               LIB  "gfx"
  36. DECLARE SUB    ::circleRGBA                ALIAS     "gfx_circleRGBA"                LIB  "gfx"
  37. DECLARE SUB    ::arcColor                  ALIAS     "gfx_arcColor"                  LIB  "gfx"
  38. DECLARE SUB    ::arcRGBA                   ALIAS     "gfx_arcRGBA"                   LIB  "gfx"
  39. DECLARE SUB    ::aacircleColor             ALIAS     "gfx_aacircleColor"             LIB  "gfx"
  40. DECLARE SUB    ::aacircleRGBA              ALIAS     "gfx_aacircleRGBA"              LIB  "gfx"
  41. DECLARE SUB    ::filledCircleColor         ALIAS     "gfx_filledCircleColor"         LIB  "gfx"
  42. DECLARE SUB    ::filledCircleRGBA          ALIAS     "gfx_filledCircleRGBA"          LIB  "gfx"
  43. DECLARE SUB    ::ellipseColor              ALIAS     "gfx_ellipseColor"              LIB  "gfx"
  44. DECLARE SUB    ::ellipseRGBA               ALIAS     "gfx_ellipseRGBA"               LIB  "gfx"
  45. DECLARE SUB    ::aaellipseColor            ALIAS     "gfx_aaellipseColor"            LIB  "gfx"
  46. DECLARE SUB    ::aaellipseRGBA             ALIAS     "gfx_aaellipseRGBA"             LIB  "gfx"
  47. DECLARE SUB    ::filledEllipseColor        ALIAS     "gfx_filledEllipseColor"        LIB  "gfx"
  48. DECLARE SUB    ::filledEllipseRGBA         ALIAS     "gfx_filledEllipseRGBA"         LIB  "gfx"
  49. DECLARE SUB    ::pieColor                  ALIAS     "gfx_pieColor"                  LIB  "gfx"
  50. DECLARE SUB    ::pieRGBA                   ALIAS     "gfx_pieRGBA"                   LIB  "gfx"
  51. DECLARE SUB    ::filledPieColor            ALIAS     "gfx_filledPieColor"            LIB  "gfx"
  52. DECLARE SUB    ::filledPieRGBA             ALIAS     "gfx_filledPieRGBA"             LIB  "gfx"
  53. DECLARE SUB    ::trigonColor               ALIAS     "gfx_trigonColor"               LIB  "gfx"
  54. DECLARE SUB    ::trigonRGBA                ALIAS     "gfx_trigonRGBA"                LIB  "gfx"
  55. DECLARE SUB    ::aatrigonColor             ALIAS     "gfx_aatrigonColor"             LIB  "gfx"
  56. DECLARE SUB    ::aatrigonRGBA              ALIAS     "gfx_aatrigonRGBA"              LIB  "gfx"
  57. DECLARE SUB    ::filledTrigonColor         ALIAS     "gfx_filledTrigonColor"         LIB  "gfx"
  58. DECLARE SUB    ::filledTrigonRGBA          ALIAS     "gfx_filledTrigonRGBA"          LIB  "gfx"
  59. DECLARE SUB    ::polygonColor              ALIAS     "gfx_polygonColor"              LIB  "gfx"
  60. DECLARE SUB    ::polygonRGBA               ALIAS     "gfx_polygonRGBA"               LIB  "gfx"
  61. DECLARE SUB    ::aapolygonColor            ALIAS     "gfx_aapolygonColor"            LIB  "gfx"
  62. DECLARE SUB    ::aapolygonRGBA             ALIAS     "gfx_aapolygonRGBA"             LIB  "gfx"
  63. DECLARE SUB    ::filledPolygonColor        ALIAS     "gfx_filledPolygonColor"        LIB  "gfx"
  64. DECLARE SUB    ::filledPolygonRGBA         ALIAS     "gfx_filledPolygonRGBA"         LIB  "gfx"
  65. DECLARE SUB    ::texturedPolygon           ALIAS     "gfx_texturedPolygon"           LIB  "gfx"
  66. DECLARE SUB    ::bezierColor               ALIAS     "gfx_bezierColor"               LIB  "gfx"
  67. DECLARE SUB    ::bezierRGBA                ALIAS     "gfx_bezierRGBA"                LIB  "gfx"
  68. DECLARE SUB    ::SetFont                   ALIAS     "gfx_SetFont"                   LIB  "gfx"
  69. DECLARE SUB    ::FontRotation              ALIAS     "gfx_FontRotation"              LIB  "gfx"
  70. DECLARE SUB    ::characterColor            ALIAS     "gfx_characterColor"            LIB  "gfx"
  71. DECLARE SUB    ::characterRGBA             ALIAS     "gfx_characterRGBA"             LIB  "gfx"
  72. DECLARE SUB    ::stringColor               ALIAS     "gfx_stringColor"               LIB  "gfx"
  73. DECLARE SUB    ::stringRGBA                ALIAS     "gfx_stringRGBA"                LIB  "gfx"
  74. DECLARE SUB    ::SDL_initFramerate         ALIAS     "gfx_SDL_initFramerate"         LIB  "gfx"
  75. DECLARE SUB    ::SDL_getFramerate          ALIAS     "gfx_SDL_getFramerate"          LIB  "gfx"
  76. DECLARE SUB    ::SDL_setFramerate          ALIAS     "gfx_SDL_setFramerate"          LIB  "gfx"
  77. DECLARE SUB    ::SDL_framerateDelay        ALIAS     "gfx_SDL_framerateDelay"        LIB  "gfx"
  78. DECLARE SUB    ::CreateSurface             ALIAS     "gfx_CreateSurface"             LIB  "gfx"
  79. DECLARE SUB    ::FreeSurface               ALIAS     "gfx_FreeSurface"               LIB  "gfx"
  80. DECLARE SUB    ::BlitSurface               ALIAS     "gfx_BlitSurface"               LIB  "gfx"
  81. DECLARE SUB    ::LoadBMP                   ALIAS     "gfx_LoadBMP"                   LIB  "gfx"
  82.  
  83. END MODULE
  84.  

The following keyboard and mouse functions are available for polling and waiting for events.

  • gfx_Mouse(0) - Waits for mouse movement and returns X position.
  • gfx_Mouse(1) - Waits for mouse movement and returns Y position.
  • gfx_Mouse(2) - Polls for a mouse button press event and returns.
  • gfx_Mouse(3) - Waits for a mouse button to be pressed then returns.
  • gfx_GetKey(0) - Polls for a key press event and returns a unicode value
  • gfx_GetKey(1) - Waits for a key to be pressed then returns a unicode value
  • gfx_GetKey(2) - Polls for a key press event and returns a keycode value
  • gfx_GetKey(3) - Waits for a key to be pressed then returns a keycode value
  • gfx_GetKey(4) - Polls for a key press event and returns a scancode value
  • gfx_GetKey(5) - Waits for a key to be pressed then returns a scancode value
  • gfx_KeyName(0) - (not new) Polls for key up/down events and returns the key name with a +=dn / -=up prefix
  • gfx_KeyName(1) - (not new) Waits for a key up/down event and returns the key name with a +=dn / -=up prefix
  • gfx_ClearScreen(n) - Clears the screen with the passed (n) color value in the format of 0xRRGGBB



Here is an example of typing abc<left shift hold>ABC<ESC> for each of the gfx_GetKey(n) modes.

UNICODE
jrs@laptop:~/sb/sb22/sdl$ scriba getkey.sb
Unicode: 97 Character: a
Unicode: 98 Character: b
Unicode: 99 Character: c
Unicode: 0 Character:
Unicode: 65 Character: A
Unicode: 66 Character: B
Unicode: 67 Character: C
Unicode: 27 Character: 
jrs@laptop:~/sb/sb22/sdl$

KeyCode
jrs@laptop:~/sb/sb22/sdl$ scriba getkey.sb
Keycode: 97 Character: a
Keycode: 98 Character: b
Keycode: 99 Character: c
Keycode: 304 Character: 0
Keycode: 97 Character: a
Keycode: 98 Character: b
Keycode: 99 Character: c
Keycode: 27 Character: 
jrs@laptop:~/sb/sb22/sdl$

ScanCode
jrs@laptop:~/sb/sb22/sdl$ scriba getkey.sb
Scancode: 38 Character: &
Scancode: 56 Character: 8
Scancode: 54 Character: 6
Scancode: 50 Character: 2
Scancode: 38 Character: &
Scancode: 56 Character: 8
Scancode: 54 Character: 6
Scancode: 9 Character:
jrs@laptop:~/sb/sb22/sdl$

gfx_KeyName (SDL_GetKeyName +keydown | -keyup)
jrs@laptop:~/sb/sb22/sdl$ scriba getkey.sb
Key Name: +a
Key Name: -a
Key Name: +b
Key Name: -b
Key Name: +c
Key Name: -c
Key Name: +left shift
Key Name: +a
Key Name: -a
Key Name: +b
Key Name: -b
Key Name: +c
Key Name: -c
Key Name: -left shift
Key Name: +escape
Key Name: -escape
jrs@laptop:~/sb/sb22/sdl$

287
Here is a peek at the ScriptBasic SDL extension module as it stands with the new BBC BASIC graphics extensions. It's written in a combination of SB & C BASIC macros and defines. The completed SDL extension module along with the IUP extension module will be part of the ScriptBasic 2.2 release.

This example is using the BBC Basic and SDL_draw libraries to render the example. The BBC library gives the SDL_draw library clipping features not present when used alone.



Code: [Select]
' UFO

DECLARE SUB BBC_OPEN ALIAS "BBC_init_screen" LIB "sdl"
DECLARE SUB BBC_MODE ALIAS "BBC_emulate_mode" LIB "sdl"
DECLARE SUB BBC_ORIGIN ALIAS "BBC_emulate_origin" LIB "sdl"
DECLARE SUB BBC_GCOL ALIAS "BBC_emulate_gcol" LIB "sdl"
DECLARE SUB BBC_OFF ALIAS "BBC_emulate_off" LIB "sdl"
DECLARE SUB BBC_PLOT ALIAS "BBC_emulate_plot" LIB "sdl"
DECLARE SUB BBC_PRINT ALIAS "BBC_emulate_vdustr" LIB "sdl"
DECLARE SUB BBC_CLOSE ALIAS "BBC_end_screen" LIB "sdl"
DECLARE SUB Ticks ALIAS "SB_Ticks" LIB "sdl"
DECLARE SUB GETKEY ALIAS "SB_GetKey" LIB "sdl"
DECLARE SUB Draw_FillCircle ALIAS "SB_Draw_FillCircle" LIB "sdl"
DECLARE SUB RGB ALIAS "SB_RGB" LIB "sdl"
DECLARE SUB SB_OPEN ALIAS "SB_Window" LIB "sdl"
DECLARE SUB SB_UPDATESCR ALIAS "SB_UpdateRect" LIB "sdl"

BBC_OPEN
SB_OPEN 800,600,"BBC & SDL_draw"
t1 = Ticks()
BBC_MODE 31
BBC_ORIGIN 800,600
XS=2
YS=2
BBC_GCOL 0,14
BBC_OFF
A=700
B=A*A
C=600
FOR X=0 TO A STEP XS
  S=X*X
  P=SQR(B-S)
  FOR I=-P TO P STEP 6*YS
    R=SQR(S+I*I)/A
    Q=(R-1)*SIN(24*R)
    Y=INT(I/3+Q*C)
    IF I=-P THEN
      M=Y
      N=Y
    END IF
    IF Y>M THEN M=Y
    IF Y<N THEN N=Y
    IF M=Y OR N=Y THEN
      BBC_PLOT 69,NOT(x),y
      BBC_PLOT 69,X,Y
    END IF
  NEXT
NEXT
Draw_FillCircle 400, 0, 30, RGB(32, 255, 255)
SB_UPDATESCR
BBC_OFF
t2 = Ticks()
t3 = (t2-t1)/1000
BBC_PRINT "Time: " & FORMAT("%.4f",t3) & " seconds"
WHILE GETKEY() <> "-escape"
WEND
BBC_CLOSE



Code: [Select]
' Fern

DECLARE SUB BBC_OPEN ALIAS "BBC_init_screen" LIB "sdl"
DECLARE SUB BBC_MODE ALIAS "BBC_emulate_mode" LIB "sdl"
DECLARE SUB BBC_ORIGIN ALIAS "BBC_emulate_origin" LIB "sdl"
DECLARE SUB BBC_GCOL ALIAS "BBC_emulate_gcol" LIB "sdl"
DECLARE SUB BBC_OFF ALIAS "BBC_emulate_off" LIB "sdl"
DECLARE SUB BBC_DRAW ALIAS "BBC_emulate_draw" LIB "sdl"
DECLARE SUB BBC_MOVE ALIAS "BBC_emulate_move" LIB "sdl"
DECLARE SUB BBC_PRINT ALIAS "BBC_emulate_vdustr" LIB "sdl"
DECLARE SUB BBC_CLOSE ALIAS "BBC_end_screen" LIB "sdl"
DECLARE SUB Ticks ALIAS "SB_Ticks" LIB "sdl"
DECLARE SUB BBC_RND ALIAS "BBC_RND" LIB "sdl"
DECLARE SUB GETKEY ALIAS "SB_GetKey" LIB "sdl"

BBC_OPEN
t1 = Ticks()
BBC_MODE 31
BBC_ORIGIN 200,100
BBC_OFF
BBC_GCOL 0,10
x=0
y=0
FOR i=1 TO 80000
  r = BBC_RND(1)
  IF r<=0.1 THEN
    A=0
    B=0
    C=0
    D=0.16
    E=0
    F=0
  END IF
  IF r>0.1 AND r<=0.86 THEN
    A=.85
    B=.04
    C=-.04
    D=.85
    E=0
    F=1.6
  END IF
  IF r>0.86 AND r<=0.93 THEN
    A=.2
    B=-.26
    C=.23
    D=.22
    E=0
    F=1.6
  END IF
  IF r>0.93 THEN
    A=-.15
    B =.28
    C=.26
    D=.24
    E=0
    F=.44
  END IF
  newx=A*x+B*y+E
  newy=C*x+D*y+F
  x=newx
  y=newy
  BBC_MOVE 600+96*x, 32+96*y
  BBC_DRAW 600+96*x, 32+96*y
NEXT i
t2 = Ticks()
t3 = (t2-t1)/1000
BBC_PRINT "Time: " & FORMAT("%.4f",t3) & " seconds"
WHILE GETKEY() <> "-escape"
WEND
BBC_CLOSE



Code: [Select]
' Graph Demo

DECLARE SUB BBC_OPEN ALIAS "BBC_init_screen" LIB "sdl"
DECLARE SUB BBC_MODE ALIAS "BBC_emulate_mode" LIB "sdl"
DECLARE SUB BBC_ORIGIN ALIAS "BBC_emulate_origin" LIB "sdl"
DECLARE SUB BBC_DRAW ALIAS "BBC_emulate_draw" LIB "sdl"
DECLARE SUB BBC_MOVE ALIAS "BBC_emulate_move" LIB "sdl"
DECLARE SUB BBC_CLOSE ALIAS "BBC_end_screen" LIB "sdl"
DECLARE SUB WAITKEY ALIAS "SB_WaitKey" LIB "sdl"

BBC_OPEN
BBC_MODE 31
BBC_ORIGIN 800, 600
xlow = -10
xhigh = 10
ylow = -10
yhigh = 10
depth = 10
xscale = 30
yscale = 12
c = -4000

FOR x = xlow TO xhigh
  BBC_MOVE xscale*(x+ylow), yscale*(ylow-x)+c/(x*x+ylow*ylow+depth)
  FOR y = ylow TO yhigh
    BBC_DRAW xscale*(x+y), yscale*(y-x)+c/(x*x+y*y+depth)
  NEXT
NEXT
FOR y = ylow TO yhigh
  BBC_MOVE xscale*(xlow+y), yscale*(y-xlow)+c/(xlow*xlow+y*y+depth)
  FOR x = xlow TO xhigh
    BBC_DRAW xscale*(x+y), yscale*(y-x)+c/(x*x+y*y+depth)
  NEXT
NEXT
WAITKEY
BBC_CLOSE

The following example was used as a benchmark (1000 iterations) of a random polygon generation loop. To see comparative results, visit the All BASIC Developer forum.




Code: [Select]
' Polygon

DECLARE SUB BBC_OPEN ALIAS "BBC_init_screen" LIB "sdl"
DECLARE SUB BBC_MODE ALIAS "BBC_emulate_mode" LIB "sdl"
DECLARE SUB BBC_NEWMODE ALIAS "BBC_emulate_newmode" LIB "sdl"
DECLARE SUB BBC_ORIGIN ALIAS "BBC_emulate_origin" LIB "sdl"
DECLARE SUB BBC_GCOL ALIAS "BBC_emulate_gcol" LIB "sdl"
DECLARE SUB BBC_OFF ALIAS "BBC_emulate_off" LIB "sdl"
DECLARE SUB BBC_PLOT ALIAS "BBC_emulate_plot" LIB "sdl"
DECLARE SUB BBC_DRAW ALIAS "BBC_emulate_draw" LIB "sdl"
DECLARE SUB BBC_MOVE ALIAS "BBC_emulate_move" LIB "sdl"
DECLARE SUB BBC_PRINT ALIAS "BBC_emulate_vdustr" LIB "sdl"
DECLARE SUB BBC_CLOSE ALIAS "BBC_end_screen" LIB "sdl"
DECLARE SUB Ticks ALIAS "SB_Ticks" LIB "sdl"
DECLARE SUB BBC_RND ALIAS "BBC_RND" LIB "sdl"
DECLARE SUB GETKEY ALIAS "SB_GetKey" LIB "sdl"
DECLARE SUB SHIFTLT ALIAS "SB_SHIFTLT" LIB "sdl"
DECLARE SUB BBC_VDU ALIAS "BBC_emulate_vdu" LIB "sdl"
DECLARE SUB BBC_VDUFN ALIAS "BBC_emulate_vdufn" LIB "sdl"
DECLARE SUB SB_OPEN ALIAS "SB_Window" LIB "sdl"

BBC_OPEN
SB_OPEN 800,600,"ScriptBasic Polygon using BBC graphics"
t1 = Ticks()
BBC_NEWMODE 800,600,32,-1
BBC_VDU 26
Width = 800
Height = 600
SPLITA STRING(11,"0") BY "" TO X
SPLITA STRING(11,"0") BY "" TO Y
FOR i = 1 TO 1000
  count += 1
' xorigin = BBC_RND(640 * 2)
' yorigin = BBC_RND(512 * 2)
  xorigin = BBC_RND(1250)
  yorigin = BBC_RND(840)
  Radius = BBC_RND(300) + 50
  BBC_ORIGIN xorigin, yorigin  
  sides = BBC_RND(8) + 2
  BBC_MOVE Radius, 0
  BBC_MOVE 10, 10
  C = BBC_RND(64) - 1
  T = SHIFTLT((BBC_RND(4)-1), 6)
  BBC_GCOL 0,C, T
  FOR SIDE = 1 TO sides
    angle = (SIDE-1) * 2 * PI / sides
    X[SIDE] = Radius * COS(angle)
    Y[SIDE] = Radius * SIN(angle)
    BBC_MOVE 0, 0
    BBC_PLOT 85,X[SIDE],Y[SIDE]
  NEXT SIDE
  BBC_MOVE 0, 0
  BBC_PLOT 85, Radius, 0
  REPEAT
    D=BBC_RND(64) - 1
  UNTIL (D AND 63)<>(C AND 6)
  BBC_GCOL 0,D, T
  FOR SIDE = 1 TO sides
    FOR L = SIDE TO sides
      BBC_MOVE X[SIDE], Y[SIDE]
      BBC_DRAW X[L], Y[L]
    NEXT L
  NEXT SIDE
NEXT i
t2 = Ticks()
t3 = (t2-t1)/1000
BBC_PRINT "Time: " & FORMAT("%.4f",t3) & " seconds"
WHILE GETKEY() <> "-escape"
WEND
BBC_CLOSE

288
General Discussions / Re: just a very stupid question
« on: January 01, 2014, 11:58:35 AM »
ScriptBasic has no command line option.

You seem to be talking about the shell (bash, sh, ...) you are using to run a ScriptBasic script.

I use Ubuntu standard terminal. If I want to copy something from the screen and paste it at the prompt to execute, I first select the text I want with the mouse, right click on it and select copy. I then immediately right click again and select paste which inserts it at the current command prompt ready for execution.

 

289
What's New / Re: ScriptBasic 32 Bit Linux
« on: December 31, 2013, 10:18:55 AM »
Hi Fred,

Quote
When I run the scriba deb ...

There is no ScriptBasic 2.2 .deb available. The above SB 2.1 (.deb / .rpm) versions is using 2006 based code (Peter's last release) and is no longer supported.

Can you give me more details about trying the SDL extension module and your problems with MySQL? (after installing the current Ubuntu or Debian SB 2.2 version)

John

290
What's New / Re: ScriptBasic 32 bit Windows
« on: December 31, 2013, 10:16:17 AM »
I use the 32 bit version of scriba under Wine all the time. What issues are you having?

291
What's New / Re: ScriptBasic SDL extension module
« on: December 28, 2013, 12:03:48 PM »
I have added a GetKey() function to the ScriptBasic SDL extension module. The GetKey function returns both keydown (+) and keyup (-) events. The capslock and numlock keys act as toggles. (+ = On, - = Off) Here is a list of the returned key names beyond the single character keys you would expect.

Code: [Select]
left alt
left ctrl
left shift
left super
tab
escape
f1
f2
f3
f4
f5
f6
f7
f8
f9
f10
f11
f12
up
down
left
right
insert
delete
end
page down
page up
home
scroll lock
pause
right ctrl
right alt
right shift
return
backspace
space
numlock
[/]
[*]
[-]
[7]
[8]
[9]
[4]
[5]
[6]
[1]
[2]
[3]
[0]
[.]
[+]
enter

Example
Code: [Select]
DECLARE SUB Window ALIAS "SB_Window" LIB "sdl"
DECLARE SUB GetKey ALIAS "SB_GetKey" LIB "sdl"

Window 100,75

NextKey:
k = GetKey()
PRINT k,"\n"
GOTO NextKey

jrs@laptop:~/sb/sb22/sdl$ scriba getkey.sb
+a
-a
+left shift
+a
-a
-left shift
jrs@laptop:~/sb/sb22/sdl$

In the above example the a key is pressed and released. The next time the left shift key is pressed and held down while the a key is pressed. The a key is then release as is the left shift key.



292
What's New / Re: ScriptBasic SDL extension module
« on: December 23, 2013, 08:22:27 PM »
The following is the ScriptBasic SDL extension module functions I have included to date. These functions may be an ALIAS to whatever name you would like to use in your ScriptBasic program. I'll update this list as I have time to work on it.

Code: [Select]
SB_Window
SB_RGB
SB_WaitKey
SB_Ticks
SB_UpdateRect
SB_CLS
SB_Draw_Pixel
SB_Draw_Line
SB_Draw_Circle
SB_Draw_FillCircle
SB_Draw_HLine
SB_Draw_VLine
SB_Draw_Rect
SB_Draw_FillRect
SB_Draw_Ellipse
SB_Draw_FillEllipse
SB_Draw_Round
SB_Draw_FillRound
SB_CreateTerminal
SB_DestroyTerminal
SB_TerminalBlit
SB_TerminalRefresh
SB_TerminalClear
SB_TerminalPrint
SB_TerminalPrintAt
SB_TerminalReset
SB_TerminalSetFont
SB_TerminalSetSize
SB_TerminalSetPosition
SB_TerminalSetColor
SB_TerminalSetBorderColor
SB_TerminalSetBorderSize
SB_TerminalSetDefaultForeground
SB_TerminalSetDefaultBackground
SB_TerminalSetForeground
SB_TerminalSetBackground
SB_TerminalEnableBold
SB_TerminalEnableUnderline
SB_TerminalEnableItalic
SB_TerminalDisableBold
SB_TerminalDisableUnderline
SB_TerminalDisableItalic
SB_TerminalProcessEvent

293
What's New / Re: ScriptBasic SDL extension module
« on: December 23, 2013, 03:28:08 AM »
I've added terminal support to the ScriptBasic SDL extension module. I have posted as couple more advanced examples HERE.



Code: [Select]
' ScriptBasic Peacock

DECLARE SUB Window ALIAS "SB_Window" LIB "sdl"
DECLARE SUB WaitKey ALIAS "SB_WaitKey" LIB "sdl"
DECLARE SUB Ticks ALIAS "SB_Ticks" LIB "sdl"
DECLARE SUB UpdateRect ALIAS "SB_UpdateRect" LIB "sdl"
DECLARE SUB Draw_Line ALIAS "SB_Draw_Line" LIB "sdl"
DECLARE SUB CreateTerm ALIAS "SB_CreateTerminal" LIB "sdl"
DECLARE SUB TermSize ALIAS "SB_TerminalSetSize" LIB "sdl"
DECLARE SUB TermPrint ALIAS "SB_TerminalPrint" LIB "sdl"
DECLARE SUB TermShow ALIAS "SB_TerminalBlit" LIB "sdl"
DECLARE SUB TermPosition ALIAS "SB_TerminalSetPosition" LIB "sdl"
DECLARE SUB TermFont ALIAS "SB_TerminalSetFont" LIB "sdl"
DECLARE SUB TermSetColor ALIAS "SB_TerminalSetColor" LIB "sdl"
DECLARE SUB TermBorderColor ALIAS "SB_TerminalSetBorderColor" LIB "sdl"
DECLARE SUB FGColor ALIAS "SB_TerminalSetForeground" LIB "sdl"
DECLARE SUB BGColor ALIAS "SB_TerminalSetBackground" LIB "sdl"
DECLARE SUB TermClear ALIAS "SB_TerminalClear" LIB "sdl"

Window 700, 500, "Peacock Plume"
q = 1
q1 = 0.9997
v = 0.01
vv = 0.0004
xs = 750
ys = 730
xm = 650
ym = 180
br = -0.7393
bi = 0.117
ar = 0.0
ai = 0.0
_cos = cos(0.01)
_sin = sin(0.01)
t1 = Ticks()
FOR d = 1 TO 15000
  tr = ar * ar - ai * ai + br
  ti = 2 * ar * ai + bi
  x  = tr * xs + xm
  y  = ti * ys + ym
  v  = v + vv
  q  = q * q1
  c  = d ^ 2.1
  Draw_Line x, y, x + (_cos * 50 * q), y + (_sin * 50 * q), c
  ar = tr
  ai = ti
NEXT
t2 = Ticks()
t3 = (t2 - t1) / 1000
CreateTerm
TermFont "./VeraMono.ttf", 12
TermSize 40, 2
TermPosition 10, 450
TermSetColor 0, 0, 0, 0
TermBorderColor 0, 0, 0, 0
FGColor 255,255,255,255
BGColor 0,0,0,0
TermClear
TermPrint FORMAT("%.4f", t3) & " Seconds\n"
TermPrint STR(d-1) & " Lines Drawn"
TermShow
UpdateRect
WaitKey


Here is an example of the SDL_image addition to the ScriptBasic SDL extension module.



Code: [Select]
' ScriptBasic SDL Image

DECLARE SUB Window ALIAS "SB_Window" LIB "sdl"
DECLARE SUB WaitKey ALIAS "SB_WaitKey" LIB "sdl"
DECLARE SUB LoadImage ALIAS "SB_LoadImage" LIB "sdl"
DECLARE SUB ShowImage ALIAS "SB_ShowImage" LIB "sdl"
DECLARE SUB UpdateRect ALIAS "SB_UpdateRect" LIB "sdl"

Window 400, 300, "ScriptBasic SDL Image"
img = LoadImage("sblogo.gif")
ShowImage img, 100, 75
UpdateRect
WaitKey

294
What's New / ScriptBasic SDL extension module
« on: December 21, 2013, 09:11:58 PM »
I have created a SDL extension module for drawing 2D graphic primitives. I plan to expand of the SDL extension module with sprites, a terminal and other SDL related API functions. I hope to have the SDL extension module completed for the ScriptBasic 2.2 release.



Code: [Select]
' ScriptBasic SDL_Draw Example

DECLARE SUB Window ALIAS "SB_Window" LIB "sdl"
DECLARE SUB RGB ALIAS "SB_RGB" LIB "sdl"
DECLARE SUB WaitKey ALIAS "SB_WaitKey" LIB "sdl"
DECLARE SUB Ticks ALIAS "SB_Ticks" LIB "sdl"
DECLARE SUB UpdateRect ALIAS "SB_UpdateRect" LIB "sdl"
DECLARE SUB CLS ALIAS "SB_CLS" LIB "sdl"
DECLARE SUB Draw_Pixel ALIAS "SB_Draw_Pixel" LIB "sdl"
DECLARE SUB Draw_Line ALIAS "SB_Draw_Line" LIB "sdl"
DECLARE SUB Draw_Circle ALIAS "SB_Draw_Circle" LIB "sdl"
DECLARE SUB Draw_FillCircle ALIAS "SB_Draw_FillCircle" LIB "sdl"
DECLARE SUB Draw_HLine ALIAS "SB_Draw_HLine" LIB "sdl"
DECLARE SUB Draw_VLine ALIAS "SB_Draw_VLine" LIB "sdl"
DECLARE SUB Draw_Rect ALIAS "SB_Draw_Rect" LIB "sdl"
DECLARE SUB Draw_FillRect ALIAS "SB_Draw_FillRect" LIB "sdl"
DECLARE SUB Draw_Ellipse ALIAS "SB_Draw_Ellipse" LIB "sdl"
DECLARE SUB Draw_FillEllipse ALIAS "SB_Draw_FillEllipse" LIB "sdl"
DECLARE SUB Draw_Round ALIAS "SB_Draw_Round" LIB "sdl"
DECLARE SUB Draw_FillRound ALIAS "SB_Draw_FillRound" LIB "sdl"

Window(640, 480, "ScriptBasic SDL_Draw Example")
c_white = RGB(255, 255, 255)
c_gray = RGB(200, 200, 200)
c_dgray = RGB(64, 64, 64)
c_cyan = RGB(32, 255, 255)
Draw_Line(100, 100, 30, 0, c_white)
Draw_Line(30, 0, 100, 100, c_white)
Draw_Line(100, 100, 30, 0, c_white)
Draw_Line(30, 0, 100, 100, c_white)
Draw_Line(0, 0, 100, 100, c_white)
Draw_Line(100, 100, 300, 200, c_white)
Draw_Line(200, 300, 250, 400, RGB(128, 128, 255))
Draw_Line(500, 50, 600, 70, RGB(128, 255, 128))
Draw_Line(500, 50, 600, 70, RGB(128, 255, 128))
Draw_Circle(100, 100, 50, c_white)
Draw_Circle(150, 150, 5, c_white)
Draw_Circle(150, 150, 4, RGB(64, 64, 64))
Draw_Circle(150, 150, 3, RGB(255, 0, 0))
Draw_Circle(150, 150, 2, RGB(0, 255, 0))
Draw_Circle(150, 150, 1, RGB(0, 0, 255))
Draw_Line(500, 100, 600, 120, RGB(128, 255, 128))
Draw_Circle(601, 121, 2, c_white)
Draw_Circle(400, 200, 2, c_white)
Draw_Line(400, 200, 409, 200, c_white)
Draw_Circle(409, 200, 2, c_white)
Draw_Line(400, 200, 400, 250, c_white)
Draw_Circle(400, 250, 2, c_white)
Draw_Line(409, 200, 400, 250, c_white)
Draw_Line(400, 300, 409, 300, c_gray)
Draw_Line(400, 300, 400, 350, c_gray)
Draw_Line(409,300, 400, 350, c_dgray)
Draw_Rect(398, 298, 4, 4, c_cyan)
Draw_Rect(407, 298, 4, 4, c_cyan)
Draw_Rect(398, 348, 4, 4, c_cyan)
Draw_HLine(10, 400, 50, c_white)
Draw_VLine(60, 400, 360, c_white)
Draw_Rect(500, 400, 50, 50, c_white)
Draw_Pixel(510, 410, c_white)
Draw_Pixel(520, 420, RGB(255, 0, 0))
Draw_Pixel(530, 430, RGB(0, 255, 0))
Draw_Pixel(540,440, RGB(0, 0, 255))
Draw_Ellipse(100, 300, 60, 30, c_white)
Draw_FillEllipse(300, 300, 30, 60, RGB(64, 64, 200))
Draw_Ellipse(300, 300, 30, 60, RGB(255, 0, 0))
Draw_Round(200, 20, 70, 50, 10, c_white)
Draw_Round(300, 20, 70, 50, 20, RGB(255, 0, 0))
Draw_FillRound(390, 20, 70, 50, 20, RGB(255, 0, 0))
Draw_Round(390, 20, 70, 50, 20, c_cyan)
Draw_Rect(499, 199, 52, 72, RGB(255, 255, 0))
Draw_FillRect(500, 200, 50, 70, RGB(64, 200, 64))
Draw_FillCircle(500, 330, 30, c_cyan)
  
UpdateRect

WaitKey



Code: [Select]
' ScriptBasic Circle

DECLARE SUB Window ALIAS "SB_Window" LIB "sdl"
DECLARE SUB WaitKey ALIAS "SB_WaitKey" LIB "sdl"
DECLARE SUB UpdateRect ALIAS "SB_UpdateRect" LIB "sdl"
DECLARE SUB RGB ALIAS "SB_RGB" LIB "sdl"
DECLARE SUB CLS ALIAS "SB_CLS" LIB "sdl"
DECLARE SUB Draw_Circle ALIAS "SB_Draw_Circle" LIB "sdl"

Window 800, 600, "ScriptBasic Circle"
w = 400
h = 300
CLS(RGB(255, 255, 255))
black = RGB(0, 0, 0)
FOR i = 0 TO 130 STEP 10
  Draw_Circle w - i, h + i, i, black
  Draw_Circle w + i, h - i, i, black
  Draw_Circle w + i, h + i, i, black
  Draw_Circle w - i, h - i, i, black
NEXT
UpdateRect
WaitKey

295
Source / Re: ScriptBasic bug
« on: October 18, 2013, 09:40:12 PM »
Hi Ron,

Attached is the string.c with Peter's correction.


296
I found my first ScriptBasic bug after managing the project since 2006. It even surprised Peter that no one discovered it before. The fix was easy and based on the reminder / warning comment in the old version of the code Peter left, it was something I think he had plans to come back to. I was going to include this fix as part of the next ScriptBasic 2.2 Build 2 release candidate but the fix was needed now for the BAS2NIM project as it will use LIKE/JOKER extensively.

Quote from: Peter Verhas
Matching with jokers has a serious flaw in the core ScriptBasic. To fix that the file commands/string.c has to be modified.

Code: [Select]
$ diff commands/string.c ../commands/string.c
2329a2330
>
2331,2337c2332,2335
<     }else{
<     /* If the array is long enough then delete the previous result otherwise
<        fake data may remain in it and it may cause trouble. */
<     for( i=0 ; i < pLastResult->cArraySize ; i++ ){
<       pLastResult->pcbParameterArray[i] = 0;
<       pLastResult->ParameterArray[i] = NULL;
<       }
---
>     }
>   for( i=0 ; i < pLastResult->cArraySize ; i++ ){
>     pLastResult->pcbParameterArray[i] = 0;
>     pLastResult->ParameterArray[i] = NULL;

It is simply removing the "else" from the code and this way the ParameterArray variables always get NULLified.

This code originally assumed that even if there is some garbage in this array that will never be accessed, because the algorithm calculates the number of joker characters in the pattern and if any JOKER(N) call is made with a large N then it fill return undef by default, because the code recognized the over indexing.

However in the example above there are special joker characters, namely <, > and / that are configured not to be joker characters by default and they are also not activated using the SET JOKER command. They are calculated and the code comes to the conclusion that there are 6 joker characters. In reality there are only two when the matching is done and the array indexes from 2 to 5 remain garbage, but still accessible. Setting them explicitly NULL before the matching takes place will force them to be undef. Although this "undef" is not because of over indexing in the C level code there is no difference on the BASIC level.

--
Dipl. Ing. Peter Verhas
 

297
What's New / Re: ScriptBasic LiveDev
« on: October 04, 2013, 10:50:36 AM »
ScriptBasic 2.2 CentOS 64 bit (Red Hat clone) runs great on CompileOnline.com. If someone is curious if SB can fill their needs, this is a great way to find out.


298
What's New / Re: ScriptBasic LiveDev
« on: October 03, 2013, 08:53:50 AM »
It looks like Cloud9 IDE isn't as robust as I thought and is more restrictive than developing on a non-rooted Android device .  :-\ I would say it's more tailored for web scripting development than language development.

The CompileOnline.com option is the best way to try ScriptBasic before downloading a copy for yourself.


299
What's New / ScriptBasic LiveDev
« on: October 02, 2013, 01:40:43 PM »
ScriptBasic developers and advocates,

I have setup a Cloud9 IDE online development interface for the ScriptBasic project. I currently have the ScriptBasic 2.2 runtime environment working and plan a source code workspace with a Github interface. (stay tuned for announcement)

Here is the runtime project site and you need at least a FREE membership to Cloud9 IDE for access. Leave me a message here with your C9IDE user ID that you would like R/W access and ability to create example programs and test the SB 2.2 pre-release.

https://c9.io/scriptbasic/sb22

FYI - If your only interest is to try ScriptBasic 2.2 and don't want to sign up for Cloud9 IDE, the CompileOnline.com site gives you instance access to the ScriptBasic IDE to run your scripts without having to join a thing.

Note: CompileOnline.com only supports SQLite3 and not MySQL.






300
What's New / Re: ScriptBasic 2.2 Beta Release
« on: September 24, 2013, 09:04:50 PM »
Quote from: kryton9
John, I think scriptbasic is working for you guys because you must have had earlier built versions from source scriptbasics.

If you download the current ubuntu2.2 64 bit version zip to a clean ubuntu install(no previous scriptbasic ever) you will see the catch 22 routine with getting a basic.conf made.
scriba runs, but anything requiring additional includes no way.

But this is not only a scriptbasic issue, I am having problems installing many languages. Only luck was code::blocks and the c and c++ compilers.

These beta releases are designed to unzip where you want. There are a few steps to getting hooked into the environment.

From a console:

1. Get your environment variables set.

export PATH=/home/jrs/sb/sb22/bin:$PATH
export SCRIBACONF=/home/jrs/sb/sb22/bin/basic.conf

2. Here is my minimal basic.conf I use. (change paths to meet your setup)

Code: [Select]
dll ".so"
module "/home/jrs/sb/sb22/modules/"
include "/home/jrs/sb/sb22/include/"
maxinclude 100
preproc (
  internal (
    sdbg "/home/jrs/sb/sb22/modules/sdbg.so"
   )
 )
maxstep 0
maxlocalstep 0
maxlevel 300
maxmem 0

You can edit and recompile the basic.conf with the following scriba command line option. The result will create a binary basic.conf in the directory you pointed the environment variable SCRIBACONF to.

scriba -k your_conf_text_file

The module / include directories paths in the basic.conf file are used by the ScriptBasic extension modules so you can do a IMPORT mysql and it knows where to find things. Without these paths defined you have to used full paths in your program.  :(

That should allow you to run all the SB test programs if you have all your dependencies installed. (MySQL server/client, libcurl, unixODBC, Mini-XML)


Quote from: kryton9
Everything is a lot easier on Windows, although Ubuntu did see all my hardware better than Windows does on new installs. But for a new user, it is too confusing.
Files are everywhere and almost all are protected except for stuff in home.

 I thought one of the beauties of linux was supposed to be the packaging systems
and its ability to download all dependencies for you, but this is not the case by my testing these few days.

Linux has a GUI package installer (Synaptic) and apt-get from the console. Your a man now, put the boy toys away.  ;D

If you need root level privileges then use sudo. For example if you need to copy a library you built in your user /home/you directory structure to the system /usr/lib directory, try this.

sudo cp mylib.so /usr/lib/

It will ask for your password you assigned yourself. (assuming you gave yourself admin privileges as the default user)

if you want to remain in a root shell, use sudo su.

Use exit to exit the shell your in or close the console.

 

Quote from: kryton9
I will leave Ubuntu on the dual boot, but back to windows so I can code again.

Don't give up so easy. Learning is part of the fun. I'll catch you if you fall.  ;)


Pages: 1 ... 18 19 [20] 21 22 ... 59