Author Topic: ❅ Snowflake Design  (Read 1124 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
❅ 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


« Last Edit: December 04, 2021, 08:11:11 pm by bplus »