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 - bplus

Pages: 1 [2] 3 4 ... 537
16
QB64 Discussion / Re: Highlight% changes by itself
« on: April 11, 2022, 03:10:55 pm »
add this in around line 115:
Code: QB64: [Select]
  1. If Highlight% > 8 Then Highlight% = 1  
  2.  

So highlight won't exceed 8

Now I think it will work as intended.

17
QB64 Discussion / Re: Highlight% changes by itself
« on: April 11, 2022, 03:07:48 pm »
Line 110 should be this:
Code: QB64: [Select]
  1.  Highlight% = Highlight% - 1    
  2.  

because the up arrow was not changing the highlight number.

18
QB64 Discussion / Re: Highlight% changes by itself
« on: April 11, 2022, 02:49:09 pm »
Type-O!
Code: QB64: [Select]
  1. Dim Shared RightArroeKey$: rightArrowKey$ = Chr$(0) + "M"
  2.  

need w in arrow where e is!

I found it by watching highlight continuously increasing even when keys not pressed.

19
QB64 Discussion / Re: Highlight% changes by itself
« on: April 11, 2022, 02:27:22 pm »
Yeah working on highlights.. looks like just _limit 30 is enough to stop flicker.

20
QB64 Discussion / Re: Highlight% changes by itself
« on: April 11, 2022, 02:19:33 pm »
Ah, I use "toggle"
toggle = 1 - toggle  0,1,0,1,....

True, False a little misleading, but everyone has their styles and preferences....

You are attempting to highlight line ready to go on Enter maybe after arrow presses, I assume.

21
QB64 Discussion / Re: Highlight% changes by itself
« on: April 11, 2022, 01:57:05 pm »
Oh you are trying to highlite something, ehhh

deja vu again today:

Didn't I suggest False% = 0 ???

An If is going to see both -1 and 1 as True and take the THEN path.

22
QB64 Discussion / Re: Highlight% changes by itself
« on: April 11, 2022, 01:50:20 pm »
I added _display and _limit to stop flicker.

Once you use _display, then you must say _display every time you want to show something immediatedly. To disable _display use _autodisplay and get default automatic "display". You could put that at the end of the sub before exiting. _display once in you main drawing loop is best.
Code: QB64: [Select]
  1.  
  2. _Title "Time Calculator"
  3.  
  4. Const TRUE% = 1
  5. Const FALSE% = -1
  6. Dim Shared LeftArrowKey$: LeftArrowKey$ = Chr$(0) + "K"
  7. Dim Shared RightArroeKey$: rightArrowKey$ = Chr$(0) + "M"
  8. Dim Shared UpArrowKey$: UpArrowKey$ = Chr$(0) + "H"
  9. Dim Shared DownArrowKey$: DownArrowKey$ = Chr$(0) + "P"
  10. Const UpArrowHit% = 18432
  11. Const LeftArrowHit% = 19200
  12. Const RightArrowHit% = 19712
  13. Const DownArrowHit% = 20480
  14. ' for the highlighted option in the GetTimeAmount SUB
  15. Const YearsHO% = 1
  16. Const DaysHO% = 2
  17. Const HoursHO% = 3
  18. Const MinutesHO% = 4
  19. Const SecondsHO% = 5
  20.  
  21. Width 80, 50
  22. Color 14, 1: Cls
  23.  
  24. Call Menu
  25.  
  26. Sub FromNowUntil
  27.  
  28. Sub HowLongSince
  29.  
  30. Sub WhatDateAfterElapsedTime
  31.  
  32. Sub AddElapsedTimes
  33.  
  34. Sub SubtractElapsedTimes
  35.  
  36. Sub Multiply
  37.  
  38. Sub Divide
  39.  
  40.  
  41. Sub Menu
  42.     HaltAndDisplay% = 0: Highlight% = 0: yPos% = 0: UserCommand$ = "": A$ = ""
  43.     xPos% = 0: MaxOption% = 0: SelectedAnOption% = 0
  44.  
  45.     HaltAndDisplay% = TRUE%: Highlight% = 1: yPos% = 13: MaxOption% = 8: SelectedAnOption% = FALSE%
  46.     Do
  47.         UserCommand$ = InKey$
  48.         Locate 45, 1: Print S$(Highlight%)
  49.         Locate 46, 1: Print "|" + UserCommand$ + "|"
  50.         If HaltAndDisplay% = TRUE% Then
  51.             Color 14, 1: Cls
  52.             A$ = "Time Calculator Menu": xPos% = Center(A$)
  53.             Locate yPos%, Center(A$): Print A$: Locate yPos% + 1, Center(A$)
  54.             Print "---- ---------- ----"
  55.  
  56.             A$ = "": A$ = "1.) Find How Long From Now"
  57.             Locate yPos% + 3, Center(A$): If Highlight% = 1 Then
  58.             Color 10, 0: Else Color 14, 1: End If: Print A$
  59.             A$ = "": A$ = "Until A Selected Time"
  60.             Locate yPos% + 4, Center(A$): If Highlight% = 1 Then
  61.             Color 10, 0: Else Color 14, 1: End If: Print A$
  62.  
  63.             A$ = "": A$ = "2.) Find How Long It Has Been Since"
  64.             Locate yPos% + 6, Center(A$): If highlighedoption% = 2 Then
  65.             Color 10, 0: Else Color 14, 1: End If: Print A$
  66.             A$ = "": A$ = "A Selected Time Has Passed"
  67.             Locate yPos% + 7, Center(A$): If Highlight% = 2 Then
  68.             Color 10, 0: Else Color 14, 1: End If: Print A$
  69.  
  70.             A$ = "": A$ = "3.) Find The Date And Time It Will Be After"
  71.             Locate yPos% + 9, Center(A$): If Highlight% = 3 Then
  72.             Color 10, 0: Else Color 14, 1: End If: Print A$
  73.             A$ = "": A$ = "A Selected Amount Of Time Has Passed"
  74.             Locate yPos% + 10, Center(A$): If Highlight% = 3 Then
  75.             Color 10, 0: Else Color 14, 1: End If: Print A$
  76.  
  77.             A$ = "": A$ = "4.) Add Two Elapsed Times"
  78.             Locate yPos% + 12, Center(A$): If Highlight% = 4 Then
  79.             Color 10, 0: Else Color 14, 1: End If: Print A$
  80.  
  81.             A$ = "": A$ = "5.) Subtract One Elapsed Time From Another One"
  82.             Locate yPos% + 14, Center(A$): If Highlight% = 5 Then
  83.             Color 10, 0: Else Color 14, 1: End If: Print A$
  84.  
  85.             A$ = "": A$ = "6.) Multiply An Elapsed Time By A Constant"
  86.             Locate yPos% + 16, Center(A$): If Highlight% = 6 Then
  87.             Color 10, 0: Else Color 14, 1: End If: Print A$
  88.  
  89.             A$ = "": A$ = "7.) Divide An Elapsed Time By A Constant"
  90.             Locate yPos% + 18, Center(A$): If Highlight% = 7 Then
  91.             Color 10, 0: Else Color 14, 1: End If: Print A$
  92.  
  93.             A$ = "": A$ = "8.) Exit"
  94.             Locate 45, Center(A$): If Highlight% = 8 Then
  95.             Color 10, 0: Else Color 14, 1: End If: Print A$
  96.  
  97.             HaltAndDisplay% = FALSE%
  98.         End If
  99.  
  100.         Select Case UserCommand$
  101.             Case UpArrowKey$, LeftArrowKey$
  102.                 Highlight% = highlightedoption - 1
  103.                 If Highlight% = 0 Then Highlight% = MaxOption%
  104.                 HaltAndDisplay% = TRUE%
  105.             Case DownArrowKey$, rightarrowkey$
  106.                 Highlight% = Highlight% + 1
  107.                 If highlightedoption > maxoption Then Highlight% = 1
  108.                 HaltAndDisplay% = TRUE%
  109.             Case Chr$(13)
  110.                 SelectedAnOption% = TRUE%
  111.             Case "1", "2", "3", "4", "5", "6", "7"
  112.                 Highlight% = Val(UserCommand$)
  113.                 SelectedAnOption% = TRUE%
  114.         End Select
  115.         If SelectedAnOption% = TRUE Then
  116.             Select Case Highlight%
  117.                 Case 1
  118.                     Call FromNowUntil: SelectedAnOption% = FALSE%
  119.                 Case 2
  120.                     Call HowLongSince: SelectedAnOption% = FALSE%
  121.                 Case 3
  122.                     Call WhatDateAfterElapsedTime: SelectedAnOption% = FALSE%
  123.                 Case 4
  124.                     Call AddElapsedTimes: SelectedAnOption% = FALSE%
  125.                 Case 5
  126.                     Call SubtractElapsedTimes: SelectedAnOption% = FALSE%
  127.                 Case 6
  128.                     Call Multiply: SelectedAnOption% = FALSE%
  129.                 Case 7
  130.                     Call Divide: SelectedAnOption% = FALSE%
  131.             End Select
  132.         End If
  133.         _Display ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< added this and next
  134.         _Limit 30
  135.     Loop Until UserCommand$ = Chr$(27) Or UserCommand$ = S$(MaxOption%)
  136.  
  137.  
  138.  
  139.  
  140.  
  141. Function Center% (Text$): Center% = Int((80 - Len(Text$)) / 2): End Function
  142. Function S$ (Number!): S$ = LTrim$(Str$(Number!)): End Function
  143. Function P$: pause$ = Input$(1): If pause$ = Chr$(27) Then End
  144. P$ = pause$: End Function
  145.  
  146.  
  147.  

23
Programs / Re: Benchmark_01
« 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.

24
Programs / Benchmark_01
« 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.

25
QB64 Discussion / Re: Particle System
« 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.  

26
QB64 Discussion / Re: Particle System
« 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.

27
QB64 Discussion / Re: Particle System
« 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 :)




28
QB64 Discussion / Re: Puzzling double precision rounding inaccuracy
« on: April 10, 2022, 07:32:26 am »
And as TempodiBasic says, remember it's not a bug, it's a feature.

You learn never to completely trust the computer, good lesson!

29
QB64 Discussion / Re: Puzzling double precision rounding inaccuracy
« on: April 10, 2022, 06:23:56 am »
You've found the solution!

Welcome to the forum!

30
BTW I am talking about this color picker, in version 6/7? I think they changed to image later?
 
image_2022-04-09_212952330.png

Pages: 1 [2] 3 4 ... 537