Author Topic: Solar Flare  (Read 10213 times)

0 Members and 1 Guest are viewing this topic.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Solar Flare
« on: December 11, 2020, 12:10:43 am »
based on code from SierraKen

I corrected pi,  was 3.14159265353 it is now 3.14159265358
Quote
SCREEN _NEWIMAGE(1000, 800, 32)
DIM pi AS DOUBLE
DIM c AS DOUBLE
DIM st AS DOUBLE
pi = 3.14159265358 * 2

DO

    i$ = INKEY$
    IF i$ = CHR$(27) THEN END


    startx = 70 + RND * 10
    starty = 70 + RND * 10

    st = (RND * pi)
    x = (SIN(st) * startx)
    y = (COS(st) * startx)

    FOR z% = 1 TO 300
        _LIMIT 1600
        c = _RGB32(255, 50, z%)
        PSET (500 + (x * (1 + z% / 100)), 400 + (y * (1 + z% / 100))), c

    NEXT z%

LOOP
END
« Last Edit: December 11, 2020, 02:02:33 am by NOVARSEG »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Solar Flare
« Reply #1 on: December 11, 2020, 12:33:53 am »
Great job!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Solar Flare
« Reply #2 on: December 11, 2020, 12:44:00 am »
Thanks

I would like to make the center look more like the sun however this could be a solar eclipse too.


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Solar Flare
« Reply #3 on: December 11, 2020, 01:09:11 am »
Quote
I would like to make the center look more like the sun

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. FOR r = 0 TO 500 STEP .25
  3.     CIRCLE (400, 300), r, Ink~&(&HFFFFFF00, &HFF220088, r / 500)
  4.  
  5. SUB cAnalysis (c AS _UNSIGNED LONG, outRed, outGrn, outBlu, outAlp)
  6.     outRed = _RED32(c): outGrn = _GREEN32(c): outBlu = _BLUE32(c): outAlp = _ALPHA32(c)
  7.  
  8. FUNCTION Ink~& (c1 AS _UNSIGNED LONG, c2 AS _UNSIGNED LONG, fr##)
  9.     DIM R1, G1, B1, A1, R2, G2, B2, A2
  10.     cAnalysis c1, R1, G1, B1, A1
  11.     cAnalysis c2, R2, G2, B2, A2
  12.     Ink~& = _RGB32(R1 + (R2 - R1) * fr##, G1 + (G2 - G1) * fr##, B1 + (B2 - B1) * fr##, A1 + (A2 - A1) * fr##)
  13.  
  14.  

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Solar Flare
« Reply #4 on: December 11, 2020, 01:18:35 am »
WOW

realistic!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Solar Flare
« Reply #5 on: December 11, 2020, 01:38:43 am »
'Updated Solar Flare with additional code from SierraKen

I corrected pi,  was 3.14159265353 it is now 3.14159265358

Quote
'SCREEN _NEWIMAGE(800, 600, 32)

SCREEN _NEWIMAGE(1000, 800, 32)
DIM pi AS DOUBLE
DIM c AS DOUBLE
DIM st AS DOUBLE
pi = 3.14159265358 * 2


FOR r = 0 TO 70 STEP .25
    CIRCLE (500, 400), r, Ink~&(&HFFFFFF00, &HFF220088, r / 500)
NEXT


DO

    i$ = INKEY$
    IF i$ = CHR$(27) THEN END


    startx = 65 + RND * 10
    starty = 65 + RND * 10

    st = (RND * pi)
    x = (SIN(st) * startx)
    y = (COS(st) * starty)

    FOR z% = 1 TO 400
        _LIMIT 1600
        c = _RGB32(255, 0, z% / 1.5)
        PSET (500 + (x * (1 + z% / 100)), 400 + (y * (1 + z% / 100))), c

    NEXT z%

LOOP
END
SUB cAnalysis (c AS _UNSIGNED LONG, outRed, outGrn, outBlu, outAlp)
    outRed = _RED32(c): outGrn = _GREEN32(c): outBlu = _BLUE32(c): outAlp = _ALPHA32(c)
END SUB

FUNCTION Ink~& (c1 AS _UNSIGNED LONG, c2 AS _UNSIGNED LONG, fr##)
    DIM R1, G1, B1, A1, R2, G2, B2, A2
    cAnalysis c1, R1, G1, B1, A1
    cAnalysis c2, R2, G2, B2, A2
    Ink~& = _RGB32(R1 + (R2 - R1) * fr##, G1 + (G2 - G1) * fr##, B1 + (B2 - B1) * fr##, A1 + (A2 - A1) * fr##)
END FUNCTION
« Last Edit: December 11, 2020, 01:59:25 am by NOVARSEG »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Solar Flare
« Reply #6 on: December 11, 2020, 04:18:07 am »
NEB CRABULA

Quote
SCREEN _NEWIMAGE(1000, 800, 32)
DIM pi AS DOUBLE
DIM c AS DOUBLE
DIM st AS DOUBLE
pi = 3.14159265358 * 2


FOR r = 0 TO 70 STEP .25
    CIRCLE (500, 400), r, Ink~&(&HFFFFFF00, &HFF220088, r / 500)
NEXT


DO

    i$ = INKEY$
    IF i$ = CHR$(27) THEN END


    startx = 70 + RND * 5
    starty = 70 + RND * 5
    st = RND * pi
    x = (SIN(st) * startx)
    y = (COS(st) * starty)
    n% = 0
    FOR z% = 1 TO 400
        _LIMIT 16000
        c = _RGB32(255, 0, z% / 1.5)

        FOR n% = 1 TO 50

            xx = 500 + (x * (1 + (z% + n%) / 100))
            yy = 400 + (y * (1 + (z% + n%) / 100))

            PSET (xx - 1, yy), c
            PSET (xx, yy - 1), c
            PSET (xx - 1, yy - 1), c
            PSET (xx, yy), c

        NEXT n%
        xx = 500 + (x * (1 + (z%) / 100))
        yy = 400 + (y * (1 + (z%) / 100))
        PRESET (xx - 1, yy)
        PRESET (xx, yy - 1)
        PRESET (xx - 1, yy - 1)
        PRESET (xx, yy)

     
    NEXT z%

LOOP
END
SUB cAnalysis (c AS _UNSIGNED LONG, outRed, outGrn, outBlu, outAlp)
    outRed = _RED32(c): outGrn = _GREEN32(c): outBlu = _BLUE32(c): outAlp = _ALPHA32(c)
END SUB

FUNCTION Ink~& (c1 AS _UNSIGNED LONG, c2 AS _UNSIGNED LONG, fr##)
    DIM R1, G1, B1, A1, R2, G2, B2, A2
    cAnalysis c1, R1, G1, B1, A1
    cAnalysis c2, R2, G2, B2, A2
    Ink~& = _RGB32(R1 + (R2 - R1) * fr##, G1 + (G2 - G1) * fr##, B1 + (B2 - B1) * fr##, A1 + (A2 - A1) * fr##)
END FUNCTION
« Last Edit: December 11, 2020, 04:19:21 am by NOVARSEG »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Solar Flare
« Reply #7 on: December 11, 2020, 04:35:54 am »
NEB CRABULA ver2  (slowed down with color change)

Quote
SCREEN _NEWIMAGE(1000, 800, 32)
DIM pi AS DOUBLE
DIM c AS DOUBLE
DIM st AS DOUBLE
pi = 3.14159265358 * 2


FOR r = 0 TO 70 STEP .25
    CIRCLE (500, 400), r, Ink~&(&HFFFFFF00, &HFF220088, r / 500)
NEXT


DO

    i$ = INKEY$
    IF i$ = CHR$(27) THEN END


    startx = 70 + RND * 5
    starty = 70 + RND * 5
    st = RND * pi
    x = (SIN(st) * startx)
    y = (COS(st) * starty)
    n% = 0
    FOR z% = 1 TO 400
        _LIMIT 400
        c = _RGB32(255, 255 - z%, z% / 1.5)

        FOR n% = 1 TO 50

            xx = 500 + (x * (1 + (z% + n%) / 100))
            yy = 400 + (y * (1 + (z% + n%) / 100))

            PSET (xx - 1, yy), c
            PSET (xx, yy - 1), c
            PSET (xx - 1, yy - 1), c
            PSET (xx, yy), c

        NEXT n%
        xx = 500 + (x * (1 + (z%) / 100))
        yy = 400 + (y * (1 + (z%) / 100))
        PRESET (xx - 1, yy)
        PRESET (xx, yy - 1)
        PRESET (xx - 1, yy - 1)
        PRESET (xx, yy)




    NEXT z%

LOOP
END
SUB cAnalysis (c AS _UNSIGNED LONG, outRed, outGrn, outBlu, outAlp)
    outRed = _RED32(c): outGrn = _GREEN32(c): outBlu = _BLUE32(c): outAlp = _ALPHA32(c)
END SUB

FUNCTION Ink~& (c1 AS _UNSIGNED LONG, c2 AS _UNSIGNED LONG, fr##)
    DIM R1, G1, B1, A1, R2, G2, B2, A2
    cAnalysis c1, R1, G1, B1, A1
    cAnalysis c2, R2, G2, B2, A2
    Ink~& = _RGB32(R1 + (R2 - R1) * fr##, G1 + (G2 - G1) * fr##, B1 + (B2 - B1) * fr##, A1 + (A2 - A1) * fr##)
END FUNCTION

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Solar Flare
« Reply #8 on: December 11, 2020, 08:20:55 am »
@NOVARSEG

Please, use the QB64 code block option for pasting QB64 code

 
Screenshot 2020-12-11 081916.png

 
Screenshot 2020-12-11 082008.png
« Last Edit: December 11, 2020, 08:27:22 am by SpriggsySpriggs »
Shuwatch!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Solar Flare
« Reply #9 on: December 11, 2020, 08:40:30 am »
Nice sun/circle snippet, @bplus.  What a coincidence too, I was just looking for code to do something like that.

- Dav

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Solar Flare
« Reply #10 on: December 11, 2020, 12:28:44 pm »
Quote
I corrected pi,  was 3.14159265353 it is now 3.14159265358

Hi @NOVARSEG  get your free pi here  _PI a constant that QB64 has built in. Try it out:
Code: QB64: [Select]

Posting your code in Quote Tags is not quite right, neither is the extra large print, please use the button right next to Quote Tags Button that Spriggsy just pointed to, it's just left of quote and looks either like QB64 icon or # sign.




Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Solar Flare
« Reply #11 on: December 11, 2020, 12:34:55 pm »
Nice sun/circle snippet, @bplus.  What a coincidence too, I was just looking for code to do something like that.

- Dav

@ Dav Yeah that is my newest version of MidInk, blending one color into another depending how far from first color to 2nd color as a fraction going from 0 at first color location To 1 at 2nd color location.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Solar Flare
« Reply #12 on: December 11, 2020, 02:51:34 pm »
Dig the rays:
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2.     FOR r = 0 TO 500 STEP .25
  3.         CIRCLE (400, 300), r, Ink~&(&HFFFFFF44, &HFF220088, r / 500)
  4.     NEXT
  5.     FOR i = 1 TO 100
  6.         a = RND * _PI(2)
  7.         r1 = 20 + RND * 100
  8.         r2 = r1 + 20 + RND * 260
  9.         midx = _WIDTH / 2 + (r1 + (r2 - r1) / 2) * COS(a): midy = _HEIGHT / 2 + (r1 + (r2 - r1) / 2) * SIN(a)
  10.         ray& = _NEWIMAGE(r2 - r1, 1, 32)
  11.         _PUTIMAGE , 0, ray&, (400, 300)-STEP(r2 - r1, 1)
  12.         RotoZoom midx, midy, ray&, 1, _R2D(a)
  13.         _FREEIMAGE ray&
  14.     NEXT
  15.     _DISPLAY
  16.     _LIMIT 60 'try to reduce fan usage
  17.  
  18. SUB cAnalysis (c AS _UNSIGNED LONG, outRed, outGrn, outBlu, outAlp)
  19.     outRed = _RED32(c): outGrn = _GREEN32(c): outBlu = _BLUE32(c): outAlp = _ALPHA32(c)
  20.  
  21. FUNCTION Ink~& (c1 AS _UNSIGNED LONG, c2 AS _UNSIGNED LONG, fr##)
  22.     DIM R1, G1, B1, A1, R2, G2, B2, A2
  23.     cAnalysis c1, R1, G1, B1, A1
  24.     cAnalysis c2, R2, G2, B2, A2
  25.     Ink~& = _RGB32(R1 + (R2 - R1) * fr##, G1 + (G2 - G1) * fr##, B1 + (B2 - B1) * fr##, A1 + (A2 - A1) * fr##)
  26.  
  27. SUB RotoZoom (X AS LONG, Y AS LONG, Image AS LONG, Scale AS SINGLE, Rotation AS SINGLE)
  28.     DIM px(3) AS SINGLE, py(3) AS SINGLE, W&, H&, sinr!, cosr!, i&, x2&, y2&
  29.     W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
  30.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  31.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  32.     sinr! = SIN(-Rotation / 57.2957795131): cosr! = COS(-Rotation / 57.2957795131)
  33.     FOR i& = 0 TO 3
  34.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * Scale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * Scale + Y
  35.         px(i&) = x2&: py(i&) = y2&
  36.     NEXT
  37.     _MAPTRIANGLE (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  38.     _MAPTRIANGLE (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  39.  
  40.  
  41.  
« Last Edit: December 11, 2020, 02:54:49 pm by bplus »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Solar Flare
« Reply #13 on: December 11, 2020, 08:18:59 pm »
bplus
nice sun effect

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Solar Flare
« Reply #14 on: December 12, 2020, 04:45:48 am »
Solar flare (photons)  based on code from SierraKen

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1000, 800, 32)
  2. 'SCREEN _NEWIMAGE(800, 600, 32)
  3. DIM starx(1000), stary(1000)
  4. DIM sz(1000) AS DOUBLE
  5. DIM speed(1000) AS DOUBLE
  6. DIM x(1000) AS DOUBLE
  7. DIM y(1000) AS DOUBLE
  8. pi = 3.14159265358
  9.  
  10.  
  11.     _LIMIT 100
  12.     a$ = INKEY$
  13.     IF a$ = CHR$(27) THEN END
  14.     IF a$ = " " THEN f = f + 1
  15.     IF f = 1 THEN _FULLSCREEN
  16.     IF f = 2 THEN _FULLSCREEN OFF: f = 0
  17.  
  18.     stars = INT(RND * 100) + 1
  19.     IF stars > 80 THEN
  20.         s = s + 1
  21.  
  22.         IF s > 950 THEN s = 1
  23.         rad = RND * (pi * 2)
  24.         x = SIN(rad)
  25.         y = COS(rad)
  26.         starx(s) = x
  27.         stary(s) = y
  28.         x(s) = x ' * RND * 5
  29.         y(s) = y ' * RND * 5
  30.  
  31.         'Set size and speed
  32.         rr = RND
  33.         speed(s) = ((1 + rr / 400) + .002)
  34.         sz(s) = rr + .55
  35.  
  36.     END IF
  37.  
  38.  
  39.     FOR t = 1 TO 950
  40.  
  41.         stary(t) = stary(t) * speed(t)
  42.         starx(t) = starx(t) * speed(t)
  43.         'rr = RND * 100
  44.         cx = starx(t) + 500 + x(t) * 50
  45.         cy = stary(t) + 400 + y(t) * 50
  46.         r = sz(t)
  47.         c = _RGB32(255, 255, 255)
  48.         fillCircle cx, cy, r, c
  49.  
  50.  
  51.         'skip:
  52.     NEXT t
  53.     _DISPLAY
  54.     LINE (0, 0)-(_WIDTH, _HEIGHT), _RGB32(0, 0, 0, 20), BF
  55.  
  56.     FOR b = 0 TO 45 STEP .25
  57.         CIRCLE (500, 400), b, Ink~&(&HFFFFFF00, &HFF220088, b / 500)
  58.     NEXT
  59.  
  60. 'from Steve Gold standard
  61. SUB fillCircle (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  62.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  63.     DIM X AS INTEGER, Y AS INTEGER
  64.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  65.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  66.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  67.     WHILE X > Y
  68.         RadiusError = RadiusError + Y * 2 + 1
  69.         IF RadiusError >= 0 THEN
  70.             IF X <> Y + 1 THEN
  71.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  72.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  73.             END IF
  74.             X = X - 1
  75.             RadiusError = RadiusError - X * 2
  76.         END IF
  77.         Y = Y + 1
  78.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  79.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  80.     WEND
  81.  
  82. SUB cAnalysis (c AS _UNSIGNED LONG, outRed, outGrn, outBlu, outAlp)
  83.     outRed = _RED32(c): outGrn = _GREEN32(c): outBlu = _BLUE32(c): outAlp = _ALPHA32(c)
  84.  
  85. FUNCTION Ink~& (c1 AS _UNSIGNED LONG, c2 AS _UNSIGNED LONG, fr##)
  86.     DIM R1, G1, B1, A1, R2, G2, B2, A2
  87.     cAnalysis c1, R1, G1, B1, A1
  88.     cAnalysis c2, R2, G2, B2, A2
  89.     Ink~& = _RGB32(R1 + (R2 - R1) * fr##, G1 + (G2 - G1) * fr##, B1 + (B2 - B1) * fr##, A1 + (A2 - A1) * fr##)

« Last Edit: December 12, 2020, 04:48:42 am by NOVARSEG »