Author Topic: Helicopter blades  (Read 5928 times)

0 Members and 1 Guest are viewing this topic.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Helicopter blades
« on: August 31, 2018, 12:32:15 am »
I was working on an idea for helicopter blades tonight for a game similar to: http://www.helicopter-game.org/

I thought instead of using a sprite sheet why not mathematically draw them and then store them in images instead of using a sprite sheet. Below is the result which I though I would share because the routine may be useful to others. Right now it looks like a ceiling fan spinning casting a shadow, LOL.

Code: QB64: [Select]
  1. '
  2. ' Helicopter blades idea
  3.  
  4. CONST PI = 3.1415926
  5.  
  6. start = -.00000001
  7. finish = -2 * PI / 16
  8. steps = finish / 20
  9. inc = -.0981726875
  10.  
  11. SCREEN _NEWIMAGE(640, 480, 32)
  12.  
  13.     FOR j = 0 TO 15
  14.         _LIMIT 30
  15.         CIRCLE (319, 239), 35, _RGB(25, 76, 127), , , .35
  16.         PAINT (319, 239), _RGB(25, 76, 127), _RGB(25, 76, 127)
  17.         FOR i = start + (inc * j) TO finish + (inc * j) STEP steps
  18.             FOR k = 0 TO 3
  19.                 radian = i + k * -1.5707963
  20.                 IF radian < -2 * PI THEN radian = radian + 2 * PI
  21.                 CIRCLE (319, 239), 35, _RGB(12, 38, 88), radian, radian, .35
  22.                 CIRCLE (319, 209), 35, _RGB(12, 38, 88), radian, radian, .35
  23.             NEXT k
  24.         NEXT i
  25.         _DISPLAY
  26.         CLS
  27.     NEXT j
« Last Edit: August 31, 2018, 12:34:09 am by TerryRitchie »
In order to understand recursion, one must first understand recursion.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Helicopter blades
« Reply #1 on: August 31, 2018, 02:22:24 am »
Nice!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Helicopter blades
« Reply #2 on: August 31, 2018, 05:29:18 am »
Very nicely done... and I even like the colour...

J
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Helicopter blades
« Reply #3 on: August 31, 2018, 10:54:26 am »
I made blades rectangular and then played with code some more. :)
Code: QB64: [Select]
  1. '
  2. ' Helicopter blades idea started by Terry Ritchie mods by B+ 2018-08-31
  3.  
  4. CONST PI = 3.1415926
  5.  
  6. start = -.00000001
  7. finish = -2 * PI / 16
  8. steps = finish / 20
  9. inc = -.0981726875
  10.  
  11. SCREEN _NEWIMAGE(640, 480, 32)
  12.  
  13. 'DO
  14. WHILE _KEYDOWN(27) = 0
  15.     a = a + _PI(1.111)
  16.     IF a > _PI(2) THEN a = a - _PI(2)
  17.     CLS
  18.     CIRCLE (mx, 380), 150, _RGB(25, 76, 127), , , .35
  19.     PAINT (mx, 380), _RGB(25, 76, 127), _RGB(25, 76, 127)
  20.     'FOR i = start + (inc * j) TO finish + (inc * j) STEP steps
  21.     FOR k = 0 TO 3
  22.         radian = a + k * -1.5707963
  23.         IF radian < -2 * PI THEN radian = radian + 2 * PI
  24.         x1 = mx + 15 * COS(radian)
  25.         y1 = my + .35 * 15 * SIN(radian)
  26.         y3 = 380 + .35 * 15 * SIN(radian)
  27.         x2 = mx + 135 * COS(radian)
  28.         y2 = my + .35 * 135 * SIN(radian)
  29.         y4 = 380 + .35 * 135 * SIN(radian)
  30.         'CIRCLE (319, 239), 35, _RGB(12, 38, 88), radian, radian, .35
  31.         'CIRCLE (319, 209), 35, _RGB(12, 38, 88), radian, radian, .35
  32.         thic x1, y1, x2, y2, 5, _RGB32(25, 76, 127)
  33.         thic x1, y3, x2, y4, 5, _RGB32(0, 0, 0)
  34.     NEXT k
  35.     'NEXT i
  36.     PRINT speed
  37.     _DISPLAY
  38.     my = _MOUSEY: mx = _MOUSEX
  39.     IF my <> 0 THEN speed = 60 * (480 - my) / 480 ELSE speed = 30
  40.     _LIMIT speed
  41.     '_DELAY speed
  42. 'LOOP
  43.  
  44. SUB thic (x1, y1, x2, y2, thick, K AS _UNSIGNED LONG)
  45.     t2 = thick / 2
  46.     IF t2 < 1 THEN t2 = 1
  47.     a = _ATAN2(y2 - y1, x2 - x1)
  48.     x3 = x1 + t2 * COS(a + _PI(.5))
  49.     y3 = y1 + t2 * SIN(a + _PI(.5))
  50.     x4 = x1 + t2 * COS(a - _PI(.5))
  51.     y4 = y1 + t2 * SIN(a - _PI(.5))
  52.     x5 = x2 + t2 * COS(a + _PI(.5))
  53.     y5 = y2 + t2 * SIN(a + _PI(.5))
  54.     x6 = x2 + t2 * COS(a - _PI(.5))
  55.     y6 = y2 + t2 * SIN(a - _PI(.5))
  56.     ftri x6, y6, x4, y4, x3, y3, K
  57.     ftri x3, y3, x5, y5, x6, y6, K
  58.  
  59. ' 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
  60. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  61.     a& = _NEWIMAGE(1, 1, 32)
  62.     _DEST a&
  63.     PSET (0, 0), K
  64.     _DEST 0
  65.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  66.     _FREEIMAGE a& '<<< this is important!
  67.  
  68.  

FellippeHeitor

  • Guest
Re: Helicopter blades
« Reply #4 on: August 31, 2018, 10:58:40 am »
Looking really good, gentlemen.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Helicopter blades
« Reply #5 on: August 31, 2018, 11:10:41 am »
Thanks, I though about changing the aspect of the ellipse and blade width according my relation to horizon but decided to have lunch instead. :)

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Helicopter blades
« Reply #6 on: August 31, 2018, 12:17:30 pm »
I made blades rectangular and then played with code some more. :)

Cool!
In order to understand recursion, one must first understand recursion.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Helicopter blades
« Reply #7 on: August 31, 2018, 04:00:13 pm »
Here is my post lunch launch post:
Code: QB64: [Select]
  1. '
  2. ' Mod 2  Helicopter blades idea started by Terry Ritchie mods by B+ 2018-08-31
  3.  
  4. CONST PI = 3.1415926
  5. CONST horizon = 300
  6. CONST WW = 800
  7. CONST WH = 600
  8. start = -.00000001
  9. finish = -2 * PI / 16
  10. steps = finish / 20
  11. inc = -.0981726875
  12.  
  13. SCREEN _NEWIMAGE(WW, WH, 32)
  14. _SCREENMOVE 250, 50
  15.  
  16.  
  17. WHILE _KEYDOWN(27) = 0
  18.     a = a + _PI(1.111)
  19.     IF a > _PI(2) THEN a = a - _PI(2)
  20.     aspect = ABS(horizon - my) / (WH * .5)
  21.     IF aspect > .35 THEN aspect = .35
  22.     bladeWidth = 20 * aspect
  23.     CLS
  24.     FOR i = 0 TO horizon
  25.         midInk 0, 0, 128, 200, 200, 255, i / horizon
  26.         LINE (0, i)-(WW, i)
  27.     NEXT
  28.     FOR i = horizon% TO WH
  29.         midInk 50, 200, 50, 50, 128, 50, (i - horizon) / (WH - horizon)
  30.         LINE (0, i)-(WW, i)
  31.     NEXT
  32.     FOR k = 0 TO 3
  33.         radian = a + k * -1.5707963
  34.         IF radian < -2 * PI THEN radian = radian + 2 * PI
  35.         x1 = mx + 15 * COS(radian)
  36.         y1 = my + aspect * 15 * SIN(radian)
  37.         y3 = WH - .35 * 150 + .35 * 15 * SIN(radian)
  38.         x2 = mx + 135 * COS(radian)
  39.         y2 = my + aspect * 135 * SIN(radian)
  40.         y4 = WH - .35 * 150 + .35 * 135 * SIN(radian)
  41.         IF my > horizon THEN c~& = _RGB32(255, 255, 255) ELSE c~& = _RGB32(60, 60, 60)
  42.         thic x1, y1, x2, y2, bladeWidth, c~&
  43.         thic x1, y3, x2, y4, 20 * .35, _RGB32(0, 0, 0)
  44.         _DISPLAY
  45.     NEXT k
  46.     PRINT speed
  47.     _DISPLAY
  48.     my = _MOUSEY: mx = _MOUSEX
  49.     IF my <> 0 THEN speed = 60 * (WH - my) / WH ELSE speed = 30
  50.     _LIMIT speed
  51.  
  52.  
  53. SUB thic (x1, y1, x2, y2, thick, K AS _UNSIGNED LONG)
  54.     t2 = thick / 2
  55.     IF t2 < 1 THEN t2 = 1
  56.     a = _ATAN2(y2 - y1, x2 - x1)
  57.     x3 = x1 + t2 * COS(a + _PI(.5))
  58.     y3 = y1 + t2 * SIN(a + _PI(.5))
  59.     x4 = x1 + t2 * COS(a - _PI(.5))
  60.     y4 = y1 + t2 * SIN(a - _PI(.5))
  61.     x5 = x2 + t2 * COS(a + _PI(.5))
  62.     y5 = y2 + t2 * SIN(a + _PI(.5))
  63.     x6 = x2 + t2 * COS(a - _PI(.5))
  64.     y6 = y2 + t2 * SIN(a - _PI(.5))
  65.     ftri x6, y6, x4, y4, x3, y3, K
  66.     ftri x3, y3, x5, y5, x6, y6, K
  67.  
  68. ' 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
  69. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  70.     a& = _NEWIMAGE(1, 1, 32)
  71.     _DEST a&
  72.     PSET (0, 0), K
  73.     _DEST 0
  74.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  75.     _FREEIMAGE a& '<<< this is important!
  76.  
  77. SUB midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  78.     COLOR _RGB(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  79.  
  80.  

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Helicopter blades
« Reply #8 on: September 01, 2018, 11:48:18 am »
Your math-fu astounds me. I wish I had your mathematical chops.
In order to understand recursion, one must first understand recursion.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Helicopter blades
« Reply #9 on: September 01, 2018, 12:57:07 pm »
Your math-fu astounds me. I wish I had your mathematical chops.

Yes, math can be fun, so is inspiring others. I admire your tutorial efforts.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Helicopter blades
« Reply #10 on: September 01, 2018, 03:04:25 pm »
Quote
Your math-fu astounds me. I wish I had your mathematical chops.
Pun intended?
You're not done when it works, you're done when it's right.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Helicopter blades
« Reply #11 on: September 01, 2018, 03:27:42 pm »
Quote
Your math-fu astounds me. I wish I had your mathematical chops.
Pun intended?
No, lol, the cut-elimination theorem is beyond my chops. :)
In order to understand recursion, one must first understand recursion.