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

Pages: 1 2 [3] 4 5 ... 21
31
Programs / ArcRings
« on: December 23, 2021, 01:33:08 pm »
I saw on Discord today someone wanted Thick Circles, I call them Rings soon you will want thick Arcs too. We'll do ArcRings you will have both and they will work with transparent colors too.

Well here's all that, for raStart and raEnd, ra stands for Radian Angle (not degrees) Radian Angles are expressed in fractions of Pi eg Pi = 180 degrees and whole circle is 2*Pi so 1/10 of circle is 2*pi / 10 equivalent to 36 degrees.

Now I use Basic trig Sin(RadianAngle) and Cos(RadianAngle) that go around circle Clockwise as Radian Angle increases unlike Basic's Circle which goes opposite. So between the trig mention and Radian Angle mention I have probably lost most my audience ;-))

Anyway, it will be handy if you want a transparent color arc or ring and you understand what I am calling raStart and raEnd, I hope the rest is self explanatory:
Code: QB64: [Select]
  1. _Title "ArcRings  test" 'B+ 2019-02-21  for Raceman Sequence graphing
  2. ' 2021-12-23 reviewed remove confusing comments and test code then rewrote again for Option _Explicit
  3.  
  4. Screen _NewImage(1000, 700, 32)
  5. _ScreenMove 180, 20
  6.  
  7. While _KeyDown(27) = 0
  8.     i = i + 1
  9.     If i Mod 50 = 0 Then Cls: i = 0
  10.     ro = Rnd * 100 + 50: ri = ro - ro * Rnd - 10
  11.     ArcRing Rnd * 800 + 100, Rnd * 500 + 100, ro, ri, Rnd * _Pi(2), Rnd * _Pi(2), _RGBA32(255 * Rnd, 255 * Rnd, 255 * Rnd, 255 * Rnd)
  12.     _Display
  13.     _Limit 10
  14.  
  15. Sub ArcRing (x0, y0, outerR, innerR, raStart, raEnd, colr As _Unsigned Long)
  16.     Dim Pi2, Pi32, PiH, P, raS, raE, ck1, y, x, d, ra
  17.     Pi2 = _Pi(2)
  18.     Pi32 = _Pi(1.5)
  19.     PiH = _Pi(.5)
  20.     P = _Pi
  21.     raS = raStart ' checking raStart and raEnd to behave as expected
  22.     While raS >= Pi2
  23.         raS = raS - Pi2
  24.     Wend
  25.     While raS < 0
  26.         raS = raS + Pi2
  27.     Wend
  28.     raE = raEnd
  29.     While raE < 0
  30.         raE = raE + Pi2
  31.     Wend
  32.     While raE >= Pi2
  33.         raE = raE - Pi2
  34.     Wend
  35.     If raE > raS Then ck1 = -1
  36.     For y = y0 - outerR To y0 + outerR
  37.         For x = x0 - outerR To x0 + outerR
  38.             d = Sqr((x - x0) * (x - x0) + (y - y0) * (y - y0))
  39.             If d >= innerR And d <= outerR Then 'within 2 radii
  40.                 'angle of x, y to x0, y0
  41.                 If x - x0 <> 0 And y - y0 <> 0 Then
  42.                     ra = _Atan2(y - y0, x - x0)
  43.                     If ra < 0 Then ra = ra + Pi2
  44.                 ElseIf x - x0 = 0 Then
  45.                     If y >= y0 Then ra = _Pi / 2 Else ra = Pi32
  46.                 ElseIf y - y0 = 0 Then
  47.                     If x >= x0 Then ra = 0 Else ra = PI
  48.                 End If
  49.                 If ck1 Then 'raEnd > raStart
  50.                     If ra >= raS And ra <= raE Then
  51.                         PSet (x, y), colr
  52.                     End If
  53.                 Else 'raEnd < raStart, raEnd is falls before raStart clockwise so fill through 2 * PI
  54.                     If ra >= raS And ra < Pi2 Then
  55.                         PSet (x, y), colr
  56.                     Else
  57.                         If ra >= 0 And ra <= raE Then
  58.                             PSet (x, y), colr
  59.                         End If
  60.                     End If
  61.                 End If
  62.             End If
  63.         Next
  64.     Next
  65.  

 
ArcRing Test.PNG

32
Programs / Graphics Test #3D - are you certifiable?
« on: December 19, 2021, 11:53:34 am »
3D very popular these days, try a cube of cubes:
 
3D render #3 Cube of cubes step 1.PNG

 
3D render #3 Cube of cubes step 2.PNG

33
Programs / ❅ Snowflake Design
« on: December 04, 2021, 08:05:45 pm »
Needs some improvements:

Code: QB64: [Select]
  1. _Title "Snow Flake Design 1, click points inside triangle, e expand, c clear" ' B+ started 2018-12-07 for QB64
  2. Const XMAX = 700
  3. Const YMAX = 700
  4. Const white = &HFFFFFFFF
  5. Const black = &H0
  6. Const red = &HFFFF0000
  7. Screen _NewImage(XMAX, YMAX, 32)
  8. _ScreenMove 250, 20
  9. Dim Shared xc, yc, r, d6, datIndex, maxPoints
  10. xc = XMAX / 2: yc = YMAX / 2: r = .5 * YMAX * .025: d6 = _Pi(.166666666): maxPoints = 500
  11. Dim Shared aDat(1 To maxPoints), dDat(maxPoints)
  12. drawArea
  13. While _KeyDown(27) = 0
  14.     mx = -1: my = -1: q = 0
  15.     getClick mx, my, q
  16.     If q <> 0 Then
  17.         If Chr$(q) = "e" Then
  18.             Cls
  19.             For i = 0 To 5
  20.                 For j = 1 To datIndex
  21.                     x1 = xc + dDat(j) * YMAX * Cos(i * 2 * d6 + aDat(j))
  22.                     y1 = yc + dDat(j) * YMAX * Sin(i * 2 * d6 + aDat(j))
  23.                     fcirc x1, y1, r
  24.                     x1 = xc + dDat(j) * YMAX * Cos(i * 2 * d6 - aDat(j))
  25.                     y1 = yc + dDat(j) * YMAX * Sin(i * 2 * d6 - aDat(j))
  26.                     fcirc x1, y1, r
  27.                 Next
  28.             Next
  29.         ElseIf Chr$(q) = "q" Then
  30.             End
  31.         ElseIf Chr$(q) = "c" Then
  32.             Cls
  33.             drawArea
  34.             datIndex = 0
  35.         End If
  36.     Else
  37.         'clicked mx, my
  38.         a = _Atan2(my - yc, mx - xc)
  39.         If a >= 0 And a < d6 Then
  40.             scaleDist = (((mx - xc) ^ 2 + (my - yc) ^ 2) ^ .5) / YMAX
  41.             datIndex = datIndex + 1
  42.             aDat(datIndex) = a
  43.             dDat(datIndex) = scaleDist
  44.             fcirc xc + dDat(datIndex) * YMAX * Cos(aDat(datIndex)), yc + dDat(datIndex) * YMAX * Sin(aDat(datIndex)), r
  45.         End If
  46.     End If
  47.     _Display
  48.     _Limit 60
  49.  
  50. Sub drawArea
  51.     x1 = xc + .45 * YMAX * Cos(0)
  52.     y1 = yc + .45 * YMAX * Sin(0)
  53.     x2 = xc + .45 * YMAX * Cos(d6)
  54.     y2 = yc + .45 * YMAX * Sin(d6)
  55.     Line (xc, yc)-(x1, y1), red
  56.     Line (xc, yc)-(x2, y2), red
  57.     Line (x2, y2)-(x1, y1), red
  58.  
  59. Sub getClick (mx, my, q)
  60.     While _MouseInput: Wend ' clear previous mouse activity
  61.     mx = -1: my = -1: q = 0
  62.     Do While mx = -1 And my = -1
  63.         q = _KeyHit
  64.         If q = 27 Or (q > 31 And q < 126) Then Exit Sub
  65.         i = _MouseInput: mb = _MouseButton(1)
  66.         If mb Then
  67.             Do While mb 'wait for release
  68.                 q = _KeyHit
  69.                 If q = 27 Or (q > 31 And q < 126) Then Exit Sub
  70.                 i = _MouseInput: mb = _MouseButton(1): mx = _MouseX: my = _MouseY
  71.                 _Limit 1000
  72.             Loop
  73.             Exit Sub
  74.         End If
  75.         _Limit 1000
  76.     Loop
  77.  
  78. Sub fcirc (CX As Long, CY As Long, R As Long)
  79.     Dim subRadius As Long, RadiusError As Long
  80.     Dim X As Long, Y As Long
  81.  
  82.     subRadius = Abs(R)
  83.     RadiusError = -subRadius
  84.     X = subRadius
  85.     Y = 0
  86.  
  87.     If subRadius = 0 Then PSet (CX, CY): Exit Sub
  88.  
  89.     ' Draw the middle span here so we don't draw it twice in the main loop,
  90.     ' which would be a problem with blending turned on.
  91.     Line (CX - X, CY)-(CX + X, CY), , BF
  92.  
  93.     While X > Y
  94.         RadiusError = RadiusError + Y * 2 + 1
  95.         If RadiusError >= 0 Then
  96.             If X <> Y + 1 Then
  97.                 Line (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  98.                 Line (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  99.             End If
  100.             X = X - 1
  101.             RadiusError = RadiusError - X * 2
  102.         End If
  103.         Y = Y + 1
  104.         Line (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  105.         Line (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  106.     Wend
  107.  
  108.  

Step 1: dot triangle with ice molecules
 
step 1.PNG


Step 2: press e to expand
 
step 2 press e to expand.PNG



34
Programs / Graphics Test #2 - are you certifiable?
« on: November 29, 2021, 08:37:35 am »
Can you write code for this?
 
Globe - 2 branching.PNG

35
Programs / Turkey Day is around the corner
« on: November 24, 2021, 09:41:19 pm »
Code: QB64: [Select]
  1. _Title "Turkey Run" ' b+ mod 2021-11-24
  2. 'test if can get end of landscape level to start for big looping background
  3. '2019-03-27 a more gentle adjustment back to Mountain starting height for
  4. 'more seamless connect of back end to front
  5. '2019-03-27 start this file with parallax drawing test
  6.  
  7. Screen _NewImage(800, 600, 32)
  8. _ScreenMove 100, 20
  9.  
  10. Type parallaxType
  11.     handle As Long
  12.     rate As Single 'number of pixels per frame added to le (leading edge)
  13.     le As Single
  14. nLevels = 6
  15. Dim Shared para(1 To nLevels) As parallaxType
  16.  
  17. Dim Shared scape&
  18. LoadLandscape
  19. scapeWidth = _Width(para(1).handle)
  20. scapeHeight = _Height(para(1).handle)
  21. tr = _LoadImage("turkey run.jpg")
  22. _ClearColor Point(10, 10), tr
  23. dir = 1.25
  24. While _KeyDown(27) = 0 't < 6000
  25.     Cls
  26.     For i = 1 To nLevels
  27.         If para(i).le + 800 > scapeWidth Then
  28.             te = scapeWidth - para(i).le
  29.             _PutImage (0, 0)-(te, scapeHeight), para(i).handle, 0, (scapeWidth - te, 0)-(scapeWidth, scapeHeight)
  30.             _PutImage (te, 0)-(800, scapeHeight), para(i).handle, 0, (0, 0)-(800 - te, scapeHeight)
  31.  
  32.         Else
  33.             _PutImage (0, 0)-(800, scapeHeight), para(i).handle, 0, (para(i).le, 0)-(para(i).le + 800, scapeHeight)
  34.         End If
  35.  
  36.         para(i).le = para(i).le - para(i).rate
  37.         If para(i).le < 0 Then para(i).le = scapeWidth
  38.     Next
  39.     _PutImage (350, 500 + down)-Step(111, 93), tr, 0, (0, 0)-(_Width(tr), _Height(tr) - 30)
  40.     t = t + 1
  41.     down = down + dir
  42.     If down > 37 Then down = 37: dir = -dir
  43.     If down < 13 Then down = 13: dir = -dir
  44.     _Display
  45.     _Limit 120
  46.  
  47. Sub LoadLandscape
  48.     cur& = _Dest
  49.     xmax = 800 * 3.25: ymax = 600
  50.     hdl& = 1
  51.     para(hdl&).handle = _NewImage(xmax, ymax, 32)
  52.     _Dest para(hdl&).handle
  53.  
  54.     For i = 0 To ymax
  55.         midInk 0, 0, 128, 128, 128, 200, i / ymax
  56.         Line (0, i)-(xmax, i)
  57.     Next
  58.     'the land
  59.     startH = ymax - 250
  60.     rr = 70: gg = 70: bb = 90
  61.     For mountain = 1 To nLevels
  62.         If mountain > 1 Then
  63.             para(mountain).handle = _NewImage(xmax, ymax, 32)
  64.             _Dest para(mountain).handle
  65.         End If
  66.         Xright = 0
  67.         y = startH
  68.         Color _RGB(rr, gg, bb)
  69.         While Xright < xmax - 50
  70.             ' upDown = local up / down over range, change along Y
  71.             ' range = how far up / down, along X
  72.             upDown = (Rnd * .8 - .4) * (mountain * .5)
  73.             range = Xright + rand%(15, 25) * 2.5 / mountain
  74.             If range > xmax - 50 Then range = xmax - 50
  75.             lastx = Xright - 1
  76.             For x = Xright To range 'need less flat tops
  77.                 test = y + upDown
  78.                 test2 = y - upDown
  79.                 If Abs(test - startH) < .13 * startH Then y = test Else y = test2: upDown = -upDown
  80.                 Line (lastx, y)-(x, ymax), , BF 'just lines weren't filling right
  81.                 lastx = x
  82.             Next
  83.             Xright = range
  84.         Wend
  85.         x = lastx + 1
  86.         dy = (startH - y) / 50 'more gentle adjustment back to start of screen
  87.         While x <= xmax
  88.             y = y + dy
  89.             Line (lastx, y)-(x, ymax), , BF 'just lines weren't filling right
  90.             lastx = x
  91.             x = x + 1
  92.         Wend
  93.         rr = rand%(rr + 50, rr + 30): gg = rand%(gg + 50, gg + 30): bb = rand%(bb + 50, bb + 30)
  94.         If rr < 0 Then rr = 0
  95.         If gg < 0 Then gg = 0
  96.         If bb < 0 Then bb = 0
  97.         startH = startH + mountain * rand%(2, 10)
  98.         para(mountain).le = xmax - 800
  99.         para(mountain).rate = mountain * .5
  100.     Next
  101.     _Dest cur&
  102.  
  103. Function rand% (lo%, hi%)
  104.     rand% = Int(Rnd * (hi% - lo% + 1)) + lo%
  105.  
  106. Sub midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  107.     Color _RGB(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  108.  
  109.  

You will need the image in the zip:

36
Programs / Graphics Test #1 Are You Certifiable?
« on: November 21, 2021, 01:32:26 pm »
Create this Pattern:
 
Cert Test #1.PNG


Too easy? Here's 2 mods:
 
Shrinking Chess Patterns.PNG

37
Programs / Even Better Stars
« on: November 18, 2021, 04:33:17 pm »
Souping up some old SdlBasic code:
Code: QB64: [Select]
  1. _Title "Even Better Stars" 'b+ 2021-11-18 trans of
  2. 'Better Stars.sdlbas (B+=MGA) 2016-05-16
  3. ' odd or even number of point, fat or skinny, better fills
  4.  
  5. Const Pi = _Acos(-1) 'cute way to get pi
  6. 'Print (Pi) 'check pi
  7. 'End
  8. Const Radians = Pi / 180 'to convert an angle measured in degrees to and angle measure in radians, just mutiply by this
  9. Const Xmax = 700
  10. Const Ymax = 700
  11. Const Cx = Xmax / 2
  12. Const Cy = Ymax / 2
  13.  
  14. 'setdisplay(xmax, ymax, 32, 1)
  15. Screen _NewImage(Xmax, Ymax, 32)
  16. _ScreenMove 300, 40
  17. 'setcaption("Better Stars demo")
  18. 'autoback(-2)
  19.  
  20. 'main
  21. Const NS = 100
  22. Dim Shared x(NS), y(NS), dx(NS), dy(NS), ri(NS), ro(NS), p(NS), a(NS), turn(NS), fill(NS), c(NS) As _Unsigned Long
  23. loopcounter = 0
  24. For i = 0 To NS
  25.     NewStar i
  26. While _KeyDown(27) = 0
  27.     Line (0, 0)-(Xmax, Ymax), _RGB32(0, 0, 0, 30), BF
  28.     For i = 0 To NS
  29.         If x(i) > 0 And x(i) < Xmax And y(i) > 0 And y(i) < Ymax Then
  30.             'ink(colr(c(i)))
  31.             Color c(i)
  32.             Star x(i), y(i), ri(i), ro(i), p(i), a(i), fill(i)
  33.             x(i) = x(i) + dx(i)
  34.             y(i) = y(i) + dy(i)
  35.             ri(i) = 1.015 * ri(i)
  36.             ro(i) = 1.015 * ro(i)
  37.             a(i) = a(i) + turn(i)
  38.         Else
  39.             NewStar i
  40.         End If
  41.     Next
  42.     'screenswap
  43.     _Display
  44.     _Limit 100
  45.     'wait(50)
  46.     loopcounter = loopcounter + 1
  47.  
  48.  
  49. Sub NewStar (nxt)
  50.     angle = Rnd * 2 * Pi
  51.     r = Rnd * 6 + 1
  52.     dx(nxt) = r * Cos(angle)
  53.     dy(nxt) = r * Sin(angle)
  54.     r = Rnd * 300
  55.     x(nxt) = Cx + r * dx(nxt)
  56.     y(nxt) = Cy + r * dy(nxt)
  57.     ri(nxt) = Rnd
  58.     ro(nxt) = ri(nxt) + 1 + Rnd
  59.     p(nxt) = 3 + Int(Rnd * 9)
  60.     a(nxt) = Rnd * 2 * Pi
  61.     turn(nxt) = Rnd * 6 - 3
  62.     fill(nxt) = Int(Rnd * 2)
  63.     c(nxt) = rndColor~&
  64.  
  65. Function rndColor~& ()
  66.     rndColor~& = _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
  67.  
  68. Sub Star (x, y, rInner, rOuter, nPoints, angleOffset, TFfill)
  69.     ' x, y are same as for circle,
  70.     ' rInner is center circle radius
  71.     ' rOuter is the outer most point of star
  72.     ' nPoints is the number of points,
  73.     ' angleOffset = angle offset IN DEGREES, it will be converted to radians in sub
  74.     ' this is to allow us to spin the polygon of n sides
  75.     ' TFfill filled True or False (1 or 0)
  76.     p_angle = Radians * (360 / nPoints): rad_angle_offset = Radians * angleOffset
  77.     x1 = x + rInner * Cos(rad_angle_offset)
  78.     y1 = y + rInner * Sin(rad_angle_offset)
  79.     For i = 0 To nPoints - 1
  80.         x2 = x + rOuter * Cos(i * p_angle + rad_angle_offset + .5 * p_angle)
  81.         y2 = y + rOuter * Sin(i * p_angle + rad_angle_offset + .5 * p_angle)
  82.         x3 = x + rInner * Cos((i + 1) * p_angle + rad_angle_offset)
  83.         y3 = y + rInner * Sin((i + 1) * p_angle + rad_angle_offset)
  84.         Line (x1, y1)-(x2, y2)
  85.         Line (x2, y2)-(x3, y3)
  86.         x1 = x3: y1 = y3
  87.     Next
  88.     If TFfill Then
  89.         'Circle (x, y), 2, &HFFFFFFFF
  90.         Paint (x, y), _DefaultColor, _DefaultColor
  91.     End If
  92.  
  93.  

38
Programs / Contour Plot
« on: November 16, 2021, 08:52:56 pm »
Ah, found some Contour plot code from SdlBasic which turns out started at Q B 6 4 .net [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there] by Mrwhy.

Here's how I found it SdlBasic Forum:
Code: [Select]
        ' Contour plot using Data Points by Mrwhy
       'ref: SdlBasic forum, AndyA, 9-13-2016  http://sdlbasic.epizy.com/showthread.php?tid=302

'http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=3714.msg37019#msg37019
'https://en.wikipedia.org/wiki/Richard_V._Southwell
'https://en.wikipedia.org/wiki/Relaxation_(iterative_method)

Option QBASIC
Common sw, sh
'============================
' change size of output screen here
'============================
smallPlot = 1
'============================
If smallPlot = 1 Then
    'take about 25 secs to calc
    sw = 240 : sh = 240
Else
    'large plot takes over 2 minutes to calc
    sw = 640 : sh = 480
End If

SetDisplay(sw, sh, 32, 1)
SetCaption("Contour Map")

Dim pal[23], x[50], y[50], z[100], E[50], h[sw, sh]

'red to yellow palette
pal[0]  = 0        : pal[1]  = 0x800000
pal[2]  = 0xA00000 : pal[3]  = 0xC00000
pal[4]  = 0xD00000 : pal[5]  = 0xFF0000
pal[6]  = 0xFF2000 : pal[7]  = 0xFF4000
pal[8]  = 0xFF6000 : pal[9]  = 0xFF8000
pal[10] = 0xFFA000 : pal[11] = 0xFFC000
pal[12] = 0xFFE000 : pal[13] = 0xFFFF00
pal[14] = 0xFFFF20 : pal[15] = 0xFFFF40

'============================================
' number of height/potential points in data
'============================================
numPoints = 16
'============================================

If smallPlot = 1 Then
    x[1]  = 161 : y[1]  = 120 : z[1]  = 11
    x[2]  =  80 : y[2]  =  80 : z[2]  =  9
    x[3]  =  40 : y[3]  =  40 : z[3]  =  6
    x[4]  = 122 : y[4]  =  20 : z[4]  =  3
    x[5]  = 117 : y[5]  =  72 : z[5]  =  4
    x[6]  = 178 : y[6]  = 124 : z[6]  =  7
    x[7]  = 140 : y[7]  = 173 : z[7]  =  9
    x[8]  = 194 : y[8]  =  38 : z[8]  = 13
    x[9]  =  65 : y[9]  =  65 : z[9]  = 12
    x[10] = 135 : y[10] =  60 : z[10] =  9
    x[11] = 180 : y[11] = 160 : z[11] =  8
    x[12] =  70 : y[12] = 135 : z[12] = 11
    x[13] = 165 : y[13] = 150 : z[13] =  6
    x[14] = 225 : y[14] =  90 : z[14] =  2
    x[15] = 190 : y[15] = 178 : z[15] = 12
    x[16] = 135 : y[16] = 135 : z[16] = 10
Else
    x[1]  = 279: y[1]  = 220: z[1]  = 11    '1
    x[2]  = 160: y[2]  = 160: z[2]  =  9    '2
    x[3]  =  80: y[3]  =  80: z[3]  =  6    '3
    x[4]  = 144: y[4]  =  40: z[4]  =  7    '4
    x[5]  = 350: y[5]  = 158: z[5]  =  4    '5
    x[6]  = 356: y[6]  = 248: z[6]  =  7    '6
    x[7]  = 280: y[7]  = 347: z[7]  =  9    '7
    x[8]  = 370: y[8]  =  39: z[8]  = 13    '8
    x[9]  = 130: y[9]  = 230: z[9]  = 12    '9
    x[10] = 270: y[10] = 120: z[10] =  9    '10
    x[11] = 360: y[11] = 320: z[11] =  8    '11
    x[12] = 140: y[12] = 270: z[12] = 11    '12
    x[13] = 530: y[13] = 300: z[13] =  6    '13
    x[14] = 458: y[14] = 143: z[14] =  2    '14
    x[15] = 380: y[15] = 370: z[15] = 12    '15
    x[16] = 270: y[16] = 270: z[16] = 10    '16
End If

ztot = 0
'display height or potential data points on screen
For i = 1 To numPoints
    Ink (pal[z[i]])
   FillCircle (x[i], sh - y[i], 3)
   ztot = ztot + z[i]
Next

Ink(0xFFFF40)
Text(48,2,12,"Calculating contour map")
Box(40, 1, 212, 16)
WaitVBL

'initialize some variables
zmean = ztot / numPoints
wo = sw * sh / numPoints
w = wo / 2.0

'generate initial Error estimates
For i = 1 To numPoints
   E[i] = z[i] - zmean
Next
Legend()
WaitVBL

'begin Relaxation (iterative method)
For jj = 1 To 9 * numPoints 'find max error point
   emax = 0
   For i = 1 To numPoints
       If Abs(E[i]) > emax Then
            emax = Abs(E[i])
            ii = i
        End If
       k = E[ii]
   Next
   'fixit
   For i = 1 To numPoints
       dx = x[i] - x[ii]
       dy = y[i] - y[ii]
       dsq = dx * dx + dy * dy
       E[i] = E[i] - k * Exp(-(dsq / w))
       IF i = ii Then
            'update map with revised height or potential estimates for each pixel
           For fy = 1 To (sh-1)
               For fx = 1 To (sw-1)
                   dx = fx - x[ii]
                   dy = fy - y[ii]
                   dsq2 = dx * dx + dy * dy
                    dy = sh-fy
                   h[fx, dy] = h[fx, dy] + k * Exp(-(dsq2 / w))
               Next
           Next
       End If
   Next
Next

'Draw calculated contour map
Ink(pal[h[1,1]+zmean])
Line(0,0,sw-1,0)
Line(0,0,0,sh-1)
For fy = 1 To sh-1
   For fx = 1 To sw-1
       clr = pal[h[fx, fy] + zmean]
       Plot (fx, fy, clr)
   Next
Next

'display height or potential data points on contour map
For i = 1 To numPoints
    clr = pal[z[i]]
    Ink(0)
   FillCircle (x[i], sh - y[i], 3)
    Ink(clr)
    FillCircle (x[i], sh - y[i], 2)
Next
Legend()

Waitkey(27)
End

'show height or potential value for each color in map
Sub Legend()
Ink(0xFFFF40)
Text(5, 45, 10, "Key")
posy = 58
For nn = 1 To 15
    Ink(0xFFFF40)
    Text(0, posy, 10, Str$(nn))
    Ink(0)
   Bar(14, posy + 3, 30, posy + 9)
    Ink(pal[nn])
   Bar (16, posy + 5, 28, posy + 7)
   posy = posy + 12
Next
End Sub


And my QB64 translation, mostly changing the Legend:
Code: QB64: [Select]
  1. _Title "Contour Map" 'b+ trans from SdlBasic to QB64, original from [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]
  2.  
  3. ' Contour plot using Data Points by Mrwhy
  4. 'ref: SdlBasic forum, AndyA, 9-13-2016  http://sdlbasic.epizy.com/showthread.php?tid=302
  5. ' AndyA ref:
  6. 'http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=3714.msg37019#msg37019
  7. 'https://en.wikipedia.org/wiki/Richard_V._Southwell
  8. 'https://en.wikipedia.org/wiki/Relaxation_(iterative_method)
  9.  
  10. Dim Shared sw, sh
  11. '============================
  12. ' change size of output screen here
  13. '============================
  14. smallPlot = 0
  15. '============================
  16. If smallPlot = 1 Then
  17.     'take about 25 secs to calc
  18.     sw = 240: sh = 240
  19.     'large plot takes over 2 minutes to calc
  20.     sw = 640: sh = 480
  21.  
  22. Screen _NewImage(sw, sh, 32)
  23. _ScreenMove 300, 100
  24.  
  25. Dim Shared pal(23) As _Unsigned Long, x(50), y(50), z(100), E(50), h(sw, sh)
  26.  
  27. 'red to yellow palette
  28. pal(0) = &HFF000000: pal(1) = &HFF800000
  29. pal(2) = &HFFA00000: pal(3) = &HFFC00000
  30. pal(4) = &HFFD00000: pal(5) = &HFFFF0000
  31. pal(6) = &HFFFF2000: pal(7) = &HFFFF4000
  32. pal(8) = &HFFFF6000: pal(9) = &HFFFF8000
  33. pal(10) = &HFFFFA000: pal(11) = &HFFFFC000
  34. pal(12) = &HFFFFE000: pal(13) = &HFFFFFF00
  35. pal(14) = &HFFFFFF20: pal(15) = &HFFFFFF40
  36.  
  37. '============================================
  38. ' number of height/potential points in data
  39. '============================================
  40. numPoints = 16
  41. '============================================
  42.  
  43. If smallPlot = 1 Then
  44.     x(1) = 161: y(1) = 120: z(1) = 11
  45.     x(2) = 80: y(2) = 80: z(2) = 9
  46.     x(3) = 40: y(3) = 40: z(3) = 6
  47.     x(4) = 122: y(4) = 20: z(4) = 3
  48.     x(5) = 117: y(5) = 72: z(5) = 4
  49.     x(6) = 178: y(6) = 124: z(6) = 7
  50.     x(7) = 140: y(7) = 173: z(7) = 9
  51.     x(8) = 194: y(8) = 38: z(8) = 13
  52.     x(9) = 65: y(9) = 65: z(9) = 12
  53.     x(10) = 135: y(10) = 60: z(10) = 9
  54.     x(11) = 180: y(11) = 160: z(11) = 8
  55.     x(12) = 70: y(12) = 135: z(12) = 11
  56.     x(13) = 165: y(13) = 150: z(13) = 6
  57.     x(14) = 225: y(14) = 90: z(14) = 2
  58.     x(15) = 190: y(15) = 178: z(15) = 12
  59.     x(16) = 135: y(16) = 135: z(16) = 10
  60.     x(1) = 279: y(1) = 220: z(1) = 11 '1
  61.     x(2) = 160: y(2) = 160: z(2) = 9 '2
  62.     x(3) = 80: y(3) = 80: z(3) = 6 '3
  63.     x(4) = 144: y(4) = 40: z(4) = 7 '4
  64.     x(5) = 350: y(5) = 158: z(5) = 4 '5
  65.     x(6) = 356: y(6) = 248: z(6) = 7 '6
  66.     x(7) = 280: y(7) = 347: z(7) = 9 '7
  67.     x(8) = 370: y(8) = 39: z(8) = 13 '8
  68.     x(9) = 130: y(9) = 230: z(9) = 12 '9
  69.     x(10) = 270: y(10) = 120: z(10) = 9 '10
  70.     x(11) = 360: y(11) = 320: z(11) = 8 '11
  71.     x(12) = 140: y(12) = 270: z(12) = 11 '12
  72.     x(13) = 530: y(13) = 300: z(13) = 6 '13
  73.     x(14) = 458: y(14) = 143: z(14) = 2 '14
  74.     x(15) = 380: y(15) = 370: z(15) = 12 '15
  75.     x(16) = 270: y(16) = 270: z(16) = 10 '16
  76.  
  77. ztot = 0
  78. 'display height or potential data points on screen
  79. For i = 1 To numPoints
  80.     fcirc x(i), sh - y(i), 3, pal(z(i))
  81.     ztot = ztot + z(i)
  82.  
  83. Color &HFFFFFF40
  84.  
  85. s$ = "Calculating Contour Map"
  86. x = (_Width - _PrintWidth(s$)) / 2
  87. _PrintString (x, _Height - 14), s$
  88. Line (x - 4, _Height - 18)-(x + _PrintWidth(s$) + 2, _Height - 2), , B
  89.  
  90. 'initialize some variables
  91. zmean = ztot / numPoints
  92. wo = sw * sh / numPoints
  93. w = wo / 2.0
  94.  
  95. 'generate initial Error estimates
  96. For i = 1 To numPoints
  97.     E(i) = z(i) - zmean
  98. Legend
  99.  
  100. 'begin Relaxation (iterative method)
  101. For jj = 1 To 9 * numPoints 'find max error point
  102.     emax = 0
  103.     For i = 1 To numPoints
  104.         If Abs(E(i)) > emax Then
  105.             emax = Abs(E(i))
  106.             ii = i
  107.         End If
  108.         k = E(ii)
  109.     Next
  110.     'fixit
  111.     For i = 1 To numPoints
  112.         dx = x(i) - x(ii)
  113.         dy = y(i) - y(ii)
  114.         dsq = dx * dx + dy * dy
  115.         E(i) = E(i) - k * Exp(-(dsq / w))
  116.         If i = ii Then
  117.             'update map with revised height or potential estimates for each pixel
  118.             For fy = 1 To (sh - 1)
  119.                 For fx = 1 To (sw - 1)
  120.                     dx = fx - x(ii)
  121.                     dy = fy - y(ii)
  122.                     dsq2 = dx * dx + dy * dy
  123.                     dy = sh - fy
  124.                     h(fx, dy) = h(fx, dy) + k * Exp(-(dsq2 / w))
  125.                 Next
  126.             Next
  127.         End If
  128.     Next
  129.  
  130. 'Draw calculated contour map
  131. Color pal(h(1, 1) + zmean)
  132. Line (0, 0)-(sw - 1, 0)
  133. Line (0, 0)-(0, sh - 1)
  134. For fy = 1 To sh - 1
  135.     For fx = 1 To sw - 1
  136.         PSet (fx, fy), pal(h(fx, fy) + zmean)
  137.     Next
  138.  
  139. 'display height or potential data points on contour map
  140. For i = 1 To numPoints
  141.     fcirc x(i), sh - y(i), 3, pal(0)
  142.     fcirc x(i), sh - y(i), 2, pal(z(i))
  143. Legend
  144.  
  145. 'show height or potential value for each color in map
  146. Sub Legend
  147.     posy = 20
  148.     ' just draw a balck box where legend is going
  149.     Line (0, 0)-(37, 200), pal(0), BF
  150.     Line (1, 1)-(36, 199), &HFFFFFF40, B
  151.     Color &HFFFFFF40
  152.     _Font 8
  153.     _PrintString (7, 3), "Key"
  154.     For nn = 1 To 15
  155.         Color &HFFFFFF40
  156.         _PrintString (4, posy), Right$(" " + _Trim$(Str$(nn)), 2)
  157.         Line (21, posy + 1)-(32, posy + 5), pal(nn), BF
  158.         posy = posy + 12
  159.     Next
  160.  
  161. Sub fcirc (CX As Long, CY As Long, R As Long, C As _Unsigned Long)
  162.     Dim Radius As Long, RadiusError As Long
  163.     Dim X As Long, Y As Long
  164.     Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
  165.     If Radius = 0 Then PSet (CX, CY), C: Exit Sub
  166.     Line (CX - X, CY)-(CX + X, CY), C, BF
  167.     While X > Y
  168.         RadiusError = RadiusError + Y * 2 + 1
  169.         If RadiusError >= 0 Then
  170.             If X <> Y + 1 Then
  171.                 Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  172.                 Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  173.             End If
  174.             X = X - 1
  175.             RadiusError = RadiusError - X * 2
  176.         End If
  177.         Y = Y + 1
  178.         Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  179.         Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  180.     Wend
  181.  
  182.  

 
Contour Map.PNG

39
Programs / Optical Illusion with Sinc() ?
« on: November 12, 2021, 05:24:49 pm »
Playing around with sinc()...

Code: QB64: [Select]
  1. _Title "Does this light turn yellow?" 'b+ 2021-11-12
  2.  
  3. Screen _NewImage(600, 600, 32)
  4. _ScreenMove 350, 60
  5.     Cls
  6.     For r = 0 To 300
  7.         Circle (300, 300), r, _RGB32(i * Sin(r) / r) ' checking out sinc()
  8.     Next
  9.     i = i + 10
  10.     _Display
  11.     _Limit 60
  12.  

40
Programs / Ascii Plasma!
« on: November 11, 2021, 03:16:00 am »
Look what I found trying to build isobar / contour lines!

Code: QB64: [Select]
  1. _Title  "Ansii Plasma - press spacebar for new set of points, be sure to swirl your mouse in the stuff!"  ' b+ 2021-11-11
  2. _ScreenMove 100, 40
  3.  
  4. Type xy
  5.     x As Single
  6.     y As Single
  7.     dx As Single
  8.     dy As Single
  9.  
  10. Width 150, 80
  11.  
  12. nP = 6
  13. Dim p(1 To nP) As xy, f(6)
  14.  
  15. restart:
  16. For n = 1 To nP
  17.     p(n).x = Rnd * _Width: p(n).y = Rnd * _Height: p(n).dx = .25 * (Rnd * 2 - 1): p(n).dy = 2 * (Rnd * 2 - 1)
  18.     f(n) = n * .015
  19.  
  20. While _KeyDown(27) = 0
  21.     Cls
  22.     If InKey$ = " " Then GoTo restart
  23.     For i = 1 To nP - 1
  24.         p(i).x = p(i).x + p(i).dx
  25.         If p(i).x > _Width - 1 Or p(i).x < 1 Then p(i).dx = -p(i).dx
  26.         If p(i).x < 1 Then p(i).x = 1: If p(i).x > _Width Then p(i).x = _Width
  27.         p(i).y = p(i).y + p(i).dy
  28.         If p(i).y > _Height Or p(i).y < 1 Then p(i).dy = -p(i).dy
  29.         If p(i).y < 1 Then p(i).y = 1: If p(i).y > _Height Then p(i).y = _Height
  30.     Next
  31.     p(nP).x = _MouseX: p(nP).y = _MouseY
  32.     For y = 1 To _Height
  33.         For x = 1 To _Width
  34.             d = 0
  35.             For n = 1 To nP
  36.                 dx = x - p(n).x: dy = y - p(n).y
  37.                 k = Sqr(dx * dx + dy * dy)
  38.                 d = d + (Sin(k * f(n)) + 1) / 2
  39.             Next
  40.             Locate y, x: Print Chr$(Int(d * 20));
  41.         Next
  42.     Next
  43.     _Display
  44.     _Limit 40
  45.  
  46.  
  47.  

41
Programs / Stars (Number guessing program)
« on: November 06, 2021, 11:06:35 pm »
I found this program surfing old Basic code and wondered what it was about:
Code: QB64: [Select]
  1. 10 Print Tab(34); "STARS"
  2. 20 Print Tab(15); "CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY"
  3. 100 Rem *** STARS - PEOPLE'S COMPUTER CENTER, MENLO PARK, CA
  4. 140 Rem *** A IS LIMIT ON NUMBER, M IS NUMBER OF GUESSES
  5. 150 A = 100: M = 7
  6. 170 Input "DO YOU WANT INSTRUCTIONS"; A$
  7. 190 If Left$(A$, 1) = "N" Then 280
  8. 200 Rem *** INSTRUCTIONS ON HOW TO PLAY
  9. 210 Print "I AM THINKING OF A WHOLE NUMBER FROM 1 TO"; A
  10. 220 Print "TRY TO GUESS MY NUMBER.  AFTER YOU GUESS, I"
  11. 230 Print "WILL TYPE ONE OR MORE STARS (*).  THE MORE"
  12. 240 Print "STARS I TYPE, THE CLOSER YOU ARE TO MY NUMBER."
  13. 250 Print "ONE STAR (*) MEANS FAR AWAY, SEVEN STARS (*******)"
  14. 260 Print "MEANS REALLY CLOSE!  YOU GET"; M; "GUESSES."
  15. 270 Rem *** COMPUTER THINKS OF A NUMBER
  16. 280 Print
  17. 290 Print
  18. 300 X = Int(A * Rnd(1) + 1)
  19. 310 Print "OK, I AM THINKING OF A NUMBER, START GUESSING."
  20. 320 Rem *** GUESSING BEGINS, HUMAN GETS M GUESSES
  21. 330 For K = 1 To M
  22.    340 Print
  23.    350 Print "YOUR GUESS";
  24.    360 Input G
  25.    370 If G = X Then 600
  26.    380 D = Abs(G - X)
  27.    390 If D >= 64 Then 510
  28.    400 If D >= 32 Then 500
  29.    410 If D >= 16 Then 490
  30.    420 If D >= 8 Then 480
  31.    430 If D >= 4 Then 470
  32.    440 If D >= 2 Then 460
  33.    450 Print "*";
  34.    460 Print "*";
  35.    470 Print "*";
  36.    480 Print "*";
  37.    490 Print "*";
  38.    500 Print "*";
  39.    510 Print "*";
  40.    520 Print
  41. 530 Next K
  42. 540 Rem *** DID NOT GUESS IN M GUESSES
  43. 550 Print
  44. 560 Print "SORRY, THAT'S"; M; "GUESSES. THE NUMBER WAS"; X
  45. 580 GoTo 650
  46. 590 Rem *** WE HAVE A WINNER
  47. 600 Print: For N = 1 To 79
  48.    610 Print "*";
  49. 620 Next N
  50. 640 Print "YOU GOT IT IN"; K; "GUESSES!!!  LET'S PLAY AGAIN..."
  51. 650 GoTo 280
  52. 660 End
  53.  
  54.  

I translated to more modern Basic and learned a little about LOGs.
Code: QB64: [Select]
  1. _Title "Stars: Guess number 1 to 100, get star rating 1 to 7, get 7 guesses, ...zzz = press any." 'b+ 2021-11-06
  2. 1 Cls: Randomize Timer: GoSub StarChart ' start over
  3. N = Int(100 * Rnd) + 1: nG = 1: Print ' N 'secret number : nG = number of guesses up to 7 allowed
  4. 2 Print " Guess #"; _Trim$(Str$(nG));: Input " enter > ", G
  5. If G = N Then Print "That's it in"; nG; "guesses...zzz": Sleep: GoTo 1
  6. Print " Rating: "; String$(7 - Int(Log(Abs(G - N)) / Log(2)), "* ")
  7. If nG = 7 Then Print "Sorry, that's 7 guesses, the number was"; N; "...zzz": Sleep: GoTo 1
  8. nG = nG + 1: GoTo 2 ' another guess
  9. StarChart: ' number of stars for number you are off
  10. Print Spc(35); "Star Chart:"
  11. For i = 1 To 100 ' this also tests my formula to compare to original game
  12.     If 7 - Int(Log(i) / Log(2)) <> last Then Print Spc(28); "For"; 7 - Int(Log(i) / Log(2)); "Stars, min off ="; i
  13.     last = 7 - Int(Log(i) / Log(2))
  14.  
  15. 'Test code for Star Chart LOG and convert to LOG(2) to convert to Star Rating
  16. 'For p = 0 To 6
  17. '    Print p, Log(2 ^ p) / Log(2) ' yes! When you are of 2 ^ x from number you get 7 - x stars
  18. 'Next
  19.  
  20.  

With the help of the Star Chart (and rewriting the program) it's not hard to pick up the strategy to play the game and usually get the number in 7 guesses.

I should probably reduce the density of the code. It's starting to look like MasterGy's ;-))

42
QB64 Discussion / _ScreenMove _Middle
« on: November 05, 2021, 11:22:35 am »
Is _Middle for _ScreenMove based on the assumption that the Tool bar runs at the top edge?

I just tried _ScreenMove _Middle for a 1024 X 740 screen and _Middle leaves room above the title bar and has the screen bottom below the bottom edge of my computer screen. Limit of Height for me is 740 with title bar.

If I do
Code: QB64: [Select]
  1. _ScreenMove somethingX, 0

will that aggravate everyone who has Tool bars at the top of their screen? Or does 0 go below Tool Bar?

43
Programs / Bas Files Count and List by Recursive Algorithm
« on: November 04, 2021, 11:05:25 pm »
Here is something that might actually be useful, temperamental as hell but I finally got results after several compromises:
 
I had to ChDir to the search Directory to get good results from the GetLists Subroutine. I had never noted that before but it turns out I did do that for Oh Interpreter and other places I successfully used the cross platform files retriever. Dang! It's so frustrating to think you've got something nailed down, go to use it 6 months later and stumble into problems.

Then Windows wont let me ChDir in allot of places where _DirExists so I couldn't just start looking from C:\ for bas files nor even from C:\users\me and my stuff! blah!
But it did work OK from my Desktop and my Downloads Folders where I learn tonight over 10,000 bas files reside.

Takes about 1 sec to do the downloads folder that had 2115 bas files.
Code: QB64: [Select]
  1. _Title "Count BAS files from a start Directory" ' b+ 2021-11-04
  2.  
  3. ' direntry.h needs to be in QB64.exe folder, see below for a commented copy
  4.     Function load_dir& (s As String)
  5.     Function has_next_entry& ()
  6.     Sub close_dir ()
  7.     Sub get_next_entry (s As String, flags As Long, file_size As Long)
  8.  
  9. ReDim Shared BasList$(10000) 'store our Bas pathed Files here
  10. Dim Shared GrandTotal As _Unsigned Long ' ha, ha not that many!
  11.  
  12. FullPathedDir$ = "C:\Users\marka\downloads" ' <<<<<<<<<<<<<  change this line to top directory of your search for
  13. '                                                            best results use places where Windows lets you write bas files.
  14.  
  15. FindAndCountBasFileFrom FullPathedDir$
  16. Print " Grand Total .bas ="; GrandTotal
  17. Open FullPathedDir$ + "\Bas List.txt" For Output As #1
  18. For i = 1 To GrandTotal
  19.     Print #1, BasList$(i)
  20. Print FullPathedDir$ + "\Bas List.txt file is ready."
  21.  
  22.  
  23. Sub FindAndCountBasFileFrom (startDir$)
  24.     If startDir$ <> "." And startDir$ <> ".." And _Trim$(startDir$) <> "" Then
  25.         If Right$(startDir$, 1) <> "\" Then startDir$ = startDir$ + "\"
  26.         If _DirExists(startDir$) Then ChDir startDir$ Else Exit Sub ' >>> There are allot of places where dir exists but cant CD to go!
  27.         'Print "Changing Directory to "; startDir$; ""
  28.         ReDim ds(0) As String, fs(0) As String
  29.         GetLists startDir$, ds(), fs()
  30.         'Print startDir$ + " .bas Files:"
  31.         For i = LBound(fs) To UBound(fs)
  32.             If UCase$(Right$(fs(i), 4)) = ".BAS" Then
  33.                 GrandTotal = GrandTotal + 1
  34.                 Print GrandTotal, startDir$ + fs(i)
  35.                 BasList$(GrandTotal) = startDir$ + fs(i)
  36.                 'If i Mod 20 = 19 Then Print "Press any to cont..": Sleep
  37.             End If
  38.         Next
  39.         'Print
  40.         'Print startDir$ + " Sub-Directories:  zzz...": Sleep
  41.         For j = LBound(ds) To UBound(ds)
  42.             If ds(j) <> "." And ds(j) <> ".." And _Trim$(ds(j)) <> "" Then
  43.                 newD$ = startDir$ + ds(j)
  44.                 'Print "Press any to FindAndCountBasFileFrom " + newD$ + "... zzz": Sleep
  45.                 FindAndCountBasFileFrom newD$
  46.             End If
  47.         Next
  48.         'Print "Press any to cont...": Sleep
  49.     End If
  50.  
  51. Sub GetLists (SearchDirectory As String, DirList() As String, FileList() As String)
  52.  
  53.     '   !!! For this sub to work the _CWD has to be the Search Directory! !!!
  54.  
  55.     ' Thanks SNcNeill ! for a cross platform method to get file and directory lists
  56.     'put this block in main code section of your program close to top
  57.     '' direntry.h needs to be in QB64 folder '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  58.     'DECLARE CUSTOMTYPE LIBRARY ".\direntry"
  59.     '    FUNCTION load_dir& (s AS STRING)
  60.     '    FUNCTION has_next_entry& ()
  61.     '    SUB close_dir ()
  62.     '    SUB get_next_entry (s AS STRING, flags AS LONG, file_size AS LONG)
  63.     'END DECLARE
  64.  
  65.     Const IS_DIR = 1
  66.     Const IS_FILE = 2
  67.     Dim flags As Long, file_size As Long, DirCount As Integer, FileCount As Integer, length As Long
  68.     Dim nam$
  69.     ReDim _Preserve DirList(100), FileList(100)
  70.     DirCount = 0: FileCount = 0
  71.  
  72.     If load_dir(SearchDirectory + Chr$(0)) Then
  73.         Do
  74.             length = has_next_entry
  75.             If length > -1 Then
  76.                 nam$ = Space$(length)
  77.                 get_next_entry nam$, flags, file_size
  78.                 If (flags And IS_DIR) Then
  79.                     DirCount = DirCount + 1
  80.                     If DirCount > UBound(DirList) Then ReDim _Preserve DirList(UBound(DirList) + 1000)
  81.                     DirList(DirCount) = nam$
  82.                 ElseIf (flags And IS_FILE) Then
  83.                     FileCount = FileCount + 1
  84.                     If FileCount > UBound(FileList) Then
  85.                         ReDim _Preserve FileList(UBound(FileList) + 1000)
  86.                         'Print Left$(SearchDirectory, Len(searchDiretory) - 1)
  87.                         'getting allot of wierd misfires
  88.                         If Left$(SearchDirectory, Len(searchDiretory) - 1) = "C:\" Then Exit Sub
  89.                     End If
  90.                     FileList(FileCount) = nam$
  91.                 End If
  92.             End If
  93.         Loop Until length = -1
  94.         'close_dir 'move to after end if  might correct the multi calls problem
  95.     Else
  96.     End If
  97.     close_dir 'this  might correct the multi calls problem
  98.  
  99.     ReDim _Preserve DirList(DirCount)
  100.     ReDim _Preserve FileList(FileCount)
  101.  
  102. '  Remove comments below and save as direntry.h
  103. ' in your QB64.exe folder if you don't have it already
  104. '=============================================================
  105.  
  106. '#include <dirent.h>
  107. '#include <sys/stat.h>
  108. '#include <unistd.h>
  109.  
  110. 'const int IS_DIR_FLAG = 1, IS_FILE_FLAG = 2;
  111.  
  112. 'DIR *pdir;
  113. 'struct dirent *next_entry;
  114. 'struct stat statbuf1;
  115.  
  116. 'char current_dir[FILENAME_MAX];
  117. '#ifdef QB64_WINDOWS
  118. '  #define GetCurrentDir _getcwd
  119. '#else
  120. '  #define GetCurrentDir getcwd
  121. '#endif
  122.  
  123. 'int load_dir (char * path) {
  124. '  struct dirent *pent;
  125. '  struct stat statbuf1;
  126. '//Open current directory
  127. 'pdir = opendir(path);
  128. 'if (!pdir) {
  129. 'return 0; //Didn't open
  130. '}
  131. 'return -1;
  132. '}
  133.  
  134. 'int has_next_entry () {
  135. '  next_entry = readdir(pdir);
  136. '  if (next_entry == NULL) return -1;
  137.  
  138. '  stat(next_entry->d_name, &statbuf1);
  139. '  return strlen(next_entry->d_name);
  140. '}
  141.  
  142. 'void get_next_entry (char * nam, int * flags, int * file_size) {
  143. '  strcpy(nam, next_entry->d_name);
  144. '  if (S_ISDIR(statbuf1.st_mode)) {
  145. '    *flags = IS_DIR_FLAG;
  146. '  } else {
  147. '    *flags = IS_FILE_FLAG;
  148. '  }
  149. '  *file_size = statbuf1.st_size;
  150. '  return ;
  151. '}
  152.  
  153. 'void close_dir () {
  154. '  closedir(pdir);
  155. '  pdir = NULL;
  156. '  return ;
  157. '}
  158.  
  159. 'int current_dir_length () {
  160. '  GetCurrentDir(current_dir, sizeof(current_dir));
  161. '  return strlen(current_dir);
  162. '}
  163.  
  164. 'void get_current_dir(char *dir) {
  165. '  memcpy(dir, current_dir, strlen(current_dir));
  166. '  return ;
  167. '}
  168.  
  169.  

Theoretically this is cross platform, would non Windows users verify?

So how many bas files have you got laying around your computer?

Update: This code has nasty error in it and is missing allot of folders.

44
Programs / Recursive Fills (almost)
« on: November 03, 2021, 01:39:42 am »
I almost have it working, it has a little problem getting around circles, looks kind of interesting though. It's pretty fast! see random tests after first screen.
Code: QB64: [Select]
  1. _Title "Recursive Fill" 'b+ 2021-11-03
  2. Screen _NewImage(800, 600, 32)
  3. _Delay .25
  4.  
  5. Line (110, 200)-Step(580, 200), _RGB32(255, 0, 0), B
  6. Circle (400, 300), 280, _RGB32(255, 0, 0)
  7. 'Circle (400, 300), 200.5, _RGB32(255, 0, 0) ' some circle radius leak like radius = 200
  8. 'Circle (400, 300), 201, _RGB32(255, 0, 0)
  9. fill 400, 300, _RGB32(255, 0, 0)
  10. Line (300, 10)-Step(200, 580), _RGB32(255, 0, 0), B
  11. fill 400, 150, _RGB32(255, 0, 0)
  12. fill 400, 450, _RGB32(255, 0, 0)
  13. While _KeyDown(27) = 0
  14.     Cls
  15.     Line (0, 0)-(_Width - 1, _Height - 1), _RGB32(255, 0, 0), B
  16.     doBoxes = Int(Rnd * 2)
  17.     For i = 1 To 10
  18.         If doBoxes Then Line (Rnd * (_Width - 100) + 50, Rnd * (_Height - 100) + 50)-(Rnd * 100, Rnd * 100), _RGB32(255, 0, 0), B
  19.         x = Rnd * _Width: y = Rnd * _Height: r = Rnd * 50 + 10
  20.         Circle (x, y), r, _RGB32(255, 0, 0)
  21.         Circle (x, y), r + .5, _RGB32(255, 0, 0)
  22.         Circle (x, y), r + 1, _RGB32(255, 0, 0)
  23.     Next
  24.     fill 400, 300, _RGB32(255, 0, 0)
  25.     'Beep
  26.     Sleep
  27.  
  28. Function plus (x, y, c As _Unsigned Long)
  29.     If Point(x, y) <> c Then
  30.         For i = x - 1 To 0 Step -1
  31.             If Point(i, y) = c Then xl = i + 1: Exit For
  32.         Next
  33.         'if xl = 0 then xl = 0
  34.         For i = x + 1 To _Width - 1
  35.             If Point(i, y) = c Then xr = i - 1: Exit For
  36.         Next
  37.         If xr = 0 Then xr = _Width - 1
  38.         For i = y - 1 To 0 Step -1
  39.             If Point(x, i) = c Then yu = i + 1: Exit For
  40.         Next
  41.         'if yu = 0 then yu = 0
  42.         For i = y + 1 To _Height - 1
  43.             If Point(x, i) = c Then yd = i - 1: Exit For
  44.         Next
  45.         If yd = 0 Then yd = _Height - 1
  46.         Line (xl, y)-(xr, y), c
  47.         Line (x, yu)-(x, yd), c
  48.         plus = -1
  49.     End If
  50.  
  51. Sub fill (x, y, c As _Unsigned Long)
  52.     If plus(x, y, c) Then
  53.         fill x - 1, y - 1, c
  54.         fill x - 1, y + 1, c
  55.         fill x + 1, y - 1, c
  56.         fill x + 1, y + 1, c
  57.     End If
  58.  
  59.  

45
Programs / How Many Recursive Calls Can Your System Take?
« on: November 02, 2021, 12:01:23 pm »
Find out here!

Code: QB64: [Select]
  1. _Title "About How Many Recursive Calls Can Your Systen Take?" ' b+ 2021-11-02
  2. Screen _NewImage(800, 600, 32)
  3. Dim Shared recurrance
  4. Print "Pausing a second at every 1000."
  5. Line (150, 100)-Step(501, 401), &HFFFFFF00, B
  6. Fill 151, 101, &HFFFFFF00
  7.  
  8. Sub Fill (x, y, kolor As _Unsigned Long)
  9.     recurrance = recurrance + 1
  10.     Locate 3, 1: Print Space$(10)
  11.     Locate 3, 1: Print recurrance
  12.     If recurrance Mod 1000 = 0 Then _Delay 1 Else _Delay .01
  13.     If Point(x, y) <> kolor Then PSet (x, y), kolor
  14.     If Point(x + 1, y) <> kolor Then Fill x + 1, y, kolor
  15.     If Point(x - 1, y) <> kolor Then Fill x - 1, y, kolor
  16.     If Point(x, y + 1) <> kolor Then Fill x, y + 1, kolor
  17.     If Point(x, y - 1) <> kolor Then Fill x, y - 1, kolor
  18.  
  19.  

Mine died at 1810.

No that was 18010 I think 2md time was 18009.

Pages: 1 2 [3] 4 5 ... 21