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 ... 21
1
QB64 Discussion / Tip: get your pathed program file name
« on: April 15, 2022, 11:39:33 pm »
Code: QB64: [Select]
  1. PathedFile$ = Command$(0) 'or process commands sent
  2. Print PathedFile$
  3.  

  [ You are not allowed to view this attachment ]  

2
Programs / Better Bench by Ed Davis
« on: April 11, 2022, 04:15:53 pm »
Generic Basic code convert to QB64 by me for timing and Types:
Code: QB64: [Select]
  1. DefLng A-Z
  2. Dim As Double x, y, xx, yy, start
  3. start = Timer(.001)
  4. accum = 0
  5. count = 0
  6. While count < 1545
  7.     leftedge = -420
  8.     rightedge = 300
  9.     topedge = 300
  10.     bottomedge = -300
  11.     xstep = 7
  12.     ystep = 15
  13.  
  14.     maxiter = 200
  15.  
  16.     y0 = topedge
  17.     While y0 > bottomedge
  18.         x0 = leftedge
  19.         While x0 < rightedge
  20.             y = 0
  21.             x = 0
  22.             thechar = 32
  23.             xx = 0
  24.             yy = 0
  25.             i = 0
  26.             While i < maxiter And xx + yy <= 800
  27.                 xx = Int((x * x) / 200)
  28.                 yy = Int((y * y) / 200)
  29.                 If xx + yy > 800 Then
  30.                     thechar = 48 + i
  31.                     If i > 9 Then
  32.                         thechar = 64
  33.                     End If
  34.                 Else
  35.                     temp = xx - yy + x0
  36.                     If (x < 0 And y > 0) Or (x > 0 And y < 0) Then
  37.                         y = (-1 * Int((-1 * x * y) / 100)) + y0  ' << this line was revised in later post
  38.                     Else
  39.                         y = Int(x * y / 100) + y0
  40.                     End If
  41.                     x = temp
  42.                 End If
  43.  
  44.                 i = i + 1
  45.             Wend
  46.             x0 = x0 + xstep
  47.             accum = accum + thechar
  48.         Wend
  49.         y0 = y0 - ystep
  50.     Wend
  51.  
  52.     If count Mod 300 = 0 Then
  53.         Print accum,
  54.     End If
  55.     count = count + 1
  56.  
  57. Print accum
  58. Print Timer(.001) - start; " seconds"
  59.  
  60. 'This is the output:
  61.  
  62. ' 200574 60372774 120544974 180717174 240889374 301061574 309886830
  63.  
  64.  
I added DEFLNG A-Z and Dim as Double x, y, xx, yy
and I got below 10 secs on Timer with $Checking:Off, 9.61 was best time with everything turned off including Wifi.

Ed has QB64 down for 9.35 secs maybe on better machine...
http://basic4all.epizy.com/index.php?topic=21.msg166#msg166

Can anyone make a significant drop? FreeBasic at top at 1.09 secs

3
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.

4
Programs / Easter Egg Decorating
« on: March 29, 2022, 09:03:33 pm »
For Ken,

Code: QB64: [Select]
  1. _Title "Eggs o Dozens" 'b+ 2022-03-29
  2. Const Xmax = 1200, Ymax = 400, Pi = _Pi
  3. Screen _NewImage(Xmax, Ymax, 32)
  4. _ScreenMove 100, 100
  5. scale = 96
  6.     For y = 100 To 300 Step 200
  7.         For x = 100 To 1100 Step 200
  8.             drawEasterEgg x, y, scale, 0
  9.         Next
  10.     Next
  11.     _Delay 1
  12.  
  13. Sub drawEasterEgg (xc, yc, scale, radianAngle)
  14.     r = Rnd: g = Rnd: b = Rnd
  15.     For x = -1 To 1 Step .01
  16.         For y = -1 To 1 Step .01
  17.             If x < 0 Then c = c + .0005 Else c = c - .0005
  18.             If (x * x + (1.4 ^ x * 1.6 * y) ^ 2 - 1) <= .01 Then
  19.                 If y > 0 Then
  20.                     Color _RGB32(128 * (1 - y) + 128 * (1 - y) * Sin(c * r), 128 * (1 - y) + 128 * (1 - y) * Sin(c * g), 127 * (1 - y) + 127 * (1 - y) * Sin(c * b))
  21.                 Else
  22.                     Color _RGB32(128 + 128 * Sin(c * r), 128 + 128 * Sin(c * g), 127 + 127 * Sin(c * b))
  23.                 End If
  24.                 a = _Atan2(y, x)
  25.                 d = scale * Sqr(x * x + y * y)
  26.                 PSet (xc + d * Cos(a + radianAngle), yc + d * Sin(a + radianAngle))
  27.             End If
  28.         Next
  29.     Next
  30.  
  31.  
  32.  

 
Eggs o Dozens.PNG


5
Programs / Random Latin Squares - Rosetta Code
« on: March 25, 2022, 08:02:07 pm »
See Rosetta Code:  http://rosettacode.org/wiki/Random_Latin_squares

Code: QB64: [Select]
  1. _Title "Random Latin Squares - Rosetta Code" ' b+ 2022-03-25
  2. ' ref http://rosettacode.org/wiki/Random_Latin_squares
  3. Dim test, i, j
  4. ReDim b%(0, 0)
  5. Print "As required by RC:"
  6. For test = 1 To 2
  7.     n = 5
  8.     RandomLatinSquare n, b%()
  9.     displayLatinSquare n, b%()
  10. Print "Showing off:"
  11. For n = 2 To 16
  12.     RandomLatinSquare n, b%()
  13.     displayLatinSquare n, b%()
  14.  
  15. Sub RandomLatinSquare (n As Integer, RtnArray%())
  16.     Dim As Integer a(0 To n - 1), b(0 To n - 1)
  17.     For i = 0 To n - 1
  18.         a(i) = i: b(i) = i
  19.     Next
  20.     For i = n - 1 To 1 Step -1
  21.         Swap a(Int((i + 1) * Rnd)), a(i)
  22.         Swap b(Int((i + 1) * Rnd)), b(i)
  23.     Next
  24.     ReDim RtnArray%(0 To n - 1, 0 To n - 1)
  25.     For i = 0 To n - 1
  26.         For j = 0 To n - 1
  27.             RtnArray%(j, i) = (a(j) + b(i)) Mod n
  28.         Next
  29.     Next
  30.  
  31. Function pad$ (n, nSpaces)
  32.     pad$ = Right$(Space$(nSpaces) + _Trim$(Str$(n)), nSpaces)
  33.  
  34. Sub displayLatinSquare (n As Integer, b%())
  35.     For i = 0 To n - 1
  36.         For j = 0 To n - 1
  37.             If n < 10 Then Print pad$(b%(j, i), 2); Else Print pad$(b%(j, i), 3);
  38.         Next
  39.         Print
  40.     Next
  41.     Print
  42.  
  43.  
  44.  

Some low hanging fruit, no FreeBasic (or any other Basic) version yet!?

6
Programs / Boids Remake 2022-03
« on: March 19, 2022, 08:47:11 pm »
With some great tips from tsh73 at LB here is a better version of Boids:
Code: QB64: [Select]
  1. _Title "Boids Remake 2022-03" ' b+ 2022-03-19
  2. ' from JB Boids Restart #6 Wings b+ 2022-03-19
  3.  
  4. Const xmax = 1200, ymax = 700, pi = _Pi, nb = 100, no = 7, np = 3
  5. Const green = _RGB32(0, 160, 0), blue = _RGB32(0, 0, 160), black = _RGB32(0, 0, 0), brown = _RGB32(100, 80, 40)
  6. Dim As Long done, headmode, centermode, i, j, testx, testy, iter
  7. Dim As Single hf, cf, t1, s, ao, dist
  8.  
  9. Dim As Single px(np), py(np), pa(np) ' Predator radius is const 10 or so, twice a bird at least
  10. Dim As Single ox(no), oy(no), ord(no) ' obstacle x, y, radius
  11. Dim As Single bx(nb), by(nb), ba(nb), da(nb, nb) ' new  da = distance array
  12. Dim As Long pw(np), bw(nb)
  13. headmode = 1 ' on / off
  14. hf = .3 ' % of 100 pixels distance .1 = 10
  15.  
  16. centermode = 0 ' on / off
  17. cf = .2 'centering factor how strong a pull from 0 to 1  .01 is week .1 pretty strong!
  18.  
  19. Screen _NewImage(xmax, ymax, 32)
  20. _ScreenMove 100, 20
  21.  
  22. For i = 1 To no ' in array for redraw
  23.     ox(i) = rand(90, xmax - 90): oy(i) = rand(90, ymax - 90): ord(i) = rand(25, 90)
  24. For i = 1 To nb
  25.     testAgain: ' don't start a bird inside an obstacle
  26.     testx = rand(20, xmax - 20) ' start random screen x, y away from borders
  27.     testy = rand(20, ymax - 20)
  28.     j = 0
  29.     While j < no ' note get strange results with For loop
  30.         j = j + 1
  31.         If distance(testx, testy, ox(j), oy(j)) < ord(j) + 10 Then GoTo testAgain
  32.     Wend
  33.     j = 0
  34.     While j < i - 1 'no bird crowds please  note get strange results with For loop
  35.         j = j + 1
  36.         If distance(testx, testy, bx(j), by(j)) < 15 Then GoTo testAgain
  37.     Wend
  38.     bx(i) = testx: by(i) = testy: ba(i) = 2 * pi * Rnd: bw(i) = Int(3 * Rnd) ' random headings
  39. For i = 1 To np ' might be smarter to pack the smaller after the larger, ie do predators before birds
  40.     testAgain2: ' don't start a predator inside an obstacle
  41.     testx = rand(40, xmax - 40) ' start random screen x, y away from borders
  42.     testy = rand(40, ymax - 40)
  43.     j = 0
  44.     While j < no ' note get strange results with For loop
  45.         j = j + 1
  46.         If distance(testx, testy, ox(j), oy(j)) < ord(j) + 10 Then GoTo testAgain2
  47.     Wend
  48.     j = 0
  49.     While j < nb ' give birds some space from predators too
  50.         j = j + 1
  51.         If distance(testx, testy, bx(j), by(j)) < 30 Then GoTo testAgain2
  52.     Wend
  53.     px(i) = testx: py(i) = testy: pa(i) = 2 * pi * Rnd: pw(i) = Int(5 * Rnd)
  54. t1 = Timer(.001)
  55. Color , green
  56. While _KeyDown(27) = 0
  57.     Cls
  58.     For i = 1 To no
  59.         fcirc ox(i), oy(i), ord(i), brown
  60.     Next
  61.     For i = 1 To nb - 1 ' find all the distances between birds
  62.         For j = i + 1 To nb ' fix bonehead error of doing this 2x's! thanks tsh73 for catch!
  63.             da(i, j) = distance(bx(i), by(i), bx(j), by(j))
  64.             da(j, i) = da(i, j) ' symetric relationship
  65.         Next
  66.     Next
  67.  
  68.     For i = 1 To np ' Predators are just like a birds
  69.         pw(i) = (1 + pw(i)) Mod 5 ' flapper wings or not
  70.         DrawBird px(i), py(i), 15, pa(i), pw(i), blue
  71.         s = Rnd * 4 + 3 ' get some bird separation here?
  72.         px(i) = px(i) + s * Cos(pa(i)): py(i) = py(i) + s * Sin(pa(i))
  73.         j = 0
  74.         While j < no ' note get strange results with For loop
  75.             j = j + 1
  76.             If distance(px(i), py(i), ox(j), oy(j)) < ord(j) + 23 Then
  77.                 ao = _Atan2(oy(j) - py(i), ox(j) - px(i))
  78.                 pa(i) = AngleAve(pa(i), ao - pi)
  79.             End If
  80.         Wend
  81.         ' JB&LB have better Mod function! tsh73 pointed it to me
  82.         px(i) = Mod2(px(i) + xmax, xmax)
  83.         py(i) = Mod2(py(i) + ymax, ymax)
  84.         ' except predators don't flock
  85.     Next
  86.  
  87.     For i = 1 To nb 'draw then update positions of birds
  88.         ' draw current
  89.         bw(i) = (bw(i) + 1) Mod 4 ' flapper wings or not
  90.         DrawBird bx(i), by(i), 8, ba(i), bw(i), black
  91.         s = rand(3, 7) ' get some bird separation here?
  92.         bx(i) = bx(i) + s * Cos(ba(i)): by(i) = by(i) + s * Sin(ba(i))
  93.         j = 0
  94.         While j < no ' note get strange results with For loop
  95.             j = j + 1
  96.             If distance(bx(i), by(i), ox(j), oy(j)) < ord(j) + 13 Then
  97.                 ao = _Atan2(oy(j) - by(i), ox(j) - bx(i))
  98.                 ba(i) = AngleAve(ba(i), ao - pi)
  99.             End If
  100.         Wend
  101.         j = 0
  102.         While j < np
  103.             j = j + 1
  104.             If distance(bx(i), by(i), px(j), py(j)) < 65 Then
  105.                 ao = _Atan2(py(j) - by(i), px(j) - bx(i))
  106.                 ba(i) = AngleAve(ba(i), ao - pi)
  107.             End If
  108.         Wend
  109.         ' JB&LB have better Mod function! tsh73 pointed it to me
  110.         bx(i) = Mod2(bx(i) + xmax, xmax)
  111.         by(i) = Mod2(by(i) + ymax, ymax)
  112.  
  113.         For j = i + 1 To nb
  114.             dist = da(i, j)
  115.             If dist < 50 Then ' birds are close enough to influence each other by visual
  116.                 'sway the neighbors headings towards each other
  117.                 If headmode And Rnd < hf Then
  118.                     ba(i) = AngleAve(ba(i), AngleAve(ba(i), ba(j)))
  119.                     ba(j) = AngleAve(ba(j), AngleAve(ba(i), ba(j)))
  120.                 End If
  121.             End If
  122.             If dist > 30 And dist < 100 Then
  123.                 'stickiness stay close to neighbors, close distance between
  124.                 If centermode And Rnd < cf Then
  125.                     bx(i) = bx(i) - cf / 10 * (bx(i) - bx(j))
  126.                     bx(j) = bx(j) + cf / 10 * (bx(i) - bx(j))
  127.                     by(i) = by(i) - cf / 10 * (by(i) - by(j))
  128.                     by(j) = by(j) + cf / 10 * (by(i) - by(j))
  129.                 End If
  130.             End If
  131.             If dist < 20 Then ' too close!!!
  132.                 bx(i) = bx(i) + .1 * (bx(i) - bx(j))
  133.                 bx(j) = bx(j) - .1 * (bx(i) - bx(j))
  134.                 by(i) = by(i) + .1 * (by(i) - by(j))
  135.                 by(j) = by(j) - .1 * (by(i) - by(j))
  136.             End If
  137.         Next 'j
  138.     Next ' i
  139.     _Display
  140.     _Limit 10
  141.  
  142. Function rand& (lo As Long, hi As Long) 'rand integer between lo and hi iclusive
  143.     rand& = Int((hi - lo + 1) * Rnd + lo)
  144.  
  145. Function distance (x1, y1, x2, y2) ' default single OK
  146.     distance = Sqr((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))
  147.  
  148. Function AngleAve (ra1, ra2) ' default single OK
  149.     Dim twoPi, ray1, ray2, rtn
  150.     twoPi = pi * 2
  151.     ray1 = Mod2(ra1 + twoPi, twoPi)
  152.     ray2 = Mod2(ra2 + twoPi, twoPi)
  153.     rtn = (ray1 + ray2) / 2
  154.     If Abs(ray1 - ray2) > pi Then rtn = Mod2(rtn - pi + twoPi, twoPi)
  155.     AngleAve = rtn
  156.  
  157. Sub DrawBird (xc, yc, rr, ra, wings As Integer, c As _Unsigned Long)
  158.     Dim x1, y1, x2, y2, x3, y3
  159.     x1 = xc + rr * Cos(ra)
  160.     y1 = yc + rr * Sin(ra)
  161.     x2 = xc + rr * Cos(ra - .9 * pi)
  162.     y2 = yc + rr * Sin(ra - .9 * pi)
  163.     x3 = xc + rr * Cos(ra + .9 * pi)
  164.     y3 = yc + rr * Sin(ra + .9 * pi)
  165.     ftri x1, y1, xc, yc, x2, y2, c
  166.     ftri x1, y1, xc, yc, x3, y3, c
  167.     If wings Then
  168.         x2 = xc + 2 * rr * Cos(ra - 1.57 * pi)
  169.         y2 = yc + 2 * rr * Sin(ra - 1.57 * pi)
  170.         x3 = xc + 2 * rr * Cos(ra + 1.57 * pi)
  171.         y3 = yc + 2 * rr * Sin(ra + 1.57 * pi)
  172.         ftri xc, yc, x2, y2, x3, y3, c
  173.     End If
  174.  
  175. ' this allows us to do floats including negative floats
  176. Function Mod2# (n As Double, modulus As Double)
  177.     Dim rtn As Double
  178.     rtn = modulus * (Abs(n) / modulus - Int(Abs(n) / modulus))
  179.     If n < 0 Then rtn = -rtn
  180.     Mod2# = rtn
  181.  
  182. Sub fcirc (CX As Long, CY As Long, R As Long, C As _Unsigned Long)
  183.     Dim Radius As Long, RadiusError As Long
  184.     Dim X As Long, Y As Long
  185.     Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
  186.     If Radius = 0 Then PSet (CX, CY), C: Exit Sub
  187.     Line (CX - X, CY)-(CX + X, CY), C, BF
  188.     While X > Y
  189.         RadiusError = RadiusError + Y * 2 + 1
  190.         If RadiusError >= 0 Then
  191.             If X <> Y + 1 Then
  192.                 Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  193.                 Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  194.             End If
  195.             X = X - 1
  196.             RadiusError = RadiusError - X * 2
  197.         End If
  198.         Y = Y + 1
  199.         Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  200.         Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  201.     Wend
  202.  
  203. Sub ftri (x1, y1, x2, y2, x3, y3, K As _Unsigned Long)
  204.     Dim D As Long
  205.     Static a&
  206.     D = _Dest
  207.     If a& = 0 Then a& = _NewImage(1, 1, 32)
  208.     _Dest a&
  209.     _DontBlend a& '  '<<<< new 2019-12-16 fix
  210.     PSet (0, 0), K
  211.     _Blend a& '<<<< new 2019-12-16 fix
  212.     _Dest D
  213.     _MapTriangle _Seamless(0, 0)-(0, 0)-(0, 0), a& To(x1, y1)-(x2, y2)-(x3, y3)
  214.  
  215.  
Boids Remake 2022-03.PNG


EDIT: I had an FPS iteration counter but it wasn't working and I don't need it anyway for QB64.

7
Programs / Determinant of a (Square Integer) Matrix
« on: March 11, 2022, 09:52:48 pm »
By recursive calls:
Code: QB64: [Select]
  1. Option _Explicit ' determinantOfMatrix.bas b+ 2022-03-11 translate from
  2. ''''// C++ program to find Determinant of a matrix
  3. ''''#include <iostream>
  4. ''''using namespace std;
  5. ' Hope the above isn't important because WTH?
  6.  
  7. ''''// Dimension of input square matrix
  8. ''''#define N 4
  9. ' Again not sure??  oh this is for testing 4 x 4, the 3 x 3 is commented out
  10.  
  11.  
  12.  
  13.  
  14. ''''// Driver program to test above functions
  15. ' that are defined below :)
  16.  
  17. ''''int main()
  18. ''''{
  19. ''''    /* int mat[N][N] = {{6, 1, 1},
  20. ''''                     {4, -2, 5},
  21. ''''                     {2, 8, 7}}; */
  22.  
  23. ''''    int mat[N][N] = { { 1, 0, 2, -1 },
  24. ''''                      { 3, 0, 0, 5 },
  25. ''''                      { 2, 1, 4, -3 },
  26. ''''                      { 1, 0, 5, 0 } };
  27. ' well crap we need a way to read in a Matrix from a string
  28.  
  29. Dim m$
  30. m$ = "1,2;3,4"
  31. ReDim As Integer mat(0, 0)
  32. readStr2Mat m$, mat()
  33. displayMat mat(), 2, 2
  34. Print " D ="; determinantOfMatrix%(mat(), 2)
  35. m$ = "2, -3,1;2,0,-1 ;1, 4, 5"
  36. ReDim As Integer mat(0, 0)
  37. readStr2Mat m$, mat()
  38. displayMat mat(), 3, 3
  39. Print " D ="; determinantOfMatrix%(mat(), 3)
  40. m$ = "1, 0, 2, -1;3, 0, 0, 5;2, 1, 4, -3;1, 0, 5, 0 "
  41. ReDim As Integer mat(0, 0)
  42. readStr2Mat m$, mat()
  43. displayMat mat(), 4, 4
  44. Print " D ="; determinantOfMatrix%(mat(), 4)
  45.  
  46. ''''    // Function call
  47. ''''    cout <<"Determinant of the matrix is : " << determinantOfMatrix(mat, N);
  48. ''''    return 0;
  49. ''''}
  50.  
  51. ''''// this code is contributed by shivanisinghss2110
  52. ''''Output
  53.  
  54.  
  55. ' Move from near start to end
  56. ''''// Function to get cofactor of mat[p][q] in temp[][]. n is
  57. ''''// current dimension of mat[][]
  58. ''''void getCofactor(int mat[N][N], int temp[N][N], int p,
  59. ''''                 int q, int n)
  60.  
  61. Sub getCofactor (mat() As Integer, temp() As Integer, p As Integer, q As Integer, n As Integer)
  62.     Dim row, col, i, j
  63.     'Print "getCoFactor p, q, n: "; p, q, n
  64.  
  65.     ''''{
  66.     ''''    int i = 0, j = 0;
  67.  
  68.     ''''    // Looping for each element of the matrix
  69.     ''''    for (int row = 0; row < n; row++)
  70.     ''''    {
  71.     ''''        for (int col = 0; col < n; col++)
  72.     ''''        {
  73.     For row = 0 To n - 1
  74.         For col = 0 To n - 1
  75.  
  76.             ''''            //  Copying into temporary matrix only those
  77.             ''''            //  element which are not in given row and
  78.             ''''            //  column
  79.             ''''            if (row != p && col != q)
  80.             If (row <> p) And (col <> q) Then
  81.                 ''''            {
  82.                 ''''                temp[i][j++] = mat[row][col];
  83.  
  84.                 ' is j increased before or after temp(i, j) is assigned???
  85.                 temp(i, j) = mat(row, col)
  86.                 j = j + 1 ' I think j should be increased after temp copy  so temp(0,0) is filled
  87.                 If j = n - 1 Then
  88.                     j = 0: i = i + 1
  89.                 End If
  90.  
  91.                 ''''                // Row is filled, so increase row index and
  92.                 ''''                // reset col index
  93.                 ''''                if (j == n - 1)
  94.                 ''''                {
  95.                 ''''                    j = 0;
  96.                 ''''                    i++;
  97.                 ''''                }
  98.                 ''''            }
  99.                 ''''        }
  100.                 ''''    }
  101.                 ''''}
  102.             End If
  103.         Next
  104.     Next
  105.  
  106.  
  107. ' also moved
  108. ''''/* Recursive function for finding determinant of matrix.
  109. ''''   n is current dimension of mat[][]. */
  110. ''''int determinantOfMatrix(int mat[N][N], int n)
  111. Function determinantOfMatrix% (mat() As Integer, n As Integer)
  112.     ''''{
  113.     ''''    int D = 0; // Initialize result
  114.     Dim As Integer D, sign, f
  115.  
  116.     ''''    //  Base case : if matrix contains single element
  117.     ''''    if (n == 1)
  118.     ''''        return mat[0][0];
  119.  
  120.     If n = 1 Then
  121.         determinantOfMatrix% = mat(0, 0)
  122.     Else
  123.         ''''    int temp[N][N]; // To store cofactors
  124.         Dim temp(n, n) As Integer
  125.         ''''    int sign = 1; // To store sign multiplier
  126.         sign = 1
  127.  
  128.         ''''    // Iterate for each element of first row
  129.         ''''    for (int f = 0; f < n; f++)
  130.         For f = 0 To n - 1
  131.  
  132.             ''''    {
  133.             ''''        // Getting Cofactor of mat[0][f]
  134.             ''''        getCofactor(mat, temp, 0, f, n);
  135.             getCofactor mat(), temp(), 0, f, n
  136.             ''''        D += sign * mat[0][f]
  137.             ''''             * determinantOfMatrix(temp, n - 1);
  138.             D = D + sign * mat(0, f) * determinantOfMatrix%(temp(), n - 1)
  139.             ''''        // terms are to be added with alternate sign
  140.             ''''        sign = -sign;
  141.             sign = -sign
  142.             ''''    }
  143.         Next
  144.         ''''    return D;
  145.         determinantOfMatrix% = D
  146.     End If
  147.     ''''}
  148.  
  149. 'also moved
  150. ''''/* function for displaying the matrix */
  151. ''''void display(int mat[N][N], int row, int col)
  152. Sub displayMat (mat() As Integer, row As Integer, col As Integer)
  153.     Dim As Integer i, j
  154.     ''''{
  155.     ''''    for (int i = 0; i < row; i++)
  156.     ''''    {
  157.     ''''        for (int j = 0; j < col; j++)
  158.     ''''            cout <<"  " <<  mat[i][j];
  159.     ''''        cout <<"n";
  160.     ' the hell
  161.     For i = 0 To row - 1
  162.         For j = 0 To col - 1
  163.             Print Right$("   " + _Trim$(Str$(mat(i, j))), 3); ' hey no more than 2 digit numbers OK?
  164.             ''''    }
  165.             ''''}
  166.         Next
  167.         Print
  168.     Next
  169.  
  170. Sub readStr2Mat (s$, mat() As Integer) ' commas separate columns, semi-colons separate rows
  171.     Dim As Integer i, j
  172.     ReDim rows$(0)
  173.     Split s$, ";", rows$()
  174.     ReDim As Integer mat(UBound(rows$), UBound(rows$))
  175.     For i = 0 To UBound(rows$)
  176.         ReDim nums$(0)
  177.         Split rows$(i), ",", nums$()
  178.         For j = 0 To UBound(nums$)
  179.             mat(i, j) = Val(nums$(j))
  180.         Next
  181.     Next
  182.  
  183. Sub Split (SplitMeString As String, delim As String, loadMeArray() As String)
  184.     Dim curpos As Long, arrpos As Long, LD As Long, dpos As Long 'fix use the Lbound the array already has
  185.     curpos = 1: arrpos = LBound(loadMeArray): LD = Len(delim)
  186.     dpos = InStr(curpos, SplitMeString, delim)
  187.     Do Until dpos = 0
  188.         loadMeArray(arrpos) = Mid$(SplitMeString, curpos, dpos - curpos)
  189.         arrpos = arrpos + 1
  190.         If arrpos > UBound(loadMeArray) Then ReDim _Preserve loadMeArray(LBound(loadMeArray) To UBound(loadMeArray) + 1000) As String
  191.         curpos = dpos + LD
  192.         dpos = InStr(curpos, SplitMeString, delim)
  193.     Loop
  194.     loadMeArray(arrpos) = Mid$(SplitMeString, curpos)
  195.     ReDim _Preserve loadMeArray(LBound(loadMeArray) To arrpos) As String 'get the ubound correct
  196.  
  197.  

8
QB64 Discussion / Is Discord down?
« on: March 08, 2022, 02:19:24 pm »
Doesn't seem to be allowing me in.

9
Programs / Eye Candy
« on: March 06, 2022, 10:03:07 pm »
Code: QB64: [Select]
  1. _Title "Sprezzo #2 Problem 2022-03-06"
  2. Const SQ = 700, SQd2 = SQ / 2
  3. Screen _NewImage(SQ, SQ, 32)
  4. _ScreenMove 300, 60
  5. Dim Shared As Single cN, pR, pG, pB
  6. Dim diag, pi2, i, a, di, r, s
  7. diag = SQd2 * Sqr(2)
  8. pi2 = _Pi(2)
  9.  
  10. Dim colr~&(-1000 To diag + 1000)
  11.     resetPlasma
  12.     For i = -1000 To diag + 1000
  13.         colr~&(i) = Plasma~&
  14.     Next
  15.     di = 1: s = 0
  16.     For a = 0 To pi2 Step pi2 / (16 * 360)
  17.         i = 50 * Sin(s) ' 2 * s or just s
  18.         For r = 0 To diag
  19.             PSet (SQd2 + r * Cos(a), SQd2 + r * Sin(a)), colr~&(r + i)
  20.         Next
  21.         's = s + _Pi(1 / 128)
  22.         s = s + pi2 / 180 ' for almost seamless connect  
  23.     Next
  24.     Sleep
  25.  
  26. Function Plasma~& ()
  27.     cN = cN + .5 'dim shared cN as _Integer64, pR as long, pG as long, pB as long
  28.     Plasma~& = _RGB32(127 + 127 * Sin(pR * cN), 127 + 127 * Sin(pG * cN), 127 + 127 * Sin(pB * cN))
  29.  
  30. Sub resetPlasma ()
  31.     pR = Rnd ^ 2: pG = Rnd ^ 2: pB = Rnd ^ 2
  32.  
  33.  
spectacular.PNG

10
QB64 Discussion / &H colors dont work as CONST
« on: March 03, 2022, 11:49:47 am »
Use to work with POINT, what happened?

Doesn't appear to work way back before 1.4 even.


11
Programs / Rotating Pyramid
« on: March 01, 2022, 09:20:09 am »
Another quickie for this morning and Aurels Forum: http://basic4all.info8-hosting.info/index.php

Showing Aurel how he might do this more satisfactory with his MicroA interpreter with this QB64 example:
Code: QB64: [Select]
  1. _Title "Rotating Pyramid" 'b+ 2022-03-01
  2. cx = _Width / 2
  3. ax = cx: ay = 50 ' apex
  4. ex = cx: ey = 330 ' ellipse
  5. xr = cx * .7: yr = .33 * xr
  6.     Cls
  7.     x1 = ex + xr * Cos(a): y1 = ey + yr * Sin(a)
  8.     x2 = ex + xr * Cos(a + _Pi * .5): y2 = ey + yr * Sin(a + _Pi * .5)
  9.     x3 = ex + xr * Cos(a + _Pi): y3 = ey + yr * Sin(a + _Pi)
  10.     x4 = ex + xr * Cos(a + _Pi * 1.5): y4 = ey + yr * Sin(a + _Pi * 1.5)
  11.     l x1, y1, x2, y2
  12.     l x2, y2, x3, y3
  13.     l x3, y3, x4, y4
  14.     l x4, y4, x1, y1
  15.     l x1, y1, ax, ay
  16.     l x2, y2, ax, ay
  17.     l x3, y3, ax, ay
  18.     l x4, y4, ax, ay
  19.     a = a + .01
  20.     _Display
  21.     _Limit 30
  22.  
  23. Sub l (a, b, c, d) ' this is just way easier to code lines Aurel you dont need this part
  24.     Line (a, b)-(c, d)
  25.  

 
QB64 Rotate Pyramid.PNG

12
Programs / Bump N Go Car Toy
« on: March 01, 2022, 08:19:18 am »
Spriggsy suggested this to me at Discord:
Code: QB64: [Select]
  1. _Title "Bump N Go - Drive Car" 'b+ 2022-03-01
  2. ' b+ mod of Drive Car (Graphics Dir) 'b+ 2021-09-29
  3.  
  4. Type car
  5.     As Single x, y, w, h, ra, speed
  6.     As _Unsigned Long c
  7.  
  8. Dim blue As car
  9. blue.x = _Width / 2: blue.y = _Height / 2
  10. blue.w = 20: blue.h = 40
  11. blue.ra = _Pi / 2: blue.speed = 2
  12. blue.c = 9
  13.  
  14. While _KeyDown(27) = 0
  15.     If blue.speed = 0 Then
  16.         blue.ra = _Atan2(blue.y - _Height / 2, blue.x - _Width / 2) + _Pi + Rnd * -.5
  17.         blue.speed = .1
  18.     End If
  19.     blue.speed = blue.speed + .5
  20.     Cls
  21.     blue.x = blue.x + blue.speed * Cos(blue.ra)
  22.     blue.y = blue.y + blue.speed * Sin(blue.ra)
  23.     If blue.x < 10 Or blue.x > _Width - 10 Then blue.speed = 0
  24.     If blue.y < 10 Or blue.y > _Height - 10 Then blue.speed = 0
  25.     drawCar blue
  26.     _Display ' stop flicker
  27.     _Limit 30 ' loops per sec
  28.  
  29. Sub drawCar (a As car)
  30.     ' code not optimized for speed  just proff of concept
  31.     X1 = a.x + a.h / 2 * Cos(a.ra)
  32.     Y1 = a.y + a.h / 2 * Sin(a.ra)
  33.     X2 = X1 + a.w / 2 * Cos(a.ra + _Pi / 2)
  34.     Y2 = Y1 + a.w / 2 * Sin(a.ra + _Pi / 2)
  35.     X3 = X1 + a.w / 2 * Cos(a.ra - _Pi / 2)
  36.     Y3 = Y1 + a.w / 2 * Sin(a.ra - _Pi / 2)
  37.  
  38.     x4 = a.x + a.h / 2 * Cos(a.ra - _Pi)
  39.     y4 = a.y + a.h / 2 * Sin(a.ra - _Pi)
  40.     x5 = x4 + a.w / 2 * Cos(a.ra + _Pi / 2)
  41.     y5 = y4 + a.w / 2 * Sin(a.ra + _Pi / 2)
  42.     x6 = x4 + a.w / 2 * Cos(a.ra - _Pi / 2)
  43.     y6 = y4 + a.w / 2 * Sin(a.ra - _Pi / 2)
  44.  
  45.     Line (X2, Y2)-(X3, Y3), a.c
  46.     Line (X3, Y3)-(x6, y6), a.c
  47.     Line (x6, y6)-(x5, y5), a.c
  48.     Line (x5, y5)-(X2, Y2), a.c
  49.     Paint (a.x, a.y), a.c, a.c
  50.     Line (X2, Y2)-(X3, Y3), 15 ' give car a front
  51.  
  52.     ' white top  for all cars for future numbers maybe
  53.     X1 = a.x + a.h / 4 * Cos(a.ra)
  54.     Y1 = a.y + a.h / 4 * Sin(a.ra)
  55.     X2 = X1 + (a.w / 2 - 3) * Cos(a.ra + _Pi / 2)
  56.     Y2 = Y1 + (a.w / 2 - 3) * Sin(a.ra + _Pi / 2)
  57.     X3 = X1 + (a.w / 2 - 3) * Cos(a.ra - _Pi / 2)
  58.     Y3 = Y1 + (a.w / 2 - 3) * Sin(a.ra - _Pi / 2)
  59.  
  60.     x4 = a.x + a.h / 4 * Cos(a.ra - _Pi)
  61.     y4 = a.y + a.h / 4 * Sin(a.ra - _Pi)
  62.     x5 = x4 + (a.w / 2 - 3) * Cos(a.ra + _Pi / 2)
  63.     y5 = y4 + (a.w / 2 - 3) * Sin(a.ra + _Pi / 2)
  64.     x6 = x4 + (a.w / 2 - 3) * Cos(a.ra - _Pi / 2)
  65.     y6 = y4 + (a.w / 2 - 3) * Sin(a.ra - _Pi / 2)
  66.  
  67.     Line (X2, Y2)-(X3, Y3), 15
  68.     Line (X3, Y3)-(x6, y6), 15
  69.     Line (x6, y6)-(x5, y5), 15
  70.     Line (x5, y5)-(X2, Y2), 15
  71.     Paint (a.x, a.y), 15, 15
  72.  
  73.  
  74.  

;-))

13
Programs / Evolving RI (Robot Intelligence) for a room vacuum
« on: February 28, 2022, 08:46:23 pm »
I am developing an Agent in AI lingo that is able to act on it's own without human intervention in real time

Here is first crude effort. You press spacebar for each step, or just lean on it to run through process. There is no stop signal, it just keeps on sweeping the random room.

What surprises the heck out of me is that it always, eventually, covers the whole room! So far I've not seen it fail. True  there is a lot of redundant over sweeps of cells but eventually it covers the room.

The sweeper only moves up/down or left/right each step and can only sense if there is an obstacle in these directions.

Code: QB64: [Select]
  1. _Title "I Robot - Room Mapper 1 (IR-RM1)" ' b+ 2022-02-11
  2. ' 2022-02-23 started writing code
  3. ' The little guy, say a vaccum cleaner, is plopped down somewhere in it's new home.
  4. ' The first order of business is to map out it's area of duty,
  5. ' say sweep the whole floor without getting stuck or wasting allot of moves.
  6. ' It is square and can sense, resistence on any of its edges.
  7. ' It is allowed to go N,S,E,W - the four directions
  8. ' If something is sensed on one side it is forbidden to
  9. ' enter that square from that direction.
  10. ' Rule of economy - don't reenter a square already occupied
  11. ' unless that is the only way to go.
  12. ' Do we have enough spelled out to map a room?
  13.  
  14. ' A room is a grid of squares, we don't know the dimensions
  15. ' and there are objects in many of the middle squares or along
  16. ' the walls. Later we may encounter objects that move around
  17. ' like pets or results of fickle home decorators.
  18.  
  19. ' God provides a room with objetcs and randomly drops the robot
  20. ' into it.
  21.  
  22. ' 2022-02-23 first goal is to get an edges mapped. so make up a room
  23. ' Upon some more thinking and just to get the ball rolling, I will
  24. ' allow robot vaccum sweeper to use the room map and mark it with it's
  25. ' own numbers, so now the walls are -1, empty areas 0, places visited
  26. ' are positive numbers, everytime the vacuum reoccupies the square
  27. ' the number is increased.
  28. ' OK the room setup seems satisfactory onto RI = Robot Intelligence
  29.  
  30. ' OK first run it does eventually cover the whole room.
  31. ' Need to know when it has done the whole room. There are some
  32. ' places that have to be left 0
  33.  
  34. Const SW = 601, SH = 601
  35. Screen _NewImage(SW, SH, 32)
  36. _ScreenMove 200, 70
  37.  
  38. ReDim Shared As Integer dx(3), dy(3)
  39. dx(0) = 0: dy(0) = -1
  40. dx(1) = 1: dy(1) = 0
  41. dx(2) = 0: dy(2) = 1
  42. dx(3) = -1: dy(3) = 0
  43.  
  44. ReDim Shared As Long Room(1 To 20, 1 To 20) ' 0 = empty -1 = wall see MakeRoom
  45. Dim Shared As Long rx, ry ' robot location
  46. rx = 10: ry = 10 ' starts here in middle of room should be clear
  47. MakeRoom
  48.     drawRoom 'ok the middle of room is staying clear of stuff
  49.     _Display
  50.     RI ' ok roby make your move
  51.     Sleep
  52.     Cls
  53.  
  54. Sub RI ' the robot appraises it's current postition rx, ry in Room(20x20) and makes a move changing rx, ry and that ends the sub
  55.  
  56.     ' I was here!
  57.     Room(rx, ry) = Room(rx, ry) + 1 ' sweeps the spot
  58.     Dim d(3)
  59.     d(0) = Room(rx, ry - 1)
  60.     d(1) = Room(rx + 1, ry)
  61.     d(2) = Room(rx, ry + 1)
  62.     d(3) = Room(rx - 1, ry)
  63.  
  64.     If d(0) = 0 Then ' one must have ones priorities
  65.         ry = ry - 1: Exit Sub
  66.     ElseIf d(1) = 0 Then
  67.         rx = rx + 1: Exit Sub
  68.     ElseIf d(2) = 0 Then
  69.         ry = ry + 1: Exit Sub
  70.     ElseIf d(3) = 0 Then
  71.         rx = rx - 1: Exit Sub
  72.     End If
  73.  
  74.     ' still here ?  where is min number of visits?
  75.     Dim As Long min, saveI
  76.     min = 10000000
  77.     For i = 0 To 3
  78.         If d(i) <> -1 Then
  79.             If d(i) < min Then min = d(i): saveI = i
  80.         End If
  81.     Next
  82.     rx = rx + dx(saveI)
  83.     ry = ry + dy(saveI)
  84.  
  85. Sub drawRoom
  86.     drawGridSq 0, 0, 30, 30
  87.     For x = 1 To 20
  88.         For y = 1 To 20
  89.             If Room(x, y) = -1 Then
  90.                 Line ((x - 1) * 30, (y - 1) * 30)-Step(30, 30), , BF
  91.             ElseIf Room(x, y) > 0 Then
  92.                 s$ = _Trim$(Str$(Room(x, y)))
  93.                 _PrintString ((x - 1) * 30 + (30 - Len(s$) * 8) / 2, (y - 1) * 30 + 7), s$
  94.             End If
  95.         Next
  96.     Next
  97.     ' and robot
  98.     Line ((rx - 1) * 30, (ry - 1) * 30)-Step(30, 30), &HFFFFFF00, BF
  99.  
  100. Sub MakeRoom
  101.     ReDim As Long Room(1 To 20, 1 To 20) ' 0 = empty -1 = wall
  102.     ' Here are the walls
  103.     For x = 1 To 20
  104.         For y = 1 To 2
  105.             If y = 2 Then z = 20 Else z = 1
  106.             Room(x, z) = -1
  107.             Room(z, x) = -1
  108.         Next
  109.     Next
  110.  
  111.     ' add random rectangles around the edges
  112.     For i = 1 To 20
  113.         rw = Int(Rnd * 4) + 1: rh = Int(Rnd * 4) + 1
  114.         wall = Int(Rnd * 4)
  115.         Select Case wall
  116.             Case 0 ' top
  117.                 If Rnd < .5 Then ys = 1 Else ys = 4
  118.                 xs = Int(Rnd * (20 - rw)) + 1
  119.                 For y = ys To ys + rh - 1
  120.                     For x = xs To xs + rw - 1
  121.                         Room(x, y) = -1
  122.                     Next
  123.                 Next
  124.             Case 1 'right
  125.                 If Rnd < .5 Then xs = 20 - rw + 1 Else xs = 16 - rw + 1
  126.                 ys = Int(Rnd * (20 - rh)) + 1
  127.                 For y = ys To ys + rh - 1
  128.                     For x = xs To xs + rw - 1
  129.                         Room(x, y) = -1
  130.                     Next
  131.                 Next
  132.             Case 2 ' bottom
  133.                 If Rnd < .5 Then ys = 20 - rh + 1 Else ys = 16 - rh + 1
  134.                 xs = Int(Rnd * (20 - rw)) + 1
  135.                 For y = ys To ys + rh - 1
  136.                     For x = xs To xs + rw - 1
  137.                         Room(x, y) = -1
  138.                     Next
  139.                 Next
  140.             Case 3 'left
  141.                 If Rnd < .5 Then xs = 1 Else xs = 4
  142.                 ys = Int(Rnd * (20 - rh)) + 1
  143.                 For y = ys To ys + rh - 1
  144.                     For x = xs To xs + rw - 1
  145.                         Room(x, y) = -1
  146.                     Next
  147.                 Next
  148.         End Select
  149.     Next
  150.  
  151.  
  152. Sub drawGridSq (x, y, sq, n)
  153.     Dim d As Long, i As Long
  154.     d = sq * n
  155.     For i = 0 To n
  156.         Line (x + sq * i, y)-(x + sq * i, y + d)
  157.         Line (x, y + sq * i)-(x + d, y + sq * i)
  158.     Next
  159.  
  160.  

BTW don't expect the vacuum to access sections that are completely walled off by room obstacles. A bit of a problem picking up on those isolated areas so the code knows when everything that could be swept has been as seen in next code reply.

14
Programs / Ray Trace a translation from SpecBAS
« on: February 26, 2022, 02:39:54 pm »
by Paul Dunn here was the original SpecBAS code:
Code: [Select]
10 PAPER 0: INK 15: CLS:
 palette 16,255,255,255:
 palette 32,0,192,255:
 palette 255,0,0,192:
 rainbow 16 to 32:
 rainbow 32 to 255
20 read spheres:t=msecs:
 DIM c(spheres,3),r(spheres),q(spheres),cl(4):
 w=scrw/2,h=scrh/2,s=0:
 cl(1)=6,cl(2)=1,
 cl(3)=cl(1)+8,cl(4)=cl(2)+8
30 FOR k=1 TO spheres:
    READ c(k,1),c(k,2),c(k,3),r:
    r(k)=r,q(k)=r*r:
 NEXT k
40 data 6:
 DATA -0.3,-0.8,3,0.6
50 DATA 0.9,-1.4,3.5,0.35:
 data 0.7,-0.45,2.5,0.4:
 data -0.5,-0.3,1.5,0.15:
 DATA 1.0,-0.2,1.5,0.1:
 DATA -0.1,-0.2,1.25,0.2
60 FOR i=1 TO scrh:
    FOR j=0 TO scrw-1
70       x=0.3,y=-0.5,z=0,ba=3:
       dx=j-w,dy=h-i,dz=(scrh/480)*600,
       dd=dx*dx+dy*dy+dz*dz
80       n=-(y>=0 OR dy<=0):
       IF n=0 THEN
          s=-y/dy
90       FOR k=1 TO spheres:
          px=c(k,1)-x,py=c(k,2)-y,pz=c(k,3)-z,
          pp=px*px+py*py+pz*pz,
          sc=px*dx+py*dy+pz*dz:
          IF sc<=0 THEN
             GO TO 120
100          bb=sc*sc/dd,
          aa=q(k)-pp+bb:
          IF aa<=0 THEN
             GO TO 120
110          sc=(SQR bb-SQR aa)/SQR dd:
          IF sc<s OR n<0 THEN
             n=k,s=sc
120       NEXT k
130       IF n<0 THEN
          plot ink 16+(dy*dy/dd)*240;j,scrh-i:
          go to 200
140       dx=dx*s,dy=dy*s,dz=dz*s,dd=dd*s*s,
       x+=dx,y+=dy,z+=dz:
       IF n<>0 THEN
           nx=x-c(n,1),ny=y-c(n,2),nz=z-c(n,3),
          nn=nx*nx+ny*ny+nz*nz,
          l=2*(dx*nx+dy*ny+dz*nz)/nn,
          dx=dx-nx*l,dy=dy-ny*l,dz=dz-nz*l:
          GO TO 80
160       FOR k=1 TO spheres:
          u=c(k,1)-x,
          v=c(k,3)-z:
          IF u*u+v*v<=q(k) THEN
             ba=1:
             go to 180
170       NEXT k
180       IF (x-INT x>.5)=(z-INT z>.5) THEN
          ik=cl(ba)
       else
          ik=cl(ba+1)
190       plot ink ik;j,scrh-i       
200    NEXT j:
 NEXT i
210 print at 0,0;transparent 1;ink 0;"Time: ";(msecs-t)/1000;" secs":
 pause 0:

Thanks to Rod at Just Basic for getting ball rolling for JB version, pretty easy from there to QB64
Code: QB64: [Select]
  1. _Title "RayTrace" 'b+ trans from JB to QB64 2022-02-26
  2. Const scrw = 1024, scrh = 680
  3. Screen _NewImage(scrw, scrh, 32)
  4. _ScreenMove 150, 40
  5. Read spheres
  6. Dim c(spheres, 3), r(spheres), q(spheres), cl(4) As _Unsigned Long
  7. w = scrw / 2
  8. h = scrh / 2
  9. s = 0
  10. cl(1) = _RGB32(120, 65, 45) ' shaddow
  11. cl(2) = _RGB32(0, 0, 100)
  12. cl(3) = _RGB32(255, 255, 0)
  13. cl(4) = _RGB32(0, 0, 200)
  14. For k = 1 To spheres
  15.     Read a, b, c, d
  16.     c(k, 1) = a
  17.     c(k, 2) = b
  18.     c(k, 3) = c
  19.     r = d
  20.     r(k) = r
  21.     q(k) = r * r
  22.  
  23. For i = 1 To scrh
  24.     For j = 0 To scrw - 1
  25.         x = 0.3: y = -0.5: z = 0: ba = 3
  26.         dx = j - w: dy = h - i: dz = (scrh / 480) * 600
  27.         dd = dx * dx + dy * dy + dz * dz
  28.         recursion:
  29.         n = (y >= 0 Or dy <= 0) '* -1   <<< Makes $1000 for knowing where to tap the hammer
  30.         If n = 0 Then s = (y / dy) * -1
  31.         For k = 1 To spheres
  32.             px = c(k, 1) - x: py = c(k, 2) - y: pz = c(k, 3) - z
  33.             pp = px * px + py * py + pz * pz
  34.             sc = px * dx + py * dy + pz * dz
  35.             If sc <= 0 Then GoTo donek
  36.             bb = sc * sc / dd
  37.             aa = q(k) - pp + bb
  38.             If aa <= 0 Then GoTo donek
  39.             sc = (Sqr(bb) - Sqr(aa)) / Sqr(dd)
  40.             If sc < s Or n < 0 Then n = k: s = sc
  41.             donek:
  42.         Next k
  43.         If n < 0 Then
  44.             PSet (j, scrh - i), _RGB32(128 * (scrh - i) / scrh + 128 * (dy * dy / dd), 128 * (scrh - i) / scrh + 128 * (dy * dy / dd), 200 + 55 * (dy * dy / dd))
  45.             GoTo donej
  46.         End If
  47.         dx = dx * s: dy = dy * s: dz = dz * s: dd = dd * s * s
  48.         x = x + dx: y = y + dy: z = z + dz
  49.         If n <> 0 Then
  50.             nx = x - c(n, 1): ny = y - c(n, 2): nz = z - c(n, 3)
  51.             nn = nx * nx + ny * ny + nz * nz
  52.             l = 2 * (dx * nx + dy * ny + dz * nz) / nn
  53.             dx = dx - nx * l: dy = dy - ny * l: dz = dz - nz * l
  54.             GoTo recursion
  55.         End If
  56.         For k = 1 To spheres
  57.             u = c(k, 1) - x
  58.             v = c(k, 3) - z
  59.             If u * u + v * v <= q(k) Then ba = 1: Exit For
  60.         Next k
  61.         If (x - Int(x) > .5) = (z - Int(z) > .5) Then
  62.             PSet (j, scrh - i), cl(ba)
  63.         Else
  64.             PSet (j, scrh - i), cl(ba + 1)
  65.         End If
  66.         donej:
  67.     Next j
  68.  
  69. Data -0.3,-0.8,3,0.6
  70. Data 0.9,-1.4,3.5,0.35
  71. Data 0.7,-0.45,2.5,0.4
  72. Data -0.5,-0.3,1.5,0.15
  73. Data 1.0,-0.2,1.5,0.1
  74. Data -0.1,-0.2,1.25,0.2
  75.  
  76.  

 
Ray Trace for QB64.PNG

15
QB64 Discussion / GotBasic - QB64 Mention
« on: February 25, 2022, 11:55:17 am »

Pages: [1] 2 3 ... 21