Recent Posts

Pages: 1 ... 8 9 [10]
91
Programs / Re: Benchmark_01
« Last post by jack on April 10, 2022, 02:51:32 pm »
I meant no offense to you bplus, I know who came up with the code
but if you want to do a benchmark you need to do some computations that can't be optimized out and print the result for verification
92
Programs / Re: Benchmark_01
« Last post by bplus on April 10, 2022, 02:44:58 pm »
Thank you Jack! Keybonic Plague also gets way better time than I with optimized QB64 dev 2.1

I know it's lame I didn't make it up just comparing times with other PL's and Basic's.

So I didn't screw up, it's possible to get under .5 secs.
93
Programs / Re: Benchmark_01
« Last post by jack on April 10, 2022, 02:31:04 pm »
it times at .25 seconds on my PC
but as a benchmark it's lame, a good compiler will eliminate the loop entirely and therefore give a meaningless result
94
Programs / Benchmark_01
« Last post by bplus on April 10, 2022, 01:55:11 pm »
Can someone verify this code is correct and it takes under .5 secs to run, Aurel doesn't believe it.
http://basic4all.epizy.com/index.php?topic=21.0

Code: QB64: [Select]
  1. start = Timer(.001)
  2. For n = 1 To 100000000
  3.     r = n * 2 - Sin(88)
  4. Next n&
  5. Print Timer(.001) - start; "seconds"
  6.  

 
image_2022-04-10_135600031.png


BTW oddly it does better with Double than with Single default.
95
QB64 Discussion / Re: Particle System
« Last post by bplus on April 10, 2022, 01:31:12 pm »
A little translation:
Code: QB64: [Select]
  1. ' 2022-04-10 b+ translation of  http://sdlbasic.epizy.com/showthread.php?tid=235  
  2. ' ***************
  3. ' Particle System
  4. ' ***************
  5. ' maximum number of particles slots
  6. ' lower this to get more fluent effect
  7. maximum = 100
  8.  
  9. ' Each particle has 6 parameters
  10. ' 0 : location on the x-axis
  11. ' 1 : location on the y-axis
  12. ' 2 : movement on the x-axis
  13. ' 3 : movement on the y-axis
  14. ' 4 : how old the particle can get
  15. ' 5 : period where particle keeps the same color
  16. Dim particle(maximum, 6)
  17.  
  18. ' ******************************
  19. ' Boiler plate for a nice canvas
  20. ' ******************************
  21. 'setDisplay(700, 400, 32, 1)
  22. Screen _NewImage(700, 400, 32)
  23. f& = _LoadFont("Arial.ttf", 40) ' everyone has arial?
  24.  
  25. 'setCaption("Particles Example")
  26. _Title "Particles Example"
  27. 'autoback(-2)
  28. 'hidemouse
  29. Dim As _Unsigned Long darkred, red, orange, yellow, white
  30. darkred = _RGB32(128, 0, 0)
  31. red = _RGB32(255, 0, 0)
  32. orange = _RGB32(255, 128, 0)
  33. yellow = _RGB32(255, 255, 0)
  34. white = _RGB32(255, 255, 255)
  35.  
  36. ' *************************************************
  37. ' pre-cache sin/cos calculations (small speed gain)
  38. ' *************************************************
  39. Dim degree(361, 2)
  40. pi = 3.141592654
  41. k = 0
  42. For i = 0 To 2 * pi Step (2 * pi / 359)
  43.     k = k + 1
  44.     degree(k, 0) = Sin(i)
  45.     degree(k, 1) = Cos(i)
  46.  
  47. 'initialize text
  48. text_count = 0
  49. t1$ = "Particles Example"
  50. t2$ = "( Cool, isn't it? )"
  51. t3$ = "(   useless too  )"
  52. t4$ = t2$
  53. sw_text = 0
  54.  
  55. ' *************************************************
  56. ' initial particle definition: all particles 'dead'
  57. ' *************************************************
  58. For i = 0 To maximum - 1
  59.     particle(i, 4) = 0
  60.  
  61. '**************************************************
  62. ' main loop
  63. '**************************************************
  64. While _KeyDown(27) = 0
  65.     Cls
  66.     ' create new particles
  67.     ' ********************
  68.     ' select 7 random particles at each cycle
  69.     ' play with this value to get the best result on your computer
  70.     For k = 1 To 7
  71.         spawni = rand(maximum)
  72.  
  73.         ' if age of the random particle = 0, create one
  74.         If particle(spawni, 4) = 0 Then
  75.  
  76.             ' horizontal location
  77.             If rand(100) / 100 > 0.5 Then
  78.                 particle(spawni, 0) = 20
  79.                 lings = 1
  80.             Else
  81.                 particle(spawni, 0) = 660
  82.                 lings = 0
  83.             End If
  84.  
  85.             ' vertical location
  86.             particle(spawni, 1) = 350
  87.             direction = rand(35) + 157
  88.  
  89.             ' horizontal speed vector
  90.             If lings = 1 Then
  91.                 particle(spawni, 2) = rand(6)
  92.             Else
  93.                 particle(spawni, 2) = 0 - (rand(6))
  94.             End If
  95.  
  96.             ' falling speed vector
  97.             particle(spawni, 3) = (0 - rand(6)) - 5
  98.  
  99.             ' particle age
  100.             particle(spawni, 4) = 30 + rand(50)
  101.  
  102.             ' color aging
  103.             particle(spawni, 5) = particle(spawni, 4) / 5
  104.         End If
  105.     Next
  106.  
  107.     ' update position on ALL live particles
  108.     ' *************************************
  109.     For i = 0 To maximum - 1
  110.  
  111.         ' for all live particles
  112.         If particle(i, 4) > 0 Then
  113.  
  114.             ' calculate the new location
  115.             particle(i, 0) = particle(i, 0) + particle(i, 2)
  116.             particle(i, 1) = particle(i, 1) + particle(i, 3)
  117.  
  118.             ' increase the speed of falling
  119.             particle(i, 3) = particle(i, 3) + (rand(100) / 100) / 3
  120.  
  121.             ' make the particle older
  122.             particle(i, 4) = particle(i, 4) - 1
  123.  
  124.             ' if it hits the bottom, make it bounce up
  125.             ' 0=no bounce, 1= full bounce,no damping
  126.             If particle(i, 1) > 370 Then
  127.                 particle(i, 3) = -particle(i, 3) * ((rand(100) / 100) / 2)
  128.             End If
  129.         End If
  130.     Next
  131.  
  132.     ' Color determination of the particle
  133.     '************************************
  134.     For i = 0 To maximum - 1
  135.  
  136.         ' for all live particles
  137.         If particle(i, 4) > 0 Then
  138.  
  139.             ' color it darkred if less than 20% life left
  140.             If particle(i, 4) < particle(i, 5) Then
  141.                 k = darkred
  142.             End If
  143.  
  144.             ' color it red if more than 20% life left
  145.             If particle(i, 4) > (particle(i, 5)) Then
  146.                 k = red
  147.             End If
  148.  
  149.             ' color it orange if more than 40% life left
  150.             If particle(i, 4) > (particle(i, 5) * 2) Then
  151.                 k = orange
  152.             End If
  153.  
  154.             ' color it yellow if more than 60% life left
  155.             If particle(i, 4) > (particle(i, 5) * 3) Then
  156.                 k = yellow
  157.             End If
  158.  
  159.             ' color it white if more than 80% life left
  160.             If particle(i, 4) > (particle(i, 5) * 4) Then
  161.                 k = white
  162.             End If
  163.  
  164.  
  165.             '----------------------------
  166.             ' PLOT ALL THE LIVE PARTICLES
  167.             '----------------------------
  168.  
  169.  
  170.             '--- circles ---
  171.             'circle(particle(i,0), particle(i,1), 2+rand(4))
  172.             '--- filled circles ---
  173.             'fillcircle(particle(i,0), particle(i,1), 2+rand(4))
  174.             '--- squares ---
  175.             'polyline(particle(i,0), particle(i,1), particle(i,0)+6, particle(i,1), particle(i,0)+6, particle(i,1)+6, particle(i,0), particle(i,1)+6, particle(i,0), particle(i,1))
  176.             '--- stars ---
  177.             'polyline(particle(i,0)+4, particle(i,1), particle(i,0)+8, particle(i,1)+12, particle(i,0), particle(i,1)+4, particle(i,0)+12, particle(i,1)+4, particle(i,0)+2, particle(i,1)+12)
  178.              star particle(i, 0), particle(i, 1), 8, 20, 5, 90, k
  179.             '--- polygon seems to 'lock-up' ---
  180.             'polygon(particle(i,0), particle(i,1), particle(i,0)+6, particle(i,1), particle(i,0)+6, particle(i,1)+6, particle(i,0), particle(i,1)+6, particle(i,0), particle(i,1))
  181.             '--- filled squares ---
  182.             'bar(particle(i,0), particle(i,1), particle(i,0)+2+rand(4), particle(i,1)+2+rand(4))
  183.  
  184.         End If
  185.     Next
  186.  
  187.     Color _RGB32(255, 255, 255)
  188.     _PrintString (190, 140), t1$
  189.     Color _RGB32(0, 0, 255)
  190.     _PrintString (192, 142), t1$
  191.     If text_count < 300 Then
  192.         'Text 223, 180, 24, t4$, &HFFFF0000
  193.         Color _RGB32(255, 255, 255)
  194.         _PrintString (213, 190), t4$
  195.         Color _RGB32(255, 0, 0)
  196.         _PrintString (215, 192), t4$
  197.         text_count = text_count + 1
  198.     Else
  199.         If sw_text = 1 Then
  200.             t4$ = t3$
  201.             sw_text = 0
  202.         Else
  203.             t4$ = t2$
  204.             sw_text = 1
  205.         End If
  206.         text_count = 0
  207.     End If
  208.     _Display
  209.     _Limit 10
  210.  
  211. Function rand% (n)
  212.     rand% = Int((n + 1) * Rnd)
  213.  
  214. Sub star (x, y, rInner, rOuter, nPoints, angleOffset, K As _Unsigned Long)
  215.     ' x, y are same as for circle,
  216.     ' rInner is center circle radius
  217.     ' rOuter is the outer most point of star
  218.     ' nPoints is the number of points,
  219.     ' angleOffset = angle offset IN DEGREES, it will be converted to radians in sub
  220.     ' this is to allow us to spin the polygon of n sides
  221.     Dim pAngle, radAngleOffset, x1, y1, x2, y2, x3, y3, i As Long
  222.  
  223.     pAngle = _D2R(360 / nPoints): radAngleOffset = _D2R(angleOffset)
  224.     x1 = x + rInner * Cos(radAngleOffset)
  225.     y1 = y + rInner * Sin(radAngleOffset)
  226.     For i = 0 To nPoints - 1
  227.         x2 = x + rOuter * Cos(i * pAngle + radAngleOffset + .5 * pAngle)
  228.         y2 = y + rOuter * Sin(i * pAngle + radAngleOffset + .5 * pAngle)
  229.         x3 = x + rInner * Cos((i + 1) * pAngle + radAngleOffset)
  230.         y3 = y + rInner * Sin((i + 1) * pAngle + radAngleOffset)
  231.         ftri x1, y1, x2, y2, x3, y3, K
  232.         'triangles leaked
  233.         Line (x1, y1)-(x2, y2), K
  234.         Line (x2, y2)-(x3, y3), K
  235.         Line (x3, y3)-(x1, y1), K
  236.         x1 = x3: y1 = y3
  237.     Next
  238.     Paint (x, y), K, K
  239.  
  240. '2019-12-16 fix by Steve saves some time with STATIC and saves and restores last dest
  241. Sub ftri (x1, y1, x2, y2, x3, y3, K As _Unsigned Long)
  242.     Dim D As Long
  243.     Static a&
  244.     D = _Dest
  245.     If a& = 0 Then a& = _NewImage(1, 1, 32)
  246.     _Dest a&
  247.     _DontBlend a& '  '<<<< new 2019-12-16 fix
  248.     PSet (0, 0), K
  249.     _Blend a& '<<<< new 2019-12-16 fix
  250.     _Dest D
  251.     _MapTriangle _Seamless(0, 0)-(0, 0)-(0, 0), a& To(x1, y1)-(x2, y2)-(x3, y3)
  252.  
  253. 'Sub Text (x, y, textHeight, txt$, k As _Unsigned Long)
  254. '    Dim fg As _Unsigned Long, cur&, I&, multi, xlen
  255. '    fg = _DefaultColor
  256. '    'screen snapshot
  257. '    cur& = _Dest
  258. '    I& = _NewImage(8 * Len(txt$), 16, 32)
  259. '    _Dest I&
  260. '    Color k
  261. '    _PrintString (0, 0), txt$
  262. '    multi = textHeight / 16
  263. '    xlen = Len(txt$) * 8 * multi
  264. '    _PutImage (x, y)-Step(xlen, textHeight), I&, cur&
  265. '    Color fg
  266. '    _FreeImage I&
  267. 'End Sub
  268.  
  269.  
96
Programs / Selecting a folder (a little vbs function)
« Last post by euklides on April 10, 2022, 10:54:15 am »
Little function to select a folder with VBS
(win systems)
Code: QB64: [Select]
  1. MYREP$ = REPSELECTOR$("D:"): Print MYREP$
  2. MYREP$ = REPSELECTOR$(""): Print MYREP$: Sleep
  3.  
  4. Function REPSELECTOR$ (repertoiredemarrage$)
  5.     Repz$ = repertoiredemarrage$:  FS2$ = Chr$(13) + Chr$(10)
  6.     fs1$ = "Dim objFolder, objItem, objShell" + FS2$
  7.     fs1$ = fs1$ + "On Error Resume Next" + FS2$
  8.     fs1$ = fs1$ + "SelectFolder = vbNull" + FS2$
  9.     fs1$ = fs1$ + "myStartFolder = " + "²" + Repz$ + "²" + FS2$
  10.     fs1$ = fs1$ + "Set objShell  = CreateObject( ²Shell.Application² )" + FS2$
  11.     fs1$ = fs1$ + "Set objFolder = objShell.BrowseForFolder( 0, ²Select Folder², 0, myStartFolder )" + FS2$
  12.     fs1$ = fs1$ + "If IsObject( objfolder ) Then SelectFolder = objFolder.Self.Path" + FS2$
  13.     fs1$ = fs1$ + "Set WshShell = WScript.CreateObject(²WScript.Shell²)" + FS2$
  14.     fs1$ = fs1$ + "WshShell.Run ²cmd.exe /c echo ² & SelectFolder & ² | clip², 0, TRUE   " + FS2$
  15.     FS5: J = InStr(fs1$, "²"): If J > 0 Then Mid$(fs1$, J, 1) = Chr$(34): GoTo FS5
  16.     ficvbs$ = _CWD$ + "\TEMP_FS.vbs": CanalLibre% = FreeFile: Open ficvbs$ For Output As CanalLibre%
  17.     Print #1, fs1$: Close CanalLibre%: _Delay 0.1:
  18.     Shell ficvbs$: Kill ficvbs$
  19.     REPSELECTOR$ = _Clipboard$
  20.  
97
Programs / Re: ascII almost smooth pixel scroll
« Last post by PMACKAY on April 10, 2022, 09:56:42 am »
its supposed to show junk. was just a test to smooth scroll the screen. the random was just to show you can print to the screen easy using a similar routine. you can all do as you wish this. it was me messing about as i like to play around making stuff up.

you can change the screen size and size of the scroll quiet easy to make a maze game or ascii side scroller.  not difficult to convert to vertical

Screen _NewImage(40 * 8, 28 * 16, 256) and have it draw a box around the outside and paint it. that will give a border like a commodore64

you can change the font if you want also

screendata$(1) to screendata$(24) : just put in the data what you want eg. screendata$(?) = "your maze data". you can make a maze that you walk through but your man goes up and down why your scrolls in the direction you press make the map roll around and the maze harder.

you could make it draw a map and move monsters around like a PAC man why you gobble dots on a full rotating map. maybe remap the ASCII characters and print monsters chasing you. could maybe dig holes for monsters to fall in so you could run back over them but only dig a hole every 10 seconds. just a thought

it could be made to run much better but I like it.

everyone is right it is showing garbage. its on purpose as a demo. the random print of "/" is to show you how to locate x,y:print "whatever" as the screen updates on a timer. no need to print print:
98
QB64 Discussion / Re: Particle System
« Last post by _vince on April 10, 2022, 09:38:24 am »
Found it:
http://sdlbasic.epizy.com/showthread.php?tid=235

Here is a simple particle system that I converted from Basic256. It has a lot of comments that explain what each step does.

Note: On my machine, the 'polygon' command, causes sdlbasic to freeze. SetPixel, Bar, fillcircle and Ployline all work just fine.

Wow, what is Basic256!?  There's a successor to ModernBASIC 128?
99
QB64 Discussion / Re: Particle System
« Last post by bplus on April 10, 2022, 07:57:09 am »
Found it:
http://sdlbasic.epizy.com/showthread.php?tid=235

From 6 years ago!

You call the properties parameters here, OK :)

Oh come to think of it, I think you mentioned losing your computer and a bunch of old work. Well that link is to fine Particle System you did.
100
QB64 Discussion / Re: Particle System
« Last post by bplus on April 10, 2022, 07:45:00 am »
@johnno56

This surprises me! You've done particle systems way back at SdlBasic, just fine!

You probably would like to do them with an array for each... I don't know what to call them Property? is the VB term, characteristic? oh what are they called?!

You could setup an UDT for them like this:
Type Particle
    As Single x, y, dx, dy, life, active
    As _unsigned Long colr
end Type
nParticles = 100
Dim Shared parts(nParticles) as Particle

or do it the old fashioned way
dim x(nParticles), y(nParticles), dx(nParticles), dy(nParticles), life(nParticles), active(nParticles)
dim as _unsigned long colr(nParticles)

Then it's good to have a Sub for creating a new particle depends on your app what to do
Sub NewParticle(index) 'where index is for the shared array Parts
     ' setup Parts(index) for you app here
end sub

I could probably dig up some of your code from SdlBasic for doing particles :)



Pages: 1 ... 8 9 [10]