Author Topic: Yin Yang - Rosetta Code  (Read 3286 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Yin Yang - Rosetta Code
« on: May 04, 2021, 05:23:30 pm »
But Yin Yang was never meant to be static:
Code: QB64: [Select]
  1. _Title "Ying Yang Color Balls" 'b+ 2020-08-19 balls mod 2021-05-04
  2. ' 2020-08-19 pulled this one out of my files for QB64 trans
  3. 'Ying yang color.bas 2015-07-08 I know I updated sdlbas version how about SmallBASIC?
  4. 'from Ying Yang v3.sdlbas 2015-06-03 MGA
  5.  
  6. Const sq = 500, rc = sq / 4 - 40, xc = sq / 2, yc = sq / 2
  7. Screen _NewImage(sq, sq, 32)
  8. _Delay .25
  9.  
  10. nc = 1
  11. d = .1
  12. dir = 1
  13. i = 0
  14. acc = .01 'radians
  15.     x1 = xc + rc * Sin(i)
  16.     y1 = yc + rc * Cos(i)
  17.     If nc > 254 Then d = -1 * d
  18.     If nc < 1 Then d = -1 * d
  19.     nc = nc + d * dir
  20.     If nc > 255 Then dir = dir * -1: d = d * dir
  21.     If nc < 1 Then dir = dir * -1: d = d * dir
  22.     c = _RGB32(nc, 0, 255 - nc)
  23.     drawBall x1, y1, rc, c
  24.     c = _RGB32(0, 255 - nc, nc)
  25.     drawBall x1, y1, rc / 3, c
  26.     x2 = xc + rc * Sin(i + 3.1415)
  27.     y2 = yc + rc * Cos(i + 3.1415)
  28.     drawBall x2, y2, rc, c
  29.     c = _RGB32(nc, 0, 255 - nc)
  30.     drawBall x2, y2, rc / 3, c
  31.     i = i + acc
  32.     _Display
  33.  
  34. Sub drawBall (x, y, r, c As _Unsigned Long)
  35.     Dim rred As Long, grn As Long, blu As Long, rr As Long, f
  36.     rred = _Red32(c): grn = _Green32(c): blu = _Blue32(c)
  37.     For rr = r To 0 Step -4
  38.         f = 1 - (rr / r) * .5
  39.         fcirc x, y, rr, _RGB32(rred * f, grn * f, blu * f)
  40.     Next
  41.  
  42. 'from Steve Gold standard
  43. Sub fcirc (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
  44.     Dim Radius As Integer, RadiusError As Integer
  45.     Dim X As Integer, Y As Integer
  46.     Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
  47.     If Radius = 0 Then PSet (CX, CY), C: Exit Sub
  48.     Line (CX - X, CY)-(CX + X, CY), C, BF
  49.     While X > Y
  50.         RadiusError = RadiusError + Y * 2 + 1
  51.         If RadiusError >= 0 Then
  52.             If X <> Y + 1 Then
  53.                 Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  54.                 Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  55.             End If
  56.             X = X - 1
  57.             RadiusError = RadiusError - X * 2
  58.         End If
  59.         Y = Y + 1
  60.         Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  61.         Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  62.     Wend
  63.  
  64.  
  65.  

image_2021-05-04_172940.png
* image_2021-05-04_172940.png (Filesize: 19.51 KB, Dimensions: 502x526, Views: 260)
« Last Edit: May 04, 2021, 05:29:42 pm by bplus »

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Yin Yang - Rosetta Code
« Reply #1 on: May 05, 2021, 02:27:37 am »
Nice one! I like it! very smooth
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Yin Yang - Rosetta Code
« Reply #2 on: May 05, 2021, 02:29:38 pm »
Thanks Ashish, been playing around with Yin Yang 6 years yesterday I gave it balls.