Author Topic: Re: Circle_PI (Visualizing the digits of _PI)  (Read 654 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Circle_PI (Visualizing the digits of _PI)
« on: March 23, 2019, 09:35:56 am »
Sure was interesting comparing your bouncing ball code and mine.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Circle_PI (Visualizing the digits of _PI)
« Reply #1 on: March 23, 2019, 10:05:29 am »
Challenge: can you guys put your heads together and get that fantastic fading ball trick to work with drawn lines from digit to digit, updating pi as digits are hit?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Circle_PI (Visualizing the digits of _PI)
« Reply #2 on: March 23, 2019, 02:13:00 pm »
Hey love the music!

Here is my updated version (that draws a ring around a repeating digit) using thicker lines and alternating red/blue for lines:
Code: QB64: [Select]
  1. _TITLE "Visualizing Pi 2" 'B+ 2019-03-15
  2.  
  3. 'Featuring a circle loop around the a repeated digit.
  4. ' 3 first, 8, 2, 9, 4, 1, 6, 5, 0 (300+ digits), 7 (560 digits)
  5.  
  6. 'ref  http://www.math.com/tables/constants/pi.htm  First 100 digits
  7. CONST pi100 = "3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067"
  8. 'ref same as above 1000 digits, see if can circle all digits pi shortened to 560 digits
  9. CONST pi = "314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277"
  10. 'PRINT INSTR(pi, "77") ' last number to get circled for repeating at 560
  11. CONST xmax = 800
  12. CONST ymax = 720
  13. CONST x0 = 400
  14. CONST y0 = 420
  15. CONST radius = 240
  16. CONST r2 = 20
  17. CONST red = &HFFFF0000
  18. CONST blue = &HFF0000FF
  19.  
  20. TYPE vectorType
  21.     x AS INTEGER
  22.     y AS INTEGER
  23.  
  24. SCREEN _NEWIMAGE(xmax, ymax, 32)
  25. _SCREENMOVE 300, 20
  26. s2& = _NEWIMAGE(xmax, ymax, 32) 'to update drawing lines in isolation
  27. t = TIMER(.001)
  28. ca = _PI(2 / 10)
  29. DIM vdigit(0 TO 9) AS vectorType
  30. DIM outer(0 TO 9) AS vectorType
  31. ring 0, x0, y0, radius + 3, radius - 3, _RGB32(255, 255, 255)
  32. FOR i = 0 TO 9
  33.     vdigit(i).x = x0 + radius * COS(ca * i - 2 * ca)
  34.     vdigit(i).y = y0 + radius * SIN(ca * i - 2 * ca)
  35.     x = x0 + (radius + 18) * COS(ca * i - 2 * ca) - 2
  36.     y = y0 + (radius + 18) * SIN(ca * i - 2 * ca) - 6
  37.     _PRINTSTRING (x, y), LTRIM$(STR$(i))
  38.     outer(i).x = x0 + (radius + r2) * COS(ca * i - 2 * ca)
  39.     outer(i).y = y0 + (radius + r2) * SIN(ca * i - 2 * ca)
  40. _PUTIMAGE , 0, s2&
  41.  
  42. digitPointer = 1
  43. cx = x0: cy = y0: speed = 5
  44. WHILE digitPointer <= LEN(pi)
  45.     d = VAL(MID$(pi, digitPointer, 1))
  46.     targetx = vdigit(d).x: targety = vdigit(d).y
  47.     IF digitPointer MOD 2 THEN rc~& = red ELSE rc~& = blue
  48.     IF lastd = d THEN
  49.         _DEST s2&
  50.         ring s2&, outer(d).x, outer(d).y, r2 + 3, r2 - 3, rc~&
  51.         _DEST 0
  52.         _PUTIMAGE , s2&, 0
  53.         CIRCLE (cx, cy), 10, &HFFFFFFFF
  54.         PAINT (cx, cy), &HFFFFFFFF
  55.         LOCATE 1, 1: PRINT MID$(pi, 1, digitPointer - 1)
  56.         _DISPLAY
  57.     ELSE
  58.         dist = SQR((targetx - cx) ^ 2 + (targety - cy) ^ 2)
  59.         loopCnt = dist / speed
  60.         dx = (targetx - cx) / loopCnt
  61.         dy = (targety - cy) / loopCnt
  62.         FOR i = 0 TO loopCnt
  63.             newX = cx + dx
  64.             newY = cy + dy
  65.             _DEST s2&
  66.             thic s2&, cx, cy, newX, newY, 6, rc~&
  67.             _PUTIMAGE , s2&, 0
  68.             _DEST 0
  69.             CIRCLE (newX, newY), 10, &HFFFFFFFF
  70.             PAINT (newX, newY), &HFFFFFFFF
  71.             LINE (0, 0)-(xmax, ymax), _RGBA32(0, 0, 0, 20), BF
  72.             cx = newX: cy = newY
  73.             LOCATE 1, 1: PRINT MID$(pi, 1, digitPointer - 1)
  74.             _DISPLAY
  75.             _LIMIT 120
  76.         NEXT
  77.     END IF
  78.     digitPointer = digitPointer + 1
  79.     lastd = d
  80. LOCATE 1, 1: PRINT MID$(pi, 1, digitPointer)
  81. PRINT TIMER(.001) - t; " secs"
  82.  
  83. SUB thic (h&, x1, y1, x2, y2, thick, K AS _UNSIGNED LONG)
  84.     t2 = thick / 2
  85.     IF t2 < 1 THEN t2 = 1
  86.     a = _ATAN2(y2 - y1, x2 - x1)
  87.     x3 = x1 + t2 * COS(a + _PI(.5))
  88.     y3 = y1 + t2 * SIN(a + _PI(.5))
  89.     x4 = x1 + t2 * COS(a - _PI(.5))
  90.     y4 = y1 + t2 * SIN(a - _PI(.5))
  91.     x5 = x2 + t2 * COS(a + _PI(.5))
  92.     y5 = y2 + t2 * SIN(a + _PI(.5))
  93.     x6 = x2 + t2 * COS(a - _PI(.5))
  94.     y6 = y2 + t2 * SIN(a - _PI(.5))
  95.     ftri h&, x6, y6, x4, y4, x3, y3, K
  96.     ftri h&, x3, y3, x5, y5, x6, y6, K
  97.  
  98. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  99. SUB ftri (desth&, x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  100.     a& = _NEWIMAGE(1, 1, 32)
  101.     _DEST a&
  102.     PSET (0, 0), K
  103.     _DEST desth&
  104.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  105.     _FREEIMAGE a& '<<< this is important!
  106.  
  107. SUB ring (destH&, x0, y0, outerR, innerR, colr AS _UNSIGNED LONG)
  108.     temp& = _NEWIMAGE(2 * outerR + 1, 2 * outerR + 1, 32)
  109.     _DEST temp&
  110.     CIRCLE (outerR, outerR), outerR, colr
  111.     CIRCLE (outerR, outerR), innerR, colr
  112.     PAINT (outerR + innerR + 1, outerR + 1), colr
  113.     _PUTIMAGE (x0 - outerR, y0 - outerR), temp&, destH&
  114.     _FREEIMAGE temp&
  115.  
  116.  

PS I also tried the dx, dy method for updating the ball position instead of _ARCTAN2 as [banned user]'s code is doing.
It's funny if you draw a line from A to B it does not completely overlap with a line drawn from B to A, at least the way I am doing it.
« Last Edit: March 23, 2019, 02:17:15 pm by bplus »