Author Topic: Exploding logo  (Read 4375 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
Exploding logo
« on: December 23, 2021, 07:32:03 am »
Hi, I was just playing with QB64 in particle style...

Code: QB64: [Select]
  1. Img = -11 'ico image file
  2. Screen _NewImage(300, 300, 32)
  3. CenterX = 150: CenterY = 150
  4. S = _Width(Img) * _Height(Img)
  5.     A As Single
  6.     L As Integer
  7.     C As _Unsigned Long
  8.     LG As Integer
  9.     oLG As Integer
  10. Dim P(S) As P
  11. PS = _Source
  12. i = 0
  13. For Y = 0 To _Height(Img) - 1
  14.     For X = 0 To _Width(Img) - 1
  15.         P(i).A = _Atan2(X - _Width(Img) \ 2, Y - _Height(Img) \ 2)
  16.         P(i).L = _Hypot(Y - _Height(Img) \ 2, X - _Width(Img) \ 2)
  17.         P(i).C = Point(X, Y)
  18.         P(i).LG = (10 + Rnd * 300) * Sgn(P(i).A)
  19.         P(i).oLG = P(i).LG
  20.         i = i + 1
  21. Next X, Y
  22. Do Until k& = 27
  23.     k& = _KeyHit
  24.     Do Until vsak = 2
  25.         i = 0
  26.         vsak = 0
  27.         For X = 0 To _Width(Img) - 1
  28.             For Y = 0 To _Height(Img) - 1
  29.                 If Abs(P(i).LG) > 0 Then
  30.                     If P(i).LG > 0 Then P(i).LG = P(i).LG - 1 Else P(i).LG = P(i).LG + 1
  31.                     vsak = 1
  32.                 End If
  33.                 If Sgn(P(i).A) = 1 Then DX = CenterX + Sin(P(i).A) * (P(i).L + P(i).LG) Else DX = CenterX + Sin(P(i).A) * (P(i).L - P(i).LG)
  34.                 If Sgn(P(i).A) = 1 Then DY = CenterY + Cos(P(i).A) * (P(i).L + P(i).LG) Else DY = CenterY + Cos(P(i).A) * (P(i).L - P(i).LG)
  35.                 PSet (DX, DY), P(i).C
  36.                 i = i + 1
  37.         Next Y, X
  38.         If vsak = 0 Then vsak = 2
  39.         _Display
  40.         _Limit 60
  41.         Cls
  42.     Loop
  43.     vsak = 0
  44.     Do Until vsak = 2
  45.         i = 0
  46.         vsak = 0
  47.         For X = 0 To _Width(Img) - 1
  48.             For Y = 0 To _Height(Img) - 1
  49.  
  50.                 If Abs(P(i).LG) < Abs(P(i).oLG) Then
  51.                     If P(i).oLG > 0 Then P(i).LG = P(i).LG + 1 Else P(i).LG = P(i).LG - 1
  52.                     vsak = 1
  53.                 End If
  54.  
  55.                 If Sgn(P(i).A) = 1 Then DX = CenterX + Sin(P(i).A) * (P(i).L + P(i).LG) Else DX = CenterX + Sin(P(i).A) * (P(i).L - P(i).LG)
  56.                 If Sgn(P(i).A) = 1 Then DY = CenterY + Cos(P(i).A) * (P(i).L + P(i).LG) Else DY = CenterY + Cos(P(i).A) * (P(i).L - P(i).LG)
  57.                 PSet (DX, DY), P(i).C
  58.                 i = i + 1
  59.         Next Y, X
  60.         If vsak = 0 Then vsak = 2
  61.         _Display
  62.         _Limit 60
  63.         Cls
  64.     Loop
  65.     vsak = 0
  66.  

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Exploding logo
« Reply #1 on: December 24, 2021, 08:15:37 am »
Cool effect..!  I like it...
Logic is the beginning of wisdom.

Offline Colonel_Panic

  • Newbie
  • Posts: 54
    • View Profile
Re: Exploding logo
« Reply #2 on: December 24, 2021, 06:39:32 pm »
you got me thinking particle trace; GIMP filter... ?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Exploding logo
« Reply #3 on: December 25, 2021, 04:55:13 am »
@Colonel_Panic
Quote
Filter GIMP...?

Hi. This is not a filter per se. They are just vectors. The position of a point is determined by the angle of the point's coordinates relative to the center of the screen and their distance from the center of the screen. Just a 2D vector. By changing the distance from the center, you determine the "explosive" position of the point. In practice, you can create even more complex effects, such as rotation after an explosion (just calculate the angle increment so that it is at the correct value at the destination). Maybe I'll try later, I got new toys yesterday, so now I'm sitting and soldering the circuit boards :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Exploding logo
« Reply #4 on: December 25, 2021, 12:24:52 pm »
I try exploding Christmas message:

Code: QB64: [Select]
  1. _Title "Merry Christmas 2021"
  2. Const back = _RGB32(0, 200, 100), cx = 249, cy = 249
  3. Type pt
  4.     As Single x, y, dx, dy, tx, ty, tw
  5.     As _Unsigned Long c
  6.  
  7. Screen _NewImage(500, 500, 32)
  8. _ScreenMove 450, 200
  9.  
  10. ReDim p(1 To 20000) As pt 'track particles
  11. Dim As Long np, i, pmax, psave, f
  12. Dim As Single x, y, speed, a
  13. Dim s$
  14.  
  15. f = _LoadFont("arial.ttf", 48) ' everyone has arial correct?
  16. 'Print f   'check font loaded
  17. 'End
  18.  
  19. Color _RGB32(255, 0, 48), back
  20. Color _RGB32(255, 255, 255)
  21. _PrintString (13, 223), "Merry Christmas 2021"
  22.  
  23. Color _RGB32(0, 0, 0)
  24. _PrintString (17, 227), "Merry Christmas 2021"
  25.  
  26. Color _RGB32(255, 0, 48)
  27. _PrintString (15, 225), "Merry Christmas 2021"
  28.  
  29. speed = 15
  30. np = np + 1
  31. For y = 0 To _Width - 1 '                   gather data of text points
  32.     For x = 0 To _Height - 1
  33.         If x = cx And y = cy Then psave = np
  34.         If Point(x, y) <> back Then
  35.             p(np).tx = x: p(np).ty = y '  save original location  target x, y
  36.             p(np).x = x: p(np).y = y '    current location of particle
  37.             a = _Atan2(y - cy, x - cx)
  38.             p(np).dx = speed * Cos(a): p(np).dy = speed * Sin(a) ' setup move vectors
  39.             p(np).c = Point(x, y)
  40.             np = np + 1
  41.         End If
  42.     Next
  43. pmax = np - 1
  44.  
  45. 'check we got our data right, OK!
  46. 'Sleep
  47. 'Cls
  48. 'Sleep
  49. 'For i = 1 To pmax
  50. '    PSet (p(i).x, p(i).y), p(i).c
  51. 'Next
  52.  
  53. While _KeyDown(27) = 0
  54.     _Delay 2
  55.     ' Explode
  56.     While p(psave).x > -_Width * Sqr(2) And p(psave).x < _Width * Sqr(2) ' center point is still visible
  57.         Cls
  58.         For i = 1 To pmax
  59.             p(i).x = p(i).x + p(i).dx: p(i).y = p(i).y + p(i).dy
  60.             PSet (p(i).x, p(i).y), p(i).c
  61.         Next
  62.         _Display
  63.         _Limit 30
  64.     Wend
  65.  
  66.     While p(psave).x <> p(psave).tx ' back in place
  67.         Cls
  68.         For i = 1 To pmax
  69.             p(i).x = p(i).x - p(i).dx: p(i).y = p(i).y - p(i).dy
  70.             PSet (p(i).x, p(i).y), p(i).c
  71.         Next
  72.         _Display
  73.         _Limit 30
  74.     Wend
  75.  

Offline Colonel_Panic

  • Newbie
  • Posts: 54
    • View Profile
Re: Exploding logo
« Reply #5 on: December 25, 2021, 12:46:58 pm »
Well, I never was in love with GIMP calling them "filters" anyways.
But, now its the word i use for it, "filter".

I assume you have seen "ALPHA TO LOGO" set of filters in GIMP?
some versions have the alpha to logo filter collection, some dont.

anyways, from your description of your "particle trace" routine...
I had the idea of... someone else makes a "different filter" and it gets added to a list...
a routine for editing TEXT and controlling text attributes...

and BING, we would have a "alpha to logo"  little IDE going on. We could slowly assemble extra filters, as people took it upon themselves to write a new filter...

In GIMP? I can only do ONE alpha-to-logo FILTER at all... if i want to go and do a "frozen" over top of the "sparkle" filter? It undoes it, and re-does the new one... I want to run BOTH one after the other...

the whole thing SOUNDS way more complicated than it actually is.
(if YOU dont want to play with this idea? i will try it in my spare time)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Exploding logo
« Reply #6 on: December 25, 2021, 03:06:06 pm »
@Colonel_Panic  Oh yeah, alpha trails sounds cool!

Update with trails:
Code: QB64: [Select]
  1. _Title "Merry Christmas 2021"
  2. Const back = _RGB32(0, 200, 100), cx = 249, cy = 249
  3. Type pt
  4.     As Single x, y, dx, dy, tx, ty, tw
  5.     As _Unsigned Long c
  6.  
  7. Screen _NewImage(500, 500, 32)
  8. _ScreenMove 450, 200
  9.  
  10. ReDim p(1 To 20000) As pt 'track particles
  11. Dim As Long np, i, pmax, psave, f, j
  12. Dim As Single x, y, speed, a
  13. Dim s$
  14.  
  15. f = _LoadFont("arial.ttf", 48) ' everyone has arial correct?
  16. 'Print f   'check font loaded
  17. 'End
  18.  
  19. Color _RGB32(255, 0, 48), back
  20. Color _RGB32(255, 255, 255)
  21. _PrintString (13, 223), "Merry Christmas 2021"
  22.  
  23. Color _RGB32(0, 0, 0)
  24. _PrintString (17, 227), "Merry Christmas 2021"
  25.  
  26. Color _RGB32(255, 0, 48)
  27. _PrintString (15, 225), "Merry Christmas 2021"
  28.  
  29. speed = 10
  30. np = np + 1
  31. For y = 0 To _Width - 1 '                   gather data of text points
  32.     For x = 0 To _Height - 1
  33.         If x = cx And y = cy Then psave = np
  34.         If Point(x, y) <> back Then
  35.             p(np).tx = x: p(np).ty = y '  save original location  target x, y
  36.             p(np).x = x: p(np).y = y '    current location of particle
  37.             a = _Atan2(y - cy, x - cx)
  38.             p(np).dx = speed * Cos(a): p(np).dy = speed * Sin(a) ' setup move vectors
  39.             p(np).c = Point(x, y)
  40.             np = np + 1
  41.         End If
  42.     Next
  43. pmax = np - 1
  44.  
  45. 'check we got our data right, OK!
  46. 'Sleep
  47. 'Cls
  48. 'Sleep
  49. 'For i = 1 To pmax
  50. '    PSet (p(i).x, p(i).y), p(i).c
  51. 'Next
  52.  
  53. While _KeyDown(27) = 0
  54.     _Delay 2
  55.     ' Explode
  56.     While p(psave).x > -_Width * Sqr(2) And p(psave).x < _Width * Sqr(2) ' center point is still visible
  57.         Line (0, 0)-(500, 500), _RGBA32(0, 200, 100, 30), BF
  58.         For i = 1 To pmax
  59.             p(i).x = p(i).x + p(i).dx: p(i).y = p(i).y + p(i).dy
  60.             PSet (p(i).x, p(i).y), p(i).c
  61.         Next
  62.         _Display
  63.         _Limit 30
  64.     Wend
  65.     Cls
  66.     While p(psave).x <> p(psave).tx ' back in place
  67.         Line (0, 0)-(500, 500), _RGBA32(0, 200, 100, 30), BF
  68.         For i = 1 To pmax
  69.             p(i).x = p(i).x - p(i).dx: p(i).y = p(i).y - p(i).dy
  70.             PSet (p(i).x, p(i).y), p(i).c
  71.         Next
  72.         _Display
  73.         _Limit 30
  74.     Wend
  75.     For j = 1 To 100
  76.         Line (0, 0)-(500, 500), _RGBA32(0, 200, 100, 100), BF
  77.         For i = 1 To pmax
  78.             PSet (p(i).x, p(i).y), p(i).c
  79.         Next
  80.         _Display
  81.         _Limit 30
  82.     Next
  83.  
« Last Edit: December 25, 2021, 09:28:22 pm by bplus »