Author Topic: Ascii Plasma!  (Read 6091 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Ascii Plasma!
« on: November 11, 2021, 03:16:00 am »
Look what I found trying to build isobar / contour lines!

Code: QB64: [Select]
  1. _Title  "Ansii Plasma - press spacebar for new set of points, be sure to swirl your mouse in the stuff!"  ' b+ 2021-11-11
  2. _ScreenMove 100, 40
  3.  
  4. Type xy
  5.     x As Single
  6.     y As Single
  7.     dx As Single
  8.     dy As Single
  9.  
  10. Width 150, 80
  11.  
  12. nP = 6
  13. Dim p(1 To nP) As xy, f(6)
  14.  
  15. restart:
  16. For n = 1 To nP
  17.     p(n).x = Rnd * _Width: p(n).y = Rnd * _Height: p(n).dx = .25 * (Rnd * 2 - 1): p(n).dy = 2 * (Rnd * 2 - 1)
  18.     f(n) = n * .015
  19.  
  20. While _KeyDown(27) = 0
  21.     Cls
  22.     If InKey$ = " " Then GoTo restart
  23.     For i = 1 To nP - 1
  24.         p(i).x = p(i).x + p(i).dx
  25.         If p(i).x > _Width - 1 Or p(i).x < 1 Then p(i).dx = -p(i).dx
  26.         If p(i).x < 1 Then p(i).x = 1: If p(i).x > _Width Then p(i).x = _Width
  27.         p(i).y = p(i).y + p(i).dy
  28.         If p(i).y > _Height Or p(i).y < 1 Then p(i).dy = -p(i).dy
  29.         If p(i).y < 1 Then p(i).y = 1: If p(i).y > _Height Then p(i).y = _Height
  30.     Next
  31.     p(nP).x = _MouseX: p(nP).y = _MouseY
  32.     For y = 1 To _Height
  33.         For x = 1 To _Width
  34.             d = 0
  35.             For n = 1 To nP
  36.                 dx = x - p(n).x: dy = y - p(n).y
  37.                 k = Sqr(dx * dx + dy * dy)
  38.                 d = d + (Sin(k * f(n)) + 1) / 2
  39.             Next
  40.             Locate y, x: Print Chr$(Int(d * 20));
  41.         Next
  42.     Next
  43.     _Display
  44.     _Limit 40
  45.  
  46.  
  47.  
Ascii Plasma!.PNG
* Ascii Plasma!.PNG (Filesize: 109.95 KB, Dimensions: 1206x667, Views: 467)
« Last Edit: November 11, 2021, 03:23:59 am by bplus »

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Ascii Plasma!
« Reply #1 on: November 11, 2021, 06:29:12 am »
Very impressive!

Now train 12,000 monkeys to hold up placards to accomplish the same.
It works better if you plug it in.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Ascii Plasma!
« Reply #2 on: November 11, 2021, 10:49:27 am »
Wow - Very cool!

- Dav

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Ascii Plasma!
« Reply #3 on: November 11, 2021, 09:17:18 pm »
Bplus,

NOT just blue... lol

 
Screenshot from 2021-11-12 13-15-17.png
Logic is the beginning of wisdom.

Offline DANILIN

  • Forum Regular
  • Posts: 128
    • View Profile
    • Danilin youtube
Re: Ascii Plasma!
« Reply #4 on: November 13, 2021, 03:22:00 am »
? color ?

Code: QB64: [Select]
  1.             LOCATE y, x: COLOR (INT(d * 20) MOD 7): PRINT CHR$(INT(d * 20));  

! color !

 
color7plasma.PNG
« Last Edit: November 14, 2021, 03:45:29 am by DANILIN »
Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Ascii Plasma!
« Reply #5 on: November 13, 2021, 05:04:24 am »
Your method of selecting colour is WAY more efficient than my bunch of "if...then's"... Cool...
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ascii Plasma!
« Reply #6 on: November 13, 2021, 12:04:11 pm »
Colorized for Johnno's world:
Code: QB64: [Select]
  1. _Title "Ansii Plasma Colorized - press spacebar for new set of points, be sure to swirl your mouse in the stuff!" ' b+ 2021-11-11
  2. ' 2021-11-13 colorize version
  3. _ScreenMove 100, 40
  4.  
  5. Type xy
  6.     x As Single
  7.     y As Single
  8.     dx As Single
  9.     dy As Single
  10.  
  11. Screen _NewImage(1200, 640, 32)
  12.  
  13. 'Width 150, 80
  14.  
  15. nP = 6
  16. Dim p(1 To nP) As xy, f(nP)
  17.  
  18. restart:
  19. For n = 1 To nP
  20.     p(n).x = Rnd * _Width: p(n).y = Rnd * _Height: p(n).dx = .25 * (Rnd * 2 - 1): p(n).dy = 2 * (Rnd * 2 - 1)
  21.     f(n) = n * .015
  22.  
  23. While _KeyDown(27) = 0
  24.     Cls
  25.     If InKey$ = " " Then GoTo restart
  26.     For i = 1 To nP - 1
  27.         p(i).x = p(i).x + p(i).dx
  28.         If p(i).x > _Width - 1 Or p(i).x < 1 Then p(i).dx = -p(i).dx
  29.         If p(i).x < 1 Then p(i).x = 1: If p(i).x > _Width Then p(i).x = _Width
  30.         p(i).y = p(i).y + p(i).dy
  31.         If p(i).y > _Height Or p(i).y < 1 Then p(i).dy = -p(i).dy
  32.         If p(i).y < 1 Then p(i).y = 1: If p(i).y > _Height Then p(i).y = _Height
  33.     Next
  34.     p(nP).x = _MouseX \ 8: p(nP).y = _MouseY \ 8
  35.     For y = 1 To 80
  36.         For x = 1 To 150
  37.             d = 0
  38.             For n = 1 To nP
  39.                 dx = x - p(n).x: dy = y - p(n).y
  40.                 k = Sqr(dx * dx + dy * dy)
  41.                 d = d + (Sin(k * f(n)) + 1) / 2
  42.             Next
  43.             Color _RGB32(0, 0, d * 50)    ' <<<<<<<<<<<<<<<<<<<<<<<< EDIT 2021-11-13 more contrast
  44.             _PrintString ((x - 1) * 8, (y - 1) * 8), Chr$(Int(d * 20))
  45.         Next
  46.     Next
  47.     _Display
  48.     _Limit 40
  49.  
  50.  
  51.  

Edit: f(6) to f(nP)
« Last Edit: November 13, 2021, 09:58:53 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ascii Plasma!
« Reply #7 on: November 13, 2021, 01:30:57 pm »
BTW be sure to try nP at different numbers, nP =1 will just be the mouse.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ascii Plasma!
« Reply #8 on: November 13, 2021, 09:59:40 pm »
I meant to put more contrast in reply #6.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Ascii Plasma!
« Reply #9 on: November 14, 2021, 01:45:20 am »
Cool... and I even like the colour!
Logic is the beginning of wisdom.

Offline Sanmayce

  • Newbie
  • Posts: 63
  • Where is that English Text Sidekick?
    • View Profile
    • Sanmayce's home
Re: Ascii Plasma!
« Reply #10 on: November 16, 2021, 03:51:31 pm »
Many thanks @bplus , beautiful output! Love ASCII art!
It is my new screensaver, running at 5 fps and 7% CPU, hee-hee:

 
Plasma.png


Code: QB64: [Select]
  1. _Title "Ansii Plasma - press spacebar for new set of points, be sure to swirl your mouse in the stuff!" ' b+ 2021-11-11
  2. _ScreenMove 100, 40
  3.  
  4. Type xy
  5.     x As Single
  6.     y As Single
  7.     dx As Single
  8.     dy As Single
  9.  
  10. Width 180, 100
  11.  
  12. nP = 6
  13. Dim p(1 To nP) As xy, f(6)
  14.  
  15. restart:
  16. For n = 1 To nP
  17.     p(n).x = Rnd * _Width: p(n).y = Rnd * _Height: p(n).dx = .25 * (Rnd * 2 - 1): p(n).dy = 2 * (Rnd * 2 - 1)
  18.     f(n) = n * .015
  19.  
  20. While _KeyDown(27) = 0
  21.     Cls
  22.     If InKey$ = " " Then GoTo restart
  23.     For i = 1 To nP - 1
  24.         p(i).x = p(i).x + p(i).dx
  25.         If p(i).x > _Width - 1 Or p(i).x < 1 Then p(i).dx = -p(i).dx
  26.         If p(i).x < 1 Then p(i).x = 1: If p(i).x > _Width Then p(i).x = _Width
  27.         p(i).y = p(i).y + p(i).dy
  28.         If p(i).y > _Height Or p(i).y < 1 Then p(i).dy = -p(i).dy
  29.         If p(i).y < 1 Then p(i).y = 1: If p(i).y > _Height Then p(i).y = _Height
  30.     Next
  31.     p(nP).x = _MouseX: p(nP).y = _MouseY
  32.     For y = 1 To _Height
  33.         For x = 1 To _Width
  34.             d = 0
  35.             For n = 1 To nP
  36.                 dx = x - p(n).x: dy = y - p(n).y
  37.                 k = Sqr(dx * dx + dy * dy)
  38.                 d = d + (Sin(k * f(n)) + 1) / 2
  39.             Next
  40.             'Locate y, x: Print Chr$(Int(d * 20));
  41.             Locate y, x: Color (Int(d) Mod 7): Print Chr$(Int(d * 32));
  42.         Next
  43.     Next
  44.     _Display
  45.     _Limit 5
  46.  
He learns not to learn and reverts to what all men pass by.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ascii Plasma!
« Reply #11 on: November 16, 2021, 05:22:22 pm »
I'm glad you guys are having fun with this.

Nice mods! @DANILIN and @Sanmayce not sure what @johnno56 did but judging by comments something similar to Danilin's. I do like how Danilin's has every layer separated.

That reminds me I was working on contour lines or isobars...
« Last Edit: November 16, 2021, 05:31:46 pm by bplus »