Author Topic: Happy new year 2022  (Read 2339 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Happy new year 2022
« on: December 27, 2021, 03:42:50 pm »
Hi, here is a small post to wish for 2022. I'm too lazy to make better missile synchronization, so I did it the way it is. Basically, the flight speed of the projectile would be solved depending on the length of the trajectory to the target, so that all the projectiles get to their seats at the same time....

Happy new year.

Code: QB64: [Select]
  1. Dim Shared START
  2.  
  3. DW = 1980
  4. DH = 1050
  5.  
  6. Type RCK
  7.     FlyX As Integer
  8.     FlyY As Integer
  9.     FlyA As Single
  10.     FlyL As Integer
  11.     X As Integer
  12.     Y As Integer
  13.     Radius As Integer
  14.     Rad2 As Integer
  15.     Arms As Integer
  16.     ArmPi As Single
  17.     EndRad As Integer
  18.     Effect As _Byte
  19.     Kolor As _Unsigned Long
  20.  
  21. ReDim Shared RCK(0) As RCK
  22.  
  23.  
  24. V& = _NewImage(DW, DH, 32)
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. Screen _NewImage(DW, DH, 32)
  32. T = Timer
  33. Dim rrr(376)
  34. ef = 2
  35. For rrrL = 1 To 376
  36.     If rrrL Mod 50 = 0 Then ef = ef + 1
  37.     If ef > 3 Then ef = 2
  38.     Read cX, Cy
  39.     rrr(rrrL) = NewRocket(cX, Cy, 1 + Int(Rnd * 6), 1 + Rnd * 5, ef, .3)
  40.     For S = 1 To 376
  41.         Rocket S
  42.     Next
  43.  
  44.     If Timer - T > 5 Then
  45.         T = Timer
  46.         START = 0
  47.         For S = 1 To 376
  48.             ResetRocket S
  49.         Next
  50.     End If
  51.  
  52.  
  53.     _Display
  54.     _Limit 20
  55.     Cls
  56.  
  57. Function NewRocket (X, Y, Arms, EndRadius, Effect, Angle)
  58.     U = UBound(RCK)
  59.     RCK(U).FlyX = 1 + Rnd * _Width
  60.     RCK(U).FlyY = Rnd * 30 + _Height
  61.     RCK(U).X = X
  62.     RCK(U).Y = Y
  63.     RCK(U).Radius = 0
  64.     RCK(U).Rad2 = 0
  65.     RCK(U).Arms = Arms
  66.     RCK(U).ArmPi = Angle
  67.     RCK(U).EndRad = EndRadius
  68.     RCK(U).Effect = Effect
  69.     RCK(U).Kolor = _RGB32(255 * Rnd, 200 * Rnd, 95 * Rnd)
  70.     RCK(U).FlyA = _Atan2(RCK(U).FlyY - Y, RCK(U).FlyX - X)
  71.     RCK(U).FlyL = _Hypot(Y - RCK(U).FlyY, X - RCK(U).FlyX)
  72.     NewRocket = U
  73.     ReDim _Preserve RCK(U + 1) As RCK
  74.  
  75. Sub ResetRocket (U)
  76.     If START Then Exit Sub
  77.     RCK(U).FlyX = 1 + Rnd * _Width
  78.     RCK(U).FlyY = Rnd * 30 + _Height
  79.     RCK(U).Radius = 0
  80.     RCK(U).Rad2 = 0
  81.     RCK(U).Kolor = _RGB32(255 * Rnd, 200 * Rnd, 95 * Rnd)
  82.     RCK(U).FlyA = _Atan2(RCK(U).FlyY - RCK(U).Y, RCK(U).FlyX - RCK(U).X)
  83.     RCK(U).FlyL = _Hypot(RCK(U).Y - RCK(U).FlyY, RCK(U).X - RCK(U).FlyX)
  84.  
  85.  
  86. Sub Rocket (Handle)
  87.     START = 0
  88.     Speed = 30
  89.     If RCK(Handle).FlyL > 0 Then
  90.         START = 1
  91.         RCK(Handle).FlyL = RCK(Handle).FlyL - Speed
  92.  
  93.         DX = RCK(Handle).X + Cos(RCK(Handle).FlyA) * RCK(Handle).FlyL
  94.         DY = RCK(Handle).Y + Sin(RCK(Handle).FlyA) * RCK(Handle).FlyL
  95.  
  96.         DX2 = RCK(Handle).X + Cos(RCK(Handle).FlyA) * (RCK(Handle).FlyL + 20)
  97.         DY2 = RCK(Handle).Y + Sin(RCK(Handle).FlyA) * (RCK(Handle).FlyL + 20)
  98.  
  99.         Line (DX, DY)-(DX2, DY2), White
  100.  
  101.     Else
  102.  
  103.         START = 1
  104.         Select Case RCK(Handle).Effect
  105.             Case 0, 1
  106.                 If RCK(Handle).EndRad > RCK(Handle).Radius Then
  107.                     R = _Red32(RCK(Handle).Kolor)
  108.                     G = _Green32(RCK(Handle).Kolor)
  109.                     B = _Blue32(RCK(Handle).Kolor)
  110.                     steps = (RCK(Handle).EndRad - RCK(Handle).Radius) + 1
  111.                     a = 255 / ((RCK(Handle).EndRad - RCK(Handle).Radius) / 100)
  112.  
  113.                     If RCK(Handle).Effect = 1 Then
  114.                         If RCK(Handle).Radius > 10 Then
  115.                             CircleFill RCK(Handle).X, RCK(Handle).Y, RCK(Handle).Radius, _RGBA32(R, G, B, a)
  116.                             CircleFill RCK(Handle).X, RCK(Handle).Y, RCK(Handle).Radius - 10, _RGB32(0)
  117.                         Else
  118.                             CircleFill RCK(Handle).X, RCK(Handle).Y, RCK(Handle).Radius, _RGBA32(R, G, B, a)
  119.                         End If
  120.                     Else
  121.                         CircleFill RCK(Handle).X, RCK(Handle).Y, RCK(Handle).Radius, _RGBA32(R, G, B, a)
  122.                     End If
  123.  
  124.                     RCK(Handle).Radius = RCK(Handle).Radius + 2
  125.  
  126.                 Else
  127.                     ResetRocket Handle
  128.                 End If
  129.  
  130.             Case 2, 3
  131.                 If RCK(Handle).Effect = 3 Then RCK(Handle).ArmPi = RCK(Handle).ArmPi + .01
  132.                 If RCK(Handle).EndRad > RCK(Handle).Radius Then
  133.                     a = _Pi(2) / RCK(Handle).Arms
  134.                     d = 0
  135.                     Do Until e = RCK(Handle).Arms
  136.  
  137.                         CircleFill RCK(Handle).X + Cos(d + RCK(Handle).ArmPi) * RCK(Handle).Radius, RCK(Handle).Y + Sin(d + RCK(Handle).ArmPi) * RCK(Handle).Radius, 2, White
  138.                         d = d + a
  139.                         e = e + 1
  140.                     Loop
  141.                     RCK(Handle).Radius = RCK(Handle).Radius + 1
  142.                     RCK(Handle).Rad2 = RCK(Handle).Radius
  143.                 Else
  144.                     If RCK(Handle).Rad2 - RCK(Handle).Radius < 22 Then
  145.                         a = _Pi(2) / RCK(Handle).Arms
  146.                         d = 0: e = 0
  147.                         Do Until e = RCK(Handle).Arms
  148.                             CircleFill RCK(Handle).X + Cos(d + RCK(Handle).ArmPi) * RCK(Handle).Rad2, RCK(Handle).Y + Sin(d + RCK(Handle).ArmPi) * RCK(Handle).Rad2, 5, RCK(Handle).Kolor Or Black
  149.                             d = d + a
  150.                             e = e + 1
  151.                         Loop
  152.                         RCK(Handle).Rad2 = RCK(Handle).Rad2 + 1
  153.                     Else
  154.                         ResetRocket Handle
  155.                     End If
  156.                 End If
  157.         End Select
  158.     End If
  159.  
  160.  
  161. Sub CircleFill (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
  162.     ' CX = center x coordinate
  163.     ' CY = center y coordinate
  164.     '  R = radius
  165.     '  C = fill color
  166.     Dim Radius As Integer, RadiusError As Integer
  167.     Dim X As Integer, Y As Integer
  168.     Radius = Abs(R)
  169.     RadiusError = -Radius
  170.     X = Radius
  171.     Y = 0
  172.     If Radius = 0 Then PSet (CX, CY), C: Exit Sub
  173.     Line (CX - X, CY)-(CX + X, CY), C, BF
  174.     While X > Y
  175.         RadiusError = RadiusError + Y * 2 + 1
  176.         If RadiusError >= 0 Then
  177.             If X <> Y + 1 Then
  178.                 Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  179.                 Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  180.             End If
  181.             X = X - 1
  182.             RadiusError = RadiusError - X * 2
  183.         End If
  184.         Y = Y + 1
  185.         Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  186.         Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  187.     Wend
  188.  
  189.  
  190. Data 44,3,47,24,43,53,44,80,44,103,43,130,43,154,43,182,43,205,43,226,63,111,83,115,109,115,130,112,146,111,167,113,193,113,194,0,197,30,193,57,188,91,190,113,186,134,185,159,184,184,182,212,185,229,193,73,267,239,270,218,273,196,273
  191. Data 171,275,144,276,121,274,101,281,70,283,42,296,24,315,15,347,15,360,31,380,64,383,94,383,115,383,148,383,174,383,201,383,222,384,242,369,138,345,139,326,136,309,137,291,137,431,243,435,218,431,195,432,169,434,143,433,112,433,88
  192. Data 433,61,433,39,432,17,453,6,477,9,497,14,519,19,537,28,541,55,538,71,530,87,513,104,490,116,464,122,448,124,598,256,596,239,591,204,593,220,593,178,593,153,591,117,588,132,590,90,589,62,585,36,591,10,628,10,612,7,652,12,669,17,690
  193. Data 30,697,47,694,68,687,85,672,100,654,108,633,122,615,131,600,131,727,5,734,28,739,54,744,65,748,81,752,97,761,116,768,131,778,139,794,132,801,120,812,102,821,85,828,67,831,43,834,25,839,8,783,149,783,166,782,185,783,202,778,232,780
  194. Data 253,780,263,1055,268,1050,244,1049,225,1048,201,1047,178,1044,152,1041,124,1040,99,1037,68,1031,40,1041,21,1064,15,1081,31,1089,59,1095,83,1101,104,1107,122,1113,148,1118,169,1123,196,1126,217,1131,245,1143,262,1156,270,1158,247,1160
  195. Data 217,1157,178,1156,143,1156,125,1156,104,1155,75,1152,43,1153,26,1158,159,1159,196,1317,6,1291,8,1276,11,1253,12,1231,12,1215,18,1211,45,1214,80,1216,102,1216,127,1217,153,1219,182,1220,211,1220,238,1218,265,1230,274,1253,275,1280,273
  196. Data 1308,271,1330,270,1347,267,1236,145,1255,144,1283,144,1391,9,1393,25,1397,48,1401,69,1403,91,1408,116,1410,137,1414,154,1418,173,1422,190,1425,206,1429,232,1439,254,1446,269,1464,273,1481,258,1490,236,1500,223,1511,194,1521,165,1530
  197. Data 144,1545,119,1555,97,1563,70,1572,43,1576,13,1492,8,1502,35,1515,60,1523,88,1527,104,1528,123,1540,157,1552,189,1560,210,1577,231,1578,255,1587,279,1595,295,1617,302,1622,281,1628,261,1637,233,1642,212,1642,186,1647,158,1655,135
  198. Data 1658,115,1662,91,1665,64,1668,36,1669,19,1675,1,452,477,456,496,466,521,473,544,485,570,495,591,510,613,520,629,537,633,555,621,570,601,588,578,598,563,616,539,624,515,631,494,641,469,534,654,531,671,530,695,532,722,531,744,536,773
  199. Data 534,795,528,824,865,476,846,477,819,474,794,473,771,471,758,472,731,472,718,474,706,493,710,519,708,555,706,584,701,602,700,625,702,654,704,673,702,699,701,722,701,744,701,768,700,790,698,816,711,832,745,839,764,839,794,837,812,838
  200. Data 843,841,862,842,717,658,749,666,777,665,796,665,825,665,923,849,930,813,924,826,933,786,941,754,944,731,950,701,958,668,962,648,967,625,977,594,982,562,982,522,986,540,993,493,1013,486,1032,510,1040,532,1050,561,1056,579,1062,599,1070
  201. Data 626,1080,655,1093,680,1096,708,1109,734,1115,756,1124,778,1132,809,1143,835,1151,857,1076,697,1054,697,1033,698,1008,694,978,690,958,688,1199,858,1199,833,1199,804,1197,775,1196,751,1194,717,1191,690,1188,668,1188,634,1183,608,1180
  202. Data 583,1180,562,1179,535,1176,503,1197,492,1217,491,1243,491,1266,490,1284,492,1308,504,1325,517,1339,544,1341,564,1341,589,1333,617,1314,633,1301,641,1281,644,1258,651,1231,650,1209,654,1214,673,1234,701,1254,718,1273,737,1289,759,1297
  203. Data 770,1313,787,1322,797,1332,811,1351,824,1359,839,1375,853
  204.  
  205.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Happy new year 2022
« Reply #1 on: December 27, 2021, 04:04:19 pm »
Nice, Happy New Year Petr!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Happy new year 2022
« Reply #2 on: December 27, 2021, 04:35:01 pm »
Cool...

DIS chu' DatIvjaj (Klingon - Happy new year) Sorry... There does not seem to be a good translation for 'happy'
Logic is the beginning of wisdom.