Author Topic: Helicopter blades  (Read 136 times)

Online TerryRitchie

  • Semper Fidelis
Helicopter blades
« on: August 31, 2018, 01: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: [Select]
'
' Helicopter blades idea

CONST PI = 3.1415926

start = -.00000001
finish = -2 * PI / 16
steps = finish / 20
inc = -.0981726875

SCREEN _NEWIMAGE(640, 480, 32)
CLS

DO
    FOR j = 0 TO 15
        _LIMIT 30
        CIRCLE (319, 239), 35, _RGB(25, 76, 127), , , .35
        PAINT (319, 239), _RGB(25, 76, 127), _RGB(25, 76, 127)
        FOR i = start + (inc * j) TO finish + (inc * j) STEP steps
            FOR k = 0 TO 3
                radian = i + k * -1.5707963
                IF radian < -2 * PI THEN radian = radian + 2 * PI
                CIRCLE (319, 239), 35, _RGB(12, 38, 88), radian, radian, .35
                CIRCLE (319, 209), 35, _RGB(12, 38, 88), radian, radian, .35
            NEXT k
        NEXT i
        _DISPLAY
        CLS
    NEXT j
LOOP
« Last Edit: August 31, 2018, 01:34:09 AM by TerryRitchie »
g=c800:5 fixes everything

Re: Helicopter blades
« Reply #1 on: August 31, 2018, 03:22:24 AM »
Nice!
B = B + ...
QB64 x 64 v1.2 2018 0228/86 git b30af92
QB64 v1.2 2018 0228/86 git b30af92
QB64 v1.1 2017 1106/82

Offline johnno56

  • Live long and prosper.
Re: Helicopter blades
« Reply #2 on: August 31, 2018, 06:29:18 AM »
Very nicely done... and I even like the colour...

J
Logic is the beginning of wisdom.

Re: Helicopter blades
« Reply #3 on: August 31, 2018, 11:54:26 AM »
I made blades rectangular and then played with code some more. :)
Code: [Select]
'
' Helicopter blades idea started by Terry Ritchie mods by B+ 2018-08-31

CONST PI = 3.1415926

start = -.00000001
finish = -2 * PI / 16
steps = finish / 20
inc = -.0981726875

SCREEN _NEWIMAGE(640, 480, 32)
CLS

'DO
_MOUSEHIDE
WHILE _KEYDOWN(27) = 0
    a = a + _PI(1.111)
    IF a > _PI(2) THEN a = a - _PI(2)
    CLS
    CIRCLE (mx, 380), 150, _RGB(25, 76, 127), , , .35
    PAINT (mx, 380), _RGB(25, 76, 127), _RGB(25, 76, 127)
    'FOR i = start + (inc * j) TO finish + (inc * j) STEP steps
    FOR k = 0 TO 3
        radian = a + k * -1.5707963
        IF radian < -2 * PI THEN radian = radian + 2 * PI
        x1 = mx + 15 * COS(radian)
        y1 = my + .35 * 15 * SIN(radian)
        y3 = 380 + .35 * 15 * SIN(radian)
        x2 = mx + 135 * COS(radian)
        y2 = my + .35 * 135 * SIN(radian)
        y4 = 380 + .35 * 135 * SIN(radian)
        'CIRCLE (319, 239), 35, _RGB(12, 38, 88), radian, radian, .35
        'CIRCLE (319, 209), 35, _RGB(12, 38, 88), radian, radian, .35
        thic x1, y1, x2, y2, 5, _RGB32(25, 76, 127)
        thic x1, y3, x2, y4, 5, _RGB32(0, 0, 0)
    NEXT k
    'NEXT i
    PRINT speed
    _DISPLAY
    WHILE _MOUSEINPUT: WEND
    my = _MOUSEY: mx = _MOUSEX
    IF my <> 0 THEN speed = 60 * (480 - my) / 480 ELSE speed = 30
    _LIMIT speed
    '_DELAY speed
WEND
'LOOP

SUB thic (x1, y1, x2, y2, thick, K AS _UNSIGNED LONG)
    t2 = thick / 2
    IF t2 < 1 THEN t2 = 1
    a = _ATAN2(y2 - y1, x2 - x1)
    x3 = x1 + t2 * COS(a + _PI(.5))
    y3 = y1 + t2 * SIN(a + _PI(.5))
    x4 = x1 + t2 * COS(a - _PI(.5))
    y4 = y1 + t2 * SIN(a - _PI(.5))
    x5 = x2 + t2 * COS(a + _PI(.5))
    y5 = y2 + t2 * SIN(a + _PI(.5))
    x6 = x2 + t2 * COS(a - _PI(.5))
    y6 = y2 + t2 * SIN(a - _PI(.5))
    ftri x6, y6, x4, y4, x3, y3, K
    ftri x3, y3, x5, y5, x6, y6, K
END SUB

' found at QB64.net:    http://www.qb64.net/forum/index.php?topic=14425.0
SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
    a& = _NEWIMAGE(1, 1, 32)
    _DEST a&
    PSET (0, 0), K
    _DEST 0
    _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
    _FREEIMAGE a& '<<< this is important!
END SUB

B = B + ...
QB64 x 64 v1.2 2018 0228/86 git b30af92
QB64 v1.2 2018 0228/86 git b30af92
QB64 v1.1 2017 1106/82

Online FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: Helicopter blades
« Reply #4 on: August 31, 2018, 11:58:40 AM »
Looking really good, gentlemen.

Re: Helicopter blades
« Reply #5 on: August 31, 2018, 12:10:41 PM »
Thanks, I though about changing the aspect of the ellipse and blade width according my relation to horizon but decided to have lunch instead. :)
B = B + ...
QB64 x 64 v1.2 2018 0228/86 git b30af92
QB64 v1.2 2018 0228/86 git b30af92
QB64 v1.1 2017 1106/82

Online TerryRitchie

  • Semper Fidelis
Re: Helicopter blades
« Reply #6 on: August 31, 2018, 01:17:30 PM »
I made blades rectangular and then played with code some more. :)

Cool!
g=c800:5 fixes everything

Re: Helicopter blades
« Reply #7 on: August 31, 2018, 05:00:13 PM »
Here is my post lunch launch post:
Code: [Select]
'
' Mod 2  Helicopter blades idea started by Terry Ritchie mods by B+ 2018-08-31

CONST PI = 3.1415926
CONST horizon = 300
CONST WW = 800
CONST WH = 600
start = -.00000001
finish = -2 * PI / 16
steps = finish / 20
inc = -.0981726875

SCREEN _NEWIMAGE(WW, WH, 32)
_SCREENMOVE 250, 50
CLS


_MOUSEHIDE
WHILE _KEYDOWN(27) = 0
    a = a + _PI(1.111)
    IF a > _PI(2) THEN a = a - _PI(2)
    aspect = ABS(horizon - my) / (WH * .5)
    IF aspect > .35 THEN aspect = .35
    bladeWidth = 20 * aspect
    CLS
    FOR i = 0 TO horizon
        midInk 0, 0, 128, 200, 200, 255, i / horizon
        LINE (0, i)-(WW, i)
    NEXT
    FOR i = horizon% TO WH
        midInk 50, 200, 50, 50, 128, 50, (i - horizon) / (WH - horizon)
        LINE (0, i)-(WW, i)
    NEXT
    FOR k = 0 TO 3
        radian = a + k * -1.5707963
        IF radian < -2 * PI THEN radian = radian + 2 * PI
        x1 = mx + 15 * COS(radian)
        y1 = my + aspect * 15 * SIN(radian)
        y3 = WH - .35 * 150 + .35 * 15 * SIN(radian)
        x2 = mx + 135 * COS(radian)
        y2 = my + aspect * 135 * SIN(radian)
        y4 = WH - .35 * 150 + .35 * 135 * SIN(radian)
        IF my > horizon THEN c~& = _RGB32(255, 255, 255) ELSE c~& = _RGB32(60, 60, 60)
        thic x1, y1, x2, y2, bladeWidth, c~&
        thic x1, y3, x2, y4, 20 * .35, _RGB32(0, 0, 0)
        _DISPLAY
    NEXT k
    PRINT speed
    _DISPLAY
    WHILE _MOUSEINPUT: WEND
    my = _MOUSEY: mx = _MOUSEX
    IF my <> 0 THEN speed = 60 * (WH - my) / WH ELSE speed = 30
    _LIMIT speed
WEND


SUB thic (x1, y1, x2, y2, thick, K AS _UNSIGNED LONG)
    t2 = thick / 2
    IF t2 < 1 THEN t2 = 1
    a = _ATAN2(y2 - y1, x2 - x1)
    x3 = x1 + t2 * COS(a + _PI(.5))
    y3 = y1 + t2 * SIN(a + _PI(.5))
    x4 = x1 + t2 * COS(a - _PI(.5))
    y4 = y1 + t2 * SIN(a - _PI(.5))
    x5 = x2 + t2 * COS(a + _PI(.5))
    y5 = y2 + t2 * SIN(a + _PI(.5))
    x6 = x2 + t2 * COS(a - _PI(.5))
    y6 = y2 + t2 * SIN(a - _PI(.5))
    ftri x6, y6, x4, y4, x3, y3, K
    ftri x3, y3, x5, y5, x6, y6, K
END SUB

' found at QB64.net:    http://www.qb64.net/forum/index.php?topic=14425.0
SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
    a& = _NEWIMAGE(1, 1, 32)
    _DEST a&
    PSET (0, 0), K
    _DEST 0
    _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
    _FREEIMAGE a& '<<< this is important!
END SUB

SUB midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
    COLOR _RGB(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
END SUB

B = B + ...
QB64 x 64 v1.2 2018 0228/86 git b30af92
QB64 v1.2 2018 0228/86 git b30af92
QB64 v1.1 2017 1106/82

Online TerryRitchie

  • Semper Fidelis
Re: Helicopter blades
« Reply #8 on: September 01, 2018, 12:48:18 PM »
Your math-fu astounds me. I wish I had your mathematical chops.
g=c800:5 fixes everything

Re: Helicopter blades
« Reply #9 on: September 01, 2018, 01: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.
B = B + ...
QB64 x 64 v1.2 2018 0228/86 git b30af92
QB64 v1.2 2018 0228/86 git b30af92
QB64 v1.1 2017 1106/82

Online STxAxTIC

  • QB64 Developer
Re: Helicopter blades
« Reply #10 on: September 01, 2018, 04:04:25 PM »
Quote
Your math-fu astounds me. I wish I had your mathematical chops.
Pun intended?
"An eye for an eye like a fish needs a bicycle" - Adolf Lincoln

QB64 Projects:
http://www.barnesreport.net/sxript/
http://www.barnesreport.net/sprezzo/

Online TerryRitchie

  • Semper Fidelis
Re: Helicopter blades
« Reply #11 on: September 01, 2018, 04: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. :)
g=c800:5 fixes everything