QB64.org Forum

Active Forums => Programs => Topic started by: bplus on June 22, 2019, 10:06:39 pm

Title: Ectoplasm
Post by: bplus on June 22, 2019, 10:06:39 pm
Just picked up a case today at Retro.

Code: QB64: [Select]
  1. _TITLE "Ectoplasm" 'mod of Galileo's at Retro 2019-06-22 B+
  2. 'open window 256, 256
  3. SCREEN _NEWIMAGE(256, 256, 32)
  4. 'sh=peek("winheight")
  5. sh = _HEIGHT
  6. 'sw=peek("winwidth")
  7. sw = _WIDTH
  8. d = 1
  9.     'tm = peek("secondsrunning")
  10.     tm = TIMER(.001)
  11.     dr = ran(256): dg = ran(256): db = ran(256)
  12.     w = w + 5 / 83 '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< get things moving
  13.     FOR y = 0 TO sh
  14.         FOR x = 0 TO sw
  15.             vl = SIN(distance(x + tm, y, 128, 128) / 8 + w)
  16.             vl = vl + SIN(distance(x, y, 64, 64) / 8)
  17.             vl = vl + SIN(distance(x, y + tm / 7, 192, 64) / 7)
  18.             vl = vl + SIN(distance(x, y, 192, 100) / 8)
  19.             clr = 255 / (1.00001 * ABS(vl))
  20.             r = .9 * ABS(clr - dr): g = .4 * ABS(clr - dg): b = .5 * ABS(clr - db)
  21.             'COLOR r, g, b
  22.             'dot x, y
  23.             PSET (x, y), _RGB32(r, g, b)
  24.         NEXT
  25.     NEXT
  26.     IF w > 1000 OR w < -1000 THEN w = 0: d = d * -1
  27.     _DISPLAY
  28.     _LIMIT 200
  29. FUNCTION distance (x1, y1, x2, y2) '//between two points x1,y1 and x2,y2
  30.     distance = ((x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ .5
  31. FUNCTION ran% (sing)
  32.     ran% = INT(RND * sing) + 1
  33.  
  34.  
Title: Re: Ectoplasm
Post by: SierraKen on June 22, 2019, 10:33:14 pm
Way cool! I wish I kept all the programs I used to mess with in the 90's. The old newsgroup comp.lang.basic.misc used to punch out around one a day.
Title: Re: Ectoplasm
Post by: Ashish on June 23, 2019, 12:34:32 am
Cool bplus!
Title: Re: Ectoplasm
Post by: Petr on June 23, 2019, 05:59:48 am
Hi BPlus, again nice work. Just for my curiosity i try making it faster and then... compiling it under 1.3 and under 0.978.... Look  yourself to the speed diference.

Source, which is used for this test is attached.

Code: QB64: [Select]
  1. _TITLE "Ectoplasm" 'mod of Galileo's at Retro 2019-06-22 B+
  2. 'open window 256, 256
  3. SCREEN _NEWIMAGE(256, 256, 32)
  4. DIM m AS _MEM, x AS SINGLE, y AS SINGLE, vl AS SINGLE, r AS SINGLE, clr AS SINGLE, klr AS _UNSIGNED LONG, tm AS SINGLE, dr AS SINGLE, dg AS SINGLE, db AS SINGLE, w AS SINGLE, sh AS SINGLE, sw AS SINGLE
  5. m = _MEMIMAGE(0)
  6.  
  7. 'sh=peek("winheight")
  8. sh = _HEIGHT - 1
  9. 'sw=peek("winwidth")
  10. sw = _WIDTH - 1
  11. d = 1
  12.     'tm = peek("secondsrunning")
  13.     tm = TIMER(.001)
  14.     dr = ran(256): dg = ran(256): db = ran(256)
  15.     w = w + 5 / 83 '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< get things moving
  16.     REDIM scr(255, 255) AS _UNSIGNED LONG
  17.     FOR y = 0 TO sh
  18.         FOR x = 0 TO sw
  19.             vl = SIN(distance(x + tm, y, 128, 128) / 8 + w)
  20.             vl = vl + SIN(distance(x, y, 64, 64) / 8)
  21.             vl = vl + SIN(distance(x, y + tm / 7, 192, 64) / 7)
  22.             vl = vl + SIN(distance(x, y, 192, 100) / 8)
  23.             clr = 255 / (1.00001 * ABS(vl))
  24.             r = .9 * ABS(clr - dr): g = .4 * ABS(clr - dg): b = .5 * ABS(clr - db)
  25.             'COLOR r, g, b
  26.             'dot x, y
  27.             '     PSET (x, y), _RGB32(r, g, b)
  28.             klr~& = _RGB32(r, g, b)
  29.             scr(x, y) = klr~&
  30.         NEXT
  31.     NEXT
  32.     IF w > 1000 OR w < -1000 THEN w = 0: d = d * -1
  33.     _MEMPUT m, m.OFFSET, scr()
  34.  
  35.     ' _DISPLAY
  36.     ' _LIMIT 200
  37.  
  38.  
  39. FUNCTION distance (x1, y1, x2, y2) '//between two points x1,y1 and x2,y2
  40.     distance = ((x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ .5
  41. FUNCTION ran% (sing)
  42.     ran% = INT(RND * sing) + 1
  43.  
  44.  
  45.  
Title: Re: Ectoplasm
Post by: bplus on June 23, 2019, 08:22:29 am
Hi Petr,

What is .978 an older version of QB64?

I am not seeing any great difference between two codes on my system?? Both give the fan a workout, maybe a little less with yours, Petr.

BTW this not really my work, I added w to get the stuff to move and fiddled with numbers until I got the cool glowing white effect.
Title: Re: Ectoplasm
Post by: Petr on June 23, 2019, 08:35:46 am
Hi, yeah, it's an older version of QB64. Apparently, it didn't have such a so big bug tracking in the compiled C code, so it goes a quarter faster in the old version. Maybe it will compare when a newer version comes out after RhoSigma's $CHECKING OFF upgrade.  I talk about https://www.qb64.org/forum/index.php?topic=1348.0, so maybe then is 1.3 faster than old version.
Title: Re: Ectoplasm
Post by: johnno56 on June 23, 2019, 09:15:50 am
Cool demo... I stared at it for several minutes, just to see if it would mess up my eyesight, nothing. It didn't even effect me effect me....
Title: Re: Ectoplasm
Post by: FellippeHeitor on June 23, 2019, 09:28:35 am
This is gorgeous! All these plasma effects with minimal lines have always puzzled me as I have no idea what's going on behind all the math. It just makes it more magical to me after all.

I stared at it for several minutes, just to see if it would mess up my eyesight

What did I just read, johnno56? 🤣
Title: Re: Ectoplasm
Post by: johnno56 on June 23, 2019, 09:47:30 am
... at least 'you' can still read... lol
Title: Re: Ectoplasm
Post by: TempodiBasic on June 23, 2019, 02:06:53 pm
Yeah
I can say Cool for your plasma!
Sorry but my first thought was this https://en.wikipedia.org/wiki/Blood_plasma#/media/File:FreshFrozenPlasma.JPG (https://en.wikipedia.org/wiki/Blood_plasma#/media/File:FreshFrozenPlasma.JPG) and it seems so different from those showed by code of Bplus and by code of Petr.
Thanks to you I have seen cool graphics and I have learned that also in english plasma word can have three different meanings https://www.vocabulary.com/dictionary/plasma (https://www.vocabulary.com/dictionary/plasma)

Here over the programming there are exchanges of culture! Very Cool!
Title: Re: Ectoplasm
Post by: bplus on June 23, 2019, 02:21:51 pm
Hi TempodiBasic,

Here is another definition for ectoplasm:
Quote
a supernatural viscous substance that is supposed to exude from the body of a medium during a spiritualistic trance and form the material for the manifestation of spirits.

Title: Re: Ectoplasm
Post by: TempodiBasic on June 23, 2019, 02:32:56 pm
Hey Bplus
you're right but Spiritismhttps://en.wikipedia.org/wiki/Spiritism (https://en.wikipedia.org/wiki/Spiritism) was cool in the 1900 (or before it?) and Gosthbusters is in the 1980 https://en.wikipedia.org/wiki/Ghostbusters (https://en.wikipedia.org/wiki/Ghostbusters). To what ectoplasm  do you refer between these two last?
Title: Re: Ectoplasm
Post by: bplus on June 23, 2019, 02:35:02 pm
Hey Bplus
you're right but Spiritismhttps://en.wikipedia.org/wiki/Spiritism (https://en.wikipedia.org/wiki/Spiritism) was cool in the 1900 (or before it?) and Gosthbusters is in the 1980 https://en.wikipedia.org/wiki/Ghostbusters (https://en.wikipedia.org/wiki/Ghostbusters). To what ectoplasm  do you refer between these two last?

The sticky slimy stuff of ghosts.
https://www.google.com/search?q=ghostbusters+ectoplasm+scenes&client=opera&hs=7T&tbm=isch&source=iu&ictx=1&fir=IRPWtw7nxF88HM%253A%252C7qaTnyEoRUcYVM%252C_&vet=1&usg=AI4_-kQM1iU-ldpGGFNrO7q7vv5GLcg21g&sa=X&ved=2ahUKEwiz3YDOn4DjAhUPAZ0JHfjECQgQ9QEwC3oECAMQBA#imgrc=_&vet=1
Title: Re: Ectoplasm
Post by: TempodiBasic on June 23, 2019, 06:51:31 pm
Yep
It's my preferite
https://ghostbusters.fandom.com/wiki/Ectoplasm (https://ghostbusters.fandom.com/wiki/Ectoplasm)
Title: Re: Ectoplasm
Post by: _vince on June 28, 2019, 08:03:03 pm
This is gorgeous! All these plasma effects with minimal lines have always puzzled me as I have no idea what's going on behind all the math. It just makes it more magical to me after all.

Lovely article here:  http://www.petesqbsite.com/sections/tutorials/zines/qbcm/17-plasmas.html (http://www.petesqbsite.com/sections/tutorials/zines/qbcm/17-plasmas.html)
Title: Re: Ectoplasm
Post by: OldMoses on July 01, 2019, 07:02:51 am
Ghosts are inconvenient enough without leaving spooge lying around. ;)

That is really cool and I gotta wonder how you come up with these effects. Do you have a process or do you just throw stuff at the IDE until something wild occurs?

I used to random POKE random values into my Apple II to see what strange things might happen...
Title: Re: Ectoplasm
Post by: bplus on July 01, 2019, 10:38:12 am
Ghosts are inconvenient enough without leaving spooge lying around. ;)

That is really cool and I gotta wonder how you come up with these effects. Do you have a process or do you just throw stuff at the IDE until something wild occurs?

I used to random POKE random values into my Apple II to see what strange things might happen...

The plasm effect is old trick, see _vince link in reply #14 of this thread.

I used it here: https://www.qb64.org/forum/index.php?topic=1467.msg106723#msg106723
 


for the background rolling waves of beautiful color:
Code: QB64: [Select]
  1.     'instead of CLS create rolling waves of color patterns
  2.     FOR i = 0 TO xmax
  3.         chColor
  4.         LINE (i, 0)-(i, ymax)
  5.     NEXT
  6.     ....
  7.  
  8. SUB chColor ()
  9.     IF r = 0 THEN r = RND * 255
  10.     IF g = 0 THEN g = RND * 255
  11.     IF b = 0 THEN b = RND * 255
  12.     clr = clr + .3
  13.     COLOR _RGB32(127 + 127 * SIN(r * clr), 127 + 127 * SIN(g * clr), 127 + 127 * SIN(b * clr))
  14.     IF clr > 40000 THEN r = RND: g = RND: b = RND: clr = 0
  15.  

I see Ashish is onto it here:
https://www.qb64.org/forum/index.php?topic=1472.msg106736#msg106736
Oh, maybe that's just random color... I thought I saw repeating patterns like here:
Code: QB64: [Select]
  1. _TITLE "Wavy with Plama:  Press Spacebar for New Plasma Injection."
  2. ' for QB64 fork (B+=MGA) 2017-05-05
  3. ' Wavy with Plasma Treatment.bas SmallBASIC 0.12.9 (B+=MGA) 2017-05-03
  4. ' from: animated circles started by Admin at SdlBasic 2017-05-03
  5. ' I added Plasma treatment and spacebar  changer
  6.  
  7. ' 2018-08-04 updated with better circle fill
  8.  
  9. '===================================================================
  10.  
  11. ' Instructions: press spacebar for new injection of plasma
  12.  
  13. '==================================================================
  14.  
  15.  
  16. CONST xmax = 1100
  17. CONST ymax = 700
  18. CONST DPI = 3.141516 * 2
  19. CONST PHIDELTA = DPI / 15
  20. CONST PHISTEP = DPI / 50
  21. CONST RADIUS = 20
  22. CONST SMALL_R = 20
  23. CONST DISTANCE = 23
  24. CONST W = xmax
  25. CONST H = ymax
  26.  
  27. SCREEN _NEWIMAGE(xmax, ymax, 32)
  28. _SCREENMOVE (1280 - xmax) / 2 + 30, (760 - ymax) / 2
  29. DIM SHARED pR, pG, pB AS INTEGER
  30. DIM x, y, xball, yball AS INTEGER
  31. DIM current_phi, phiIndex, phi AS DOUBLE
  32. current_phi = 0
  33. cN = 1
  34. resetPlasma
  35.     CLS
  36.     _LIMIT 10
  37.     IF _KEYHIT = 32 THEN cN = 1: resetPlasma
  38.     current_phi = current_phi + PHISTEP
  39.     FOR x = 0 TO (W + RADIUS) STEP DISTANCE
  40.         FOR y = 0 TO (H + RADIUS) STEP DISTANCE
  41.             phiIndex = ((x + y) MOD (2 * W)) / RADIUS
  42.             phi = phiIndex * PHIDELTA + current_phi
  43.             xball = COS(phi) * RADIUS + x
  44.             yball = SIN(phi) * RADIUS + y
  45.             changePlasma
  46.             fcirc xball, yball, SMALL_R
  47.         NEXT
  48.     NEXT
  49.     _DISPLAY
  50.  
  51. SUB changePlasma ()
  52.     cN = cN + 1
  53.     COLOR _RGB(127 + 127 * SIN(pR * cN), 127 + 127 * SIN(pG * cN), 127 + 127 * SIN(pB * cN))
  54.  
  55. SUB resetPlasma ()
  56.     pR = RND: pG = RND: pB = RND
  57.  
  58. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  59. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  60.     DIM subRadius AS LONG, RadiusError AS LONG
  61.     DIM X AS LONG, Y AS LONG
  62.  
  63.     subRadius = ABS(R)
  64.     RadiusError = -subRadius
  65.     X = subRadius
  66.     Y = 0
  67.  
  68.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  69.  
  70.     ' Draw the middle span here so we don't draw it twice in the main loop,
  71.     ' which would be a problem with blending turned on.
  72.     LINE (CX - X, CY)-(CX + X, CY), , BF
  73.  
  74.     WHILE X > Y
  75.         RadiusError = RadiusError + Y * 2 + 1
  76.         IF RadiusError >= 0 THEN
  77.             IF X <> Y + 1 THEN
  78.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  79.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  80.             END IF
  81.             X = X - 1
  82.             RadiusError = RadiusError - X * 2
  83.         END IF
  84.         Y = Y + 1
  85.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  86.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  87.     WEND
  88.  
Title: Re: Ectoplasm
Post by: bplus on January 20, 2020, 10:38:17 pm
I have just worked up a better version of Ectoplasm which I am calling Plasmatic:
Code: QB64: [Select]
  1. _TITLE "Plasmatic  press spacebar for new coloring set" ' b+ 2020-01-20 translated and modified from SmallBASIC
  2. 'Plasma Magnifico - updated 2015-11-26 for Android
  3. 'This program creates a plasma surface, which looks oily or silky.
  4.  
  5. CONST xmax = 800, ymax = 600
  6. TYPE xy
  7.     x AS SINGLE
  8.     y AS SINGLE
  9.     dx AS SINGLE
  10.     dy AS SINGLE
  11. SCREEN _NEWIMAGE(xmax, ymax, 32)
  12. _SCREENMOVE 300, 40
  13.  
  14. DIM c(360) AS _UNSIGNED LONG, p(6) AS xy, f(6)
  15. restart:
  16. r = RND: g = RND: b = RND: i = 0
  17. FOR n = 1 TO 5
  18.     r1 = r: g1 = g: b1 = b
  19.     DO: r = RND: LOOP UNTIL ABS(r - r1) > .2
  20.     DO: g = RND: LOOP UNTIL ABS(g - g1) > .2
  21.     DO: b = RND: LOOP UNTIL ABS(g - g1) > .2
  22.     FOR m = 0 TO 17: m1 = 17 - m
  23.         f1 = (m * r) / 18: f2 = (m * g) / 18: f3 = (m * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  24.     NEXT
  25.     FOR m = 0 TO 17: m1 = 17 - m
  26.         f1 = (m + m1 * r) / 18: f2 = (m + m1 * g) / 18: f3 = (m + m1 * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  27.     NEXT
  28.     FOR m = 0 TO 17: m1 = 17 - m
  29.         f1 = (m1 + m * r) / 18: f2 = (m1 + m * g) / 18: f3 = (m1 + m * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  30.     NEXT
  31.     FOR m = 0 TO 17: m1 = 17 - m
  32.         f1 = (m1 * r) / 18: f2 = (m1 * g) / 18: f3 = (m1 * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  33.     NEXT
  34.  
  35. FOR n = 0 TO 5
  36.     p(n).x = RND * xmax: p(n).y = RND * ymax: p(n).dx = RND * 2 - 1: p(n).dy = RND * 2 - 1
  37.     f(n) = RND * .1
  38.  
  39. WHILE _KEYDOWN(27) = 0
  40.     IF INKEY$ = " " THEN GOTO restart
  41.     FOR i = 0 TO 5
  42.         p(i).x = p(i).x + p(i).dx
  43.         IF p(i).x > xmax OR p(i).x < 0 THEN p(i).dx = -p(i).dx
  44.         p(i).y = p(i).y + p(i).dy
  45.         IF p(i).y > ymax OR p(i).y < 0 THEN p(i).dy = -p(i).dy
  46.     NEXT
  47.     FOR y = 0 TO ymax - 1 STEP 2
  48.         FOR x = 0 TO xmax - 1 STEP 2
  49.             d = 0
  50.             FOR n = 0 TO 5
  51.                 dx = x - p(n).x: dy = y - p(n).y
  52.                 k = SQR(dx * dx + dy * dy)
  53.                 d = d + (SIN(k * f(n)) + 1) / 2
  54.             NEXT n: d = d * 60
  55.             LINE (x, y)-STEP(2, 2), c(d), BF
  56.         NEXT
  57.     NEXT
  58.     _DISPLAY
  59.     _LIMIT 100
  60.  
  61. FUNCTION rgbf~& (n1, n2, n3)
  62.     rgbf~& = _RGB32(n1 * 255, n2 * 255, n3 * 255)
  63.  

Richard Frost recent clock background reminded me of old SmallBASIC program but it drew one static picture at a time because not fast enough for motion. QB64 is, just barely.

Title: Re: Ectoplasm
Post by: bplus on January 21, 2020, 11:34:40 am
https://www.qb64.org/forum/index.php?topic=2102.15
Quote
@bplus, awesome plasma, like the 3D shader effect a lot. Does the pattern repeat after a while, or it is completley random/fractaloid? I don't know a lot about this kind of math.

Hi Dajan,

I hope you don't mind my answering here in thread where I've been working on this effect. I confess I don't quite get the math yet either.

The program I translated and modified looked like this (plasmajvsh.bas from SmallBASIC code library,
http://smallbasic.github.io/pages/samples.html
Code: [Select]
'Plasma generator
'This program creates a plasma surface, which looks oily or silky.

r=rnd:g=rnd:b=rnd
for n=1 to 5
   r1=r:g1=g:b1=b
   repeat:r=rnd:until abs(r-r1)>.3
   repeat:g=rnd:until abs(g-g1)>.3
   repeat:b=rnd:until abs(g-g1)>.3
   for m=0 to 17:m1=17-m
     f1=(m*r)/18:f2=(m*g)/18:f3=(m*b)/18:c << rgbf(f1,f2,f3)
   next
   for m=0 to 17:m1=17-m
     f1=(m+m1*r)/18:f2=(m+m1*g)/18:f3=(m+m1*b)/18:c << rgbf(f1,f2,f3)
   next
   for m=0 to 17:m1=17-m
     f1=(m1+m*r)/18:f2=(m1+m*g)/18:f3=(m1+m*b)/18:c << rgbf(f1,f2,f3)
   next
   for m=0 to 17:m1=17-m
     f1=(m1*r)/18:f2=(m1*g)/18:f3=(m1*b)/18:c << rgbf(f1,f2,f3)
   next
next

for n=1 to 6
   p << [rnd*xmax,rnd*ymax]
   f << rnd*.1
next n
for y=0 to ymax-1 step 2
   for x=0 to xmax-1 step 2
     d=0
     for n=0 to 5
       k=sqr((x-p(n)(0))^2+(y-p(n)(1))^2)
       d =d+(sin(k*f(n))+1)/2
     next n:d=d*60
     rect x,y step 2,2 color c(d) filled
   next x
next y

The first part generates a color palette c(), the 2nd block generates 6 random points  and the 3rd block draws a screen full of plasma colors based on distances from the 6 points.

When that program was made it did not go nearly as fast as it can now days with 64 bit processing so I had idea to show moving plasma by moving those 6 points around the screen:
Code: QB64: [Select]
  1.  
  2. 'points structure
  3. TYPE xy
  4.     x AS SINGLE
  5.     y AS SINGLE
  6.     dx AS SINGLE
  7.     dy AS SINGLE
  8.  
  9. ...
  10. 'new points startup
  11. FOR n = 0 TO 5
  12.     p(n).x = RND * xmax: p(n).y = RND * ymax: p(n).dx = RND * 2 - 1: p(n).dy = RND * 2 - 1
  13.     f(n) = RND * .1
  14. ...
  15. 'move points
  16. FOR i = 0 TO 5
  17.         p(i).x = p(i).x + p(i).dx
  18.         IF p(i).x > xmax OR p(i).x < 0 THEN p(i).dx = -p(i).dx
  19.         p(i).y = p(i).y + p(i).dy
  20.         IF p(i).y > ymax OR p(i).y < 0 THEN p(i).dy = -p(i).dy
  21.     NEXT
  22.  

The "shader" effect comes from the palette generation. Since the points are moving around on screen it is possible to repeat a pattern, that probablility is unlikely, how unlikely? Ask STxAxTIC it's crazy big math! ;-))

Notice "ectoplasm" the first post in this thread works on the same principle and I did half baked repeating method to move it around a bit.

But last night was the inspired real plasma effect!


 
Title: Re: Ectoplasm
Post by: dajan on January 21, 2020, 12:13:34 pm
@bplus, thanks for clarification, I'm not going to pretend I understood :o) anyway, the RND part tells me, there wouldn't be any regular pattern repeating.
Title: Re: Ectoplasm
Post by: STxAxTIC on January 21, 2020, 06:55:14 pm
I felt a tingle so I knew I was mentioned somewhere, in a good light, too! Must be a good day!

Anyway, this thread is awesome, these programs are super awesome. My system is kindof a hunk of junk so I narrowed the view area to make it really liquid. A+ stuff, bplus.
Title: Re: Ectoplasm
Post by: bplus on January 21, 2020, 07:13:55 pm
Thanks STxAxTIC, I wish I were originator but happy to pass along some old classic work, maybe in new light.
Title: Re: Ectoplasm
Post by: SierraKen on January 21, 2020, 10:30:59 pm
Plasmatic is incredible!!!! I been wanting to make something like this for months. The closest thing I got was my lava lamps. But I could never get the realism that you got here. Congratulations B+!
Also congratulations to the Small Basic programmer! Some people are just geniuses. :)
Title: Re: Ectoplasm
Post by: SierraKen on January 21, 2020, 11:19:08 pm
Here's my own version. I just changed 2 numbers, from 2 to 20 on the STEPs on the last loops of the program, and now it looks like TRON or when you look at one of those giant LED billboards from your vehicle at night on the freeway. Press the space bar to get different types as you did above.
I added a picture of it, but without the animation, it's not too close to how neat it looks in the program. You also have to click the picture to see it.
You also can swap 20 with 10 or whatever number you want to try. The larger the number, the more distance between pixels.

Code: QB64: [Select]
  1. _TITLE "Plasmatic  press spacebar for new coloring set" ' b+ 2020-01-20 translated and modified from SmallBASIC
  2. 'Plasma Magnifico - updated 2015-11-26 for Android
  3. 'This program creates a plasma surface, which looks oily or silky.
  4. 'Updated again by Ken G. for TRON-like visual.
  5.  
  6. CONST xmax = 800, ymax = 600
  7. TYPE xy
  8.     x AS SINGLE
  9.     y AS SINGLE
  10.     dx AS SINGLE
  11.     dy AS SINGLE
  12. SCREEN _NEWIMAGE(xmax, ymax, 32)
  13. _SCREENMOVE 300, 40
  14.  
  15. DIM c(360) AS _UNSIGNED LONG, p(6) AS xy, f(6)
  16. restart:
  17. r = RND: g = RND: b = RND: i = 0
  18. FOR n = 1 TO 5
  19.     r1 = r: g1 = g: b1 = b
  20.     DO: r = RND: LOOP UNTIL ABS(r - r1) > .2
  21.     DO: g = RND: LOOP UNTIL ABS(g - g1) > .2
  22.     DO: b = RND: LOOP UNTIL ABS(g - g1) > .2
  23.     FOR m = 0 TO 17: m1 = 17 - m
  24.         f1 = (m * r) / 18: f2 = (m * g) / 18: f3 = (m * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  25.     NEXT
  26.     FOR m = 0 TO 17: m1 = 17 - m
  27.         f1 = (m + m1 * r) / 18: f2 = (m + m1 * g) / 18: f3 = (m + m1 * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  28.     NEXT
  29.     FOR m = 0 TO 17: m1 = 17 - m
  30.         f1 = (m1 + m * r) / 18: f2 = (m1 + m * g) / 18: f3 = (m1 + m * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  31.     NEXT
  32.     FOR m = 0 TO 17: m1 = 17 - m
  33.         f1 = (m1 * r) / 18: f2 = (m1 * g) / 18: f3 = (m1 * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  34.     NEXT
  35.  
  36. FOR n = 0 TO 5
  37.     p(n).x = RND * xmax: p(n).y = RND * ymax: p(n).dx = RND * 2 - 1: p(n).dy = RND * 2 - 1
  38.     f(n) = RND * .1
  39.  
  40. WHILE _KEYDOWN(27) = 0
  41.     IF INKEY$ = " " THEN GOTO restart
  42.     FOR i = 0 TO 5
  43.         p(i).x = p(i).x + p(i).dx
  44.         IF p(i).x > xmax OR p(i).x < 0 THEN p(i).dx = -p(i).dx
  45.         p(i).y = p(i).y + p(i).dy
  46.         IF p(i).y > ymax OR p(i).y < 0 THEN p(i).dy = -p(i).dy
  47.     NEXT
  48.  
  49.     'FOR y = 0 TO ymax - 1 STEP 2
  50.     'FOR x = 0 TO xmax - 1 STEP 2
  51.     FOR y = 0 TO ymax - 1 STEP 20
  52.         FOR x = 0 TO xmax - 1 STEP 20
  53.             d = 0
  54.             FOR n = 0 TO 5
  55.                 dx = x - p(n).x: dy = y - p(n).y
  56.                 k = SQR(dx * dx + dy * dy)
  57.                 d = d + (SIN(k * f(n)) + 1) / 2
  58.             NEXT n: d = d * 60
  59.             LINE (x, y)-STEP(2, 2), c(d), BF
  60.         NEXT
  61.     NEXT
  62.     _DISPLAY
  63.    _LIMIT 100
  64.  
  65. FUNCTION rgbf~& (n1, n2, n3)
  66.     rgbf~& = _RGB32(n1 * 255, n2 * 255, n3 * 255)
  67.  
  68.  
Title: Re: Ectoplasm
Post by: bplus on January 22, 2020, 11:13:08 am
Thanks Ken, interesting :)

You can learn many things by jiggling the numbers, you know that I am sure.

Here is a mod that jiggles the number of moving points by resetting the constant nPoints in bas source, near top of code:
Code: QB64: [Select]
  1. _TITLE "Plasmatic nPoints Test Mod, press spacebar for new color set" 'b+ 2020-01-22
  2. ' from Plasmatic  press spacebar for new coloring set" ' b+ 2020-01-20 translated and modified from SmallBASIC
  3. 'Plasma Magnifico - updated 2015-11-26 for Android
  4. 'This program creates a plasma surface, which looks oily or silky.
  5.  
  6. CONST xmax = 800, ymax = 600, nPoints = 1 '<<<<<<<<<<<<<<<<<< use 1 to 8 after 8 it runs too slow to enjoy most interesting is 1 or 2
  7. TYPE xy
  8.     x AS SINGLE
  9.     y AS SINGLE
  10.     dx AS SINGLE
  11.     dy AS SINGLE
  12. SCREEN _NEWIMAGE(xmax, ymax, 32)
  13. _SCREENMOVE 300, 40
  14.  
  15. DIM c((nPoints + 1) * 80) AS _UNSIGNED LONG, p(nPoints) AS xy, f(nPoints)
  16. restart:
  17. r = RND: g = RND: b = RND: i = 0
  18. FOR n = 1 TO nPoints
  19.     r1 = r: g1 = g: b1 = b
  20.     DO: r = RND: LOOP UNTIL ABS(r - r1) > .2
  21.     DO: g = RND: LOOP UNTIL ABS(g - g1) > .2
  22.     DO: b = RND: LOOP UNTIL ABS(g - g1) > .2
  23.     FOR m = 0 TO 17: m1 = 17 - m
  24.         f1 = (m * r) / 18: f2 = (m * g) / 18: f3 = (m * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  25.     NEXT
  26.     FOR m = 0 TO 17: m1 = 17 - m
  27.         f1 = (m + m1 * r) / 18: f2 = (m + m1 * g) / 18: f3 = (m + m1 * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  28.     NEXT
  29.     FOR m = 0 TO 17: m1 = 17 - m
  30.         f1 = (m1 + m * r) / 18: f2 = (m1 + m * g) / 18: f3 = (m1 + m * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  31.     NEXT
  32.     FOR m = 0 TO 17: m1 = 17 - m
  33.         f1 = (m1 * r) / 18: f2 = (m1 * g) / 18: f3 = (m1 * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  34.     NEXT
  35.  
  36. FOR n = 0 TO nPoints
  37.     p(n).x = RND * xmax: p(n).y = RND * ymax: p(n).dx = RND * 2 - 1: p(n).dy = RND * 2 - 1
  38.     f(n) = RND * .1
  39.  
  40. WHILE _KEYDOWN(27) = 0
  41.     IF INKEY$ = " " THEN GOTO restart
  42.     FOR i = 0 TO nPoints
  43.         p(i).x = p(i).x + p(i).dx
  44.         IF p(i).x > xmax OR p(i).x < 0 THEN p(i).dx = -p(i).dx
  45.         p(i).y = p(i).y + p(i).dy
  46.         IF p(i).y > ymax OR p(i).y < 0 THEN p(i).dy = -p(i).dy
  47.     NEXT
  48.  
  49.     FOR y = 0 TO ymax - 1 STEP 2
  50.         FOR x = 0 TO xmax - 1 STEP 2
  51.             d = 0
  52.             FOR n = 0 TO nPoints
  53.                 dx = x - p(n).x: dy = y - p(n).y
  54.                 k = SQR(dx * dx + dy * dy)
  55.                 d = d + (SIN(k * f(n)) + 1) / 2
  56.             NEXT n: d = d * 60
  57.             LINE (x, y)-STEP(2, 2), c(d), BF
  58.         NEXT
  59.     NEXT
  60.     _DISPLAY
  61.     _LIMIT 100
  62.  
  63. FUNCTION rgbf~& (n1, n2, n3)
  64.     rgbf~& = _RGB32(n1 * 255, n2 * 255, n3 * 255)
  65.  
  66.  

EDIT: although I can't see much difference, line 46 was not supposed to be  FROM 0 to 1.
Title: Re: Ectoplasm
Post by: SierraKen on January 22, 2020, 12:26:01 pm
That's really awesome! I'll have to study it a bit more to learn from. I'm surprised there's no DELAY command or anything to slow it down. I tried to speed it up with a higher LIMIT number but that didn't do anything. I wonder why it's set on that speed?
Title: Re: Ectoplasm
Post by: bplus on January 22, 2020, 02:42:44 pm
That's really awesome! I'll have to study it a bit more to learn from. I'm surprised there's no DELAY command or anything to slow it down. I tried to speed it up with a higher LIMIT number but that didn't do anything. I wonder why it's set on that speed?

_LIMIT does what I underlined above, it will delay code on a regular interval making it flow nicely at even level but only if the code is processed faster than the _LIMIT amount.

_LIMIT is not needed for stepping through this code at steps of 1 or 2 at the screen size 800 x 600 but decrease screen, or increase step size to like 20 or jiggle some other number and _LIMIT 100 (or 60) would be needed for smooth flow.

Title: Re: Ectoplasm
Post by: SierraKen on January 22, 2020, 04:15:28 pm
That makes sense, but I wonder why it's impossible to make this program go any faster?
Title: Re: Ectoplasm
Post by: bplus on January 22, 2020, 05:30:34 pm
That makes sense, but I wonder why it's impossible to make this program go any faster?

Oh this can be made to go faster, along with big steps, smaller screens, less points, ask Steve or RhoSigma for all kinds of optimizing and mem tricks and compile NoChecking...
The real bottleneck is checking the distance of every point on screen to 6 or how many points we are using for the plasma coloring number get around using SQR.
Title: Re: Ectoplasm
Post by: bplus on January 22, 2020, 11:24:19 pm
The dance of 3 equally weighted points (located by yellow dots) of fairly small globular size:
I am jiggling the f factor!

Code: QB64: [Select]
  1. _TITLE "Plasmatic 3 Points Test Mod, press spacebar for new color set" 'b+ 2020-01-22
  2. ' from Plasmatic nPoints Test Mod.bas 2020-01-22
  3. ' from Plasmatic  press spacebar for new coloring set" ' b+ 2020-01-20 translated and modified from SmallBASIC
  4. 'Plasma Magnifico - updated 2015-11-26 for Android
  5. 'This program creates a plasma surface, which looks oily or silky.
  6. '==================================================================================================================
  7. '
  8. '                          Experiments with ordered set of points, can we tell the pattern underneath?
  9. '
  10. '==================================================================================================================
  11.  
  12. CONST xmax = 800, ymax = 600, nPoints = 3
  13. TYPE xy
  14.     x AS SINGLE
  15.     y AS SINGLE
  16.     dx AS SINGLE
  17.     dy AS SINGLE
  18. SCREEN _NEWIMAGE(xmax, ymax, 32)
  19. _SCREENMOVE 300, 40
  20.  
  21. DIM c((nPoints + 1) * 80) AS _UNSIGNED LONG, p(1 TO nPoints) AS xy, f(1 TO nPoints), cc AS _UNSIGNED LONG
  22. restart:
  23. r = RND: g = RND: b = RND: i = 0
  24. FOR n = 1 TO nPoints
  25.     r1 = r: g1 = g: b1 = b
  26.     DO: r = RND: LOOP UNTIL ABS(r - r1) > .2
  27.     DO: g = RND: LOOP UNTIL ABS(g - g1) > .2
  28.     DO: b = RND: LOOP UNTIL ABS(g - g1) > .2
  29.     FOR m = 0 TO 17: m1 = 17 - m
  30.         f1 = (m * r) / 18: f2 = (m * g) / 18: f3 = (m * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  31.     NEXT
  32.     FOR m = 0 TO 17: m1 = 17 - m
  33.         f1 = (m + m1 * r) / 18: f2 = (m + m1 * g) / 18: f3 = (m + m1 * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  34.     NEXT
  35.     FOR m = 0 TO 17: m1 = 17 - m
  36.         f1 = (m1 + m * r) / 18: f2 = (m1 + m * g) / 18: f3 = (m1 + m * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  37.     NEXT
  38.     FOR m = 0 TO 17: m1 = 17 - m
  39.         f1 = (m1 * r) / 18: f2 = (m1 * g) / 18: f3 = (m1 * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  40.     NEXT
  41.  
  42. FOR n = 1 TO nPoints
  43.     p(n).x = RND * xmax: p(n).y = RND * ymax: p(n).dx = 5 * (RND * 2 - 1): p(n).dy = 5 * (RND * 2 - 1)
  44.     f(n) = .2
  45.  
  46. WHILE _KEYDOWN(27) = 0
  47.     IF INKEY$ = " " THEN GOTO restart
  48.     ca = ca + da
  49.     FOR i = 1 TO nPoints
  50.         p(i).x = p(i).x + p(i).dx
  51.         p(i).y = p(i).y + p(i).dy
  52.         IF p(i).x < 0 OR p(i).x > xmax THEN p(i).dx = -p(i).dx
  53.         IF p(i).y < 0 OR p(i).y > ymax THEN p(i).dy = -p(i).dy
  54.     NEXT
  55.  
  56.     FOR y = 0 TO ymax - 1 STEP 2
  57.         FOR x = 0 TO xmax - 1 STEP 2
  58.             d = 0
  59.             FOR n = 1 TO nPoints
  60.                 dx = x - p(n).x: dy = y - p(n).y
  61.                 k = SQR(dx * dx + dy * dy)
  62.                 d = d + (SIN(k * f(n)) + 1) / 2
  63.             NEXT n: d = d * 60
  64.             LINE (x, y)-STEP(2, 2), c(d), BF
  65.         NEXT
  66.     NEXT
  67.     FOR i = 1 TO nPoints
  68.         FOR rd = 0 TO 10 STEP .25
  69.             CIRCLE (p(i).x, p(i).y), rd, &HFFFFFF00
  70.         NEXT
  71.     NEXT
  72.     _DISPLAY
  73.     _LIMIT 30
  74.  
  75. FUNCTION rgbf~& (n1, n2, n3)
  76.     rgbf~& = _RGB32(n1 * 255, n2 * 255, n3 * 255)
  77.  
  78.  
Title: Re: Ectoplasm
Post by: SierraKen on January 23, 2020, 12:31:21 am
Pretty cool B+! I changed the F number to .05  and all the set loops to 2 so now it goes a bit faster and looks like blobs in a lava lamp. :D So I also changed the window shape to that more of like a lava lamp, a rectangle. Press the space bar a bunch of times and this is SOOO COOL! I just wish I knew the math in it. :)

Code: QB64: [Select]
  1. 'Lava Lamp modified by Ken G. and from b+ and from SmallBASIC.
  2. _TITLE "press spacebar" ' b+ 2020-01-20 translated and modified from SmallBASIC
  3. 'Plasma Magnifico - updated 2015-11-26 for Android
  4. 'This program creates a plasma surface, which looks oily or silky.
  5.  
  6. CONST xmax = 250, ymax = 600
  7. TYPE xy
  8.     x AS SINGLE
  9.     y AS SINGLE
  10.     dx AS SINGLE
  11.     dy AS SINGLE
  12. SCREEN _NEWIMAGE(xmax, ymax, 32)
  13. _SCREENMOVE 300, 40
  14.  
  15. DIM c(360) AS _UNSIGNED LONG, p(6) AS xy, f(6)
  16. restart:
  17. r = RND: g = RND: b = RND: i = 0
  18. FOR n = 1 TO 2
  19.     r1 = r: g1 = g: b1 = b
  20.     DO: r = RND: LOOP UNTIL ABS(r - r1) > .2
  21.     DO: g = RND: LOOP UNTIL ABS(g - g1) > .2
  22.     DO: b = RND: LOOP UNTIL ABS(g - g1) > .2
  23.     FOR m = 0 TO 17: m1 = 17 - m
  24.         f1 = (m * r) / 18: f2 = (m * g) / 18: f3 = (m * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  25.     NEXT
  26.     FOR m = 0 TO 17: m1 = 17 - m
  27.         f1 = (m + m1 * r) / 18: f2 = (m + m1 * g) / 18: f3 = (m + m1 * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  28.     NEXT
  29.     FOR m = 0 TO 17: m1 = 17 - m
  30.         f1 = (m1 + m * r) / 18: f2 = (m1 + m * g) / 18: f3 = (m1 + m * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  31.     NEXT
  32.     FOR m = 0 TO 17: m1 = 17 - m
  33.         f1 = (m1 * r) / 18: f2 = (m1 * g) / 18: f3 = (m1 * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  34.     NEXT
  35.  
  36. FOR n = 0 TO 2
  37.     p(n).x = RND * xmax: p(n).y = RND * ymax: p(n).dx = RND * 2 - 1: p(n).dy = RND * 2 - 1
  38.     f(n) = RND * .05
  39.  
  40. WHILE _KEYDOWN(27) = 0
  41.     IF INKEY$ = " " THEN GOTO restart
  42.     FOR i = 0 TO 2
  43.         p(i).x = p(i).x + p(i).dx
  44.         IF p(i).x > xmax OR p(i).x < 0 THEN p(i).dx = -p(i).dx
  45.         p(i).y = p(i).y + p(i).dy
  46.         IF p(i).y > ymax OR p(i).y < 0 THEN p(i).dy = -p(i).dy
  47.     NEXT
  48.     FOR y = 0 TO ymax - 1 STEP 2
  49.         FOR x = 0 TO xmax - 1 STEP 2
  50.             d = 0
  51.             FOR n = 0 TO 2
  52.                 dx = x - p(n).x: dy = y - p(n).y
  53.                 k = SQR(dx * dx + dy * dy)
  54.                 d = d + (SIN(k * f(n)) + 1) / 2
  55.             NEXT n: d = d * 60
  56.             LINE (x, y)-STEP(2, 2), c(d), BF
  57.         NEXT
  58.     NEXT
  59.     _DISPLAY
  60.     _LIMIT 100
  61.  
  62. FUNCTION rgbf~& (n1, n2, n3)
  63.     rgbf~& = _RGB32(n1 * 255, n2 * 255, n3 * 255)
  64.  
Title: Re: Ectoplasm
Post by: bplus on January 23, 2020, 01:35:11 am
Here is my mod of your mod for Lava Lamp
Code: QB64: [Select]
  1. 'Lava Lamp modified by Ken G. and from b+ and from SmallBASIC.   mod again B+
  2. _TITLE "press spacebar" ' b+ 2020-01-20 translated and modified from SmallBASIC
  3. 'Plasma Magnifico - updated 2015-11-26 for Android
  4. 'This program creates a plasma surface, which looks oily or silky.
  5.  
  6. CONST xmax = 250, ymax = 600
  7. TYPE xy
  8.     x AS SINGLE
  9.     y AS SINGLE
  10.     dx AS SINGLE
  11.     dy AS SINGLE
  12. SCREEN _NEWIMAGE(xmax, ymax, 32)
  13. _SCREENMOVE 300, 40
  14.  
  15. DIM c(360) AS _UNSIGNED LONG, p(6) AS xy, f(6)
  16.  
  17. restart:
  18. r = RND: g = RND: b = RND: i = 0
  19. FOR n = 1 TO 2
  20.     r1 = r: g1 = g: b1 = b
  21.     DO: r = RND: LOOP UNTIL ABS(r - r1) > .2
  22.     DO: g = RND: LOOP UNTIL ABS(g - g1) > .2
  23.     DO: b = RND: LOOP UNTIL ABS(g - g1) > .2
  24.     FOR m = 0 TO 17: m1 = 17 - m
  25.         f1 = (m * r) / 18: f2 = (m * g) / 18: f3 = (m * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  26.     NEXT
  27.     FOR m = 0 TO 17: m1 = 17 - m
  28.         f1 = (m + m1 * r) / 18: f2 = (m + m1 * g) / 18: f3 = (m + m1 * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  29.     NEXT
  30.     FOR m = 0 TO 17: m1 = 17 - m
  31.         f1 = (m1 + m * r) / 18: f2 = (m1 + m * g) / 18: f3 = (m1 + m * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  32.     NEXT
  33.     FOR m = 0 TO 17: m1 = 17 - m
  34.         f1 = (m1 * r) / 18: f2 = (m1 * g) / 18: f3 = (m1 * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  35.     NEXT
  36.  
  37. FOR n = 0 TO 2
  38.     p(n).x = RND * xmax: p(n).y = RND * ymax: p(n).dx = .25 * (RND * 2 - 1): p(n).dy = 2 * (RND * 2 - 1)
  39.     f(n) = .015
  40.  
  41. WHILE _KEYDOWN(27) = 0
  42.     CLS
  43.     IF INKEY$ = " " THEN GOTO restart
  44.     FOR i = 0 TO 2
  45.         p(i).x = p(i).x + p(i).dx
  46.         IF p(i).x > xmax - 50 OR p(i).x < 50 THEN p(i).dx = -p(i).dx
  47.         p(i).y = p(i).y + p(i).dy
  48.         IF p(i).y > ymax + 100 OR p(i).y < -100 THEN p(i).dy = -p(i).dy
  49.     NEXT
  50.     FOR y = 0 TO ymax - 1 STEP 2
  51.         FOR x = 0 TO xmax - 1 STEP 2
  52.             d = 0
  53.             FOR n = 0 TO 2
  54.                 dx = x - p(n).x: dy = y - p(n).y
  55.                 k = SQR(dx * dx + dy * dy)
  56.                 d = d + (SIN(k * f(n)) + 1) / 2
  57.             NEXT n: d = d * 60
  58.             LINE (x, y)-STEP(2, 2), c(d), BF
  59.         NEXT
  60.     NEXT
  61.     _DISPLAY
  62.     _LIMIT 20
  63.  
  64. FUNCTION rgbf~& (n1, n2, n3)
  65.     rgbf~& = _RGB32(n1 * 255, n2 * 255, n3 * 255)
  66.  
  67.  
  68.  

Title: Re: Ectoplasm
Post by: SierraKen on January 23, 2020, 01:36:52 pm
Great job B+! Looks just like a lava lamp now pretty much.
Title: Re: Ectoplasm
Post by: bplus on January 23, 2020, 05:23:06 pm
OK I have studied the code for palette creation and can simplify the job immensely!

Code: QB64: [Select]
  1. _TITLE "Color Mixing 4 Plasmatic" ' b+ 2020-01-23
  2. ' continued study of what makes Plasmatic tick, here the color pallete created
  3.  
  4. CONST xmax = 800, ymax = 720
  5. TYPE xy
  6.     x AS SINGLE
  7.     y AS SINGLE
  8.     dx AS SINGLE
  9.     dy AS SINGLE
  10. SCREEN _NEWIMAGE(xmax, ymax, 32)
  11. _SCREENMOVE 300, 10
  12.  
  13. DIM c(360) AS _UNSIGNED LONG, p(6) AS xy, f(6), i AS INTEGER, r AS INTEGER, g AS INTEGER, b AS INTEGER, m AS INTEGER
  14. restart:
  15. FOR i = 0 TO 360 'look at pallette
  16.     IF i MOD 60 = 0 THEN r = RND * 255: g = RND * 255: b = RND * 255
  17.     m = i MOD 60
  18.     SELECT CASE m
  19.         CASE IS < 15: c(i) = midInk(0, 0, 0, r, g, b, m / 15)
  20.         CASE IS < 30: c(i) = midInk(r, g, b, 255, 255, 255, (m - 15) / 15)
  21.         CASE IS < 45: c(i) = midInk(255, 255, 255, r, g, b, (m - 30) / 15)
  22.         CASE IS < 60: c(i) = midInk(r, g, b, 0, 0, 0, (m - 45) / 15)
  23.     END SELECT
  24.  
  25. FOR n = 0 TO 5
  26.     p(n).x = RND * xmax: p(n).y = RND * ymax: p(n).dx = RND * 2 - 1: p(n).dy = RND * 2 - 1
  27.     f(n) = RND * .1
  28.  
  29. WHILE _KEYDOWN(27) = 0
  30.     IF INKEY$ = " " THEN GOTO restart
  31.     FOR i = 0 TO 5
  32.         p(i).x = p(i).x + p(i).dx
  33.         IF p(i).x > xmax OR p(i).x < 0 THEN p(i).dx = -p(i).dx
  34.         p(i).y = p(i).y + p(i).dy
  35.         IF p(i).y > ymax OR p(i).y < 0 THEN p(i).dy = -p(i).dy
  36.     NEXT
  37.     FOR y = 0 TO ymax - 1 STEP 2
  38.         FOR x = 0 TO xmax - 1 STEP 2
  39.             d = 0
  40.             FOR n = 0 TO 5
  41.                 dx = x - p(n).x: dy = y - p(n).y
  42.                 k = SQR(dx * dx + dy * dy)
  43.                 d = d + (SIN(k * f(n)) + 1) / 2
  44.             NEXT n: d = d * 60
  45.             LINE (x, y)-STEP(2, 2), c(d), BF
  46.         NEXT
  47.     NEXT
  48.     _DISPLAY
  49.     _LIMIT 100
  50.  
  51. FUNCTION midInk~& (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  52.     midInk~& = _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  53.  
  54.  

This means I might be able to do a Plasmatic background for clock face or anything with far less code PLUS really mess with Plasma coloring that previously depends on a black border and white center like coloring a pipe in fake-3D.
Title: Re: Ectoplasm
Post by: SierraKen on January 23, 2020, 05:47:19 pm
Amazing job there. But I wonder if the slow speed will affect the speed of any more code you add?
Title: Re: Ectoplasm
Post by: SMcNeill on January 23, 2020, 06:09:15 pm
You were talking about getting rid of SQR...  Can’t you use _HYPOT?

                k = SQR(dx * dx + dy * dy)
k = _HYPOT(dx, dy)
Title: Re: Ectoplasm
Post by: bplus on January 23, 2020, 10:10:07 pm
You were talking about getting rid of SQR...  Can’t you use _HYPOT?

                k = SQR(dx * dx + dy * dy)
k = _HYPOT(dx, dy)

Thanks for suggestion, I tried it in following demo and it looks like SQR is a tiny bit faster, on my system the loop time is usually under .10 secs .09xxx with .10xxx showing more often with _HYPOT and .08xxx showing more with SQR. What is definitely slower is using ^.5 instead of SQR!


This is a demo of the new color Options available for Plasmatic effect, use t to toggle between Traditional Plasma that has high contrast Black between cells and White in cell centers, whereas the New Options available put any color between cells and any color as cell center:

again t to toggle between Traditional Plasma and New Options Plasma, use spacebar to change color sets:
Code: QB64: [Select]
  1. _TITLE "Color Mixing 4 Plasmatic" ' b+ 2020-01-23
  2. ' continued study of what makes Plasmatic tick, here the color pallete created
  3.  
  4. CONST xmax = 800, ymax = 600
  5. TYPE xy
  6.     x AS SINGLE
  7.     y AS SINGLE
  8.     dx AS SINGLE
  9.     dy AS SINGLE
  10. SCREEN _NEWIMAGE(xmax, ymax, 32)
  11. _SCREENMOVE 300, 10
  12. DIM c(360) AS _UNSIGNED LONG, p(6) AS xy, f(6), i AS INTEGER, r AS INTEGER, g AS INTEGER, b AS INTEGER, m AS INTEGER
  13. restart:
  14. IF mode < .5 THEN '<< sorry I was using RND before mode but this line still works
  15.     r1 = RND * 255: g1 = RND * 255: b1 = RND * 255
  16.     r2 = RND * 255: g2 = RND * 255: b2 = RND * 255
  17.     t$ = "t to toggle Current Mode New Plasma Option:  Between Cell Color" + STR$(r1) + STR$(g1) + STR$(b1) + "   Center Cell Color " + STR$(r2) + STR$(g2) + STR$(b2)
  18.     r2 = 255: g2 = 255: b2 = 255 'regular Plasma
  19.     r1 = 0: g1 = 0: b1 = 0
  20.     t$ = "t to toggle Current Mode Traditional Plasma:   Between Cell Color" + STR$(r1) + STR$(g1) + STR$(b1) + "   Center Cell Color" + STR$(r2) + STR$(g2) + STR$(b2)
  21.  
  22. FOR i = 0 TO 360
  23.     IF i MOD 60 = 0 THEN r = RND * 255: g = RND * 255: b = RND * 255
  24.     m = i MOD 60
  25.     SELECT CASE m
  26.         CASE IS < 15: c(i) = midInk(r1, g1, b1, r, g, b, m / 15)
  27.         CASE IS < 30: c(i) = midInk(r, g, b, r2, g2, b2, (m - 15) / 15)
  28.         CASE IS < 45: c(i) = midInk(r2, g2, b2, r, g, b, (m - 30) / 15)
  29.         CASE IS < 60: c(i) = midInk(r, g, b, r1, g1, b1, (m - 45) / 15)
  30.     END SELECT
  31.  
  32. FOR n = 0 TO 5
  33.     p(n).x = RND * xmax: p(n).y = RND * ymax: p(n).dx = RND * 2 - 1: p(n).dy = RND * 2 - 1
  34.     f(n) = .1 * RND
  35.  
  36. WHILE _KEYDOWN(27) = 0
  37.     k$ = INKEY$
  38.     IF k$ = " " THEN GOTO restart
  39.     IF k$ = "t" THEN mode = 1 - mode: GOTO restart
  40.     t = TIMER(.001)
  41.     FOR i = 0 TO 5
  42.         p(i).x = p(i).x + p(i).dx
  43.         IF p(i).x > xmax OR p(i).x < 0 THEN p(i).dx = -p(i).dx
  44.         p(i).y = p(i).y + p(i).dy
  45.         IF p(i).y > ymax OR p(i).y < 0 THEN p(i).dy = -p(i).dy
  46.     NEXT
  47.     _TITLE t$
  48.     FOR y = 0 TO ymax - 1 STEP 2
  49.         FOR x = 0 TO xmax - 1 STEP 2
  50.             d = 0
  51.             FOR n = 0 TO 5
  52.                 dx = x - p(n).x: dy = y - p(n).y
  53.                 k = SQR(dx * dx + dy * dy)
  54.                 'k = _HYPOT(dx, dy)
  55.                 d = d + (SIN(k * f(n)) + 1) / 2
  56.             NEXT n: d = d * 60
  57.             LINE (x, y)-STEP(2, 2), c(d), BF
  58.         NEXT
  59.     NEXT
  60.     LOCATE 1, 1: PRINT USING "#.####"; TIMER(.001) - t
  61.     _DISPLAY
  62.     '_LIMIT 100
  63.  
  64. FUNCTION midInk~& (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  65.     midInk~& = _RGBA32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##, 255)
  66.  
  67.  
Title: Re: Ectoplasm
Post by: johnno56 on January 24, 2020, 07:35:29 am
Plasmas are great! Flashback to the late 60's and 70's... So cool... or should that be... "Heavy man" or "Far out"?
Title: Re: Ectoplasm
Post by: SierraKen on January 24, 2020, 05:09:44 pm
Regarding my Lava Lamp mod, and yours B+, I changed it a bit more today making it only red shades of color without the ability to use the Space Bar to change anything. I did this to make it more realistic for a lava lamp. I also increased some numbers inside the bottom main loop on 2 IF/THEN statements so it would keep moving longer before everything changes direction. Do you happen to know who made the original code in SmallBasic where you got this from? I ask because I want to add their name to a comment in the code thanking them for posting it on a forum.
Tell me what you think of this, thanks.

Code: QB64: [Select]
  1. 'Lava Lamp modified by Ken G. and from b+ and from SmallBASIC.   mod again B+
  2. _TITLE "Lava Lamp" '
  3. 'Plasma Magnifico - updated 2015-11-26 for Android
  4. 'This program creates a plasma surface, which looks oily or silky.
  5. 'By SmallBasic and mods by B+ and SierraKen
  6.  
  7. CONST xmax = 250, ymax = 600
  8. TYPE xy
  9.     x AS SINGLE
  10.     y AS SINGLE
  11.     dx AS SINGLE
  12.     dy AS SINGLE
  13. SCREEN _NEWIMAGE(xmax, ymax, 32)
  14. _SCREENMOVE 300, 40
  15.  
  16. DIM c(360) AS _UNSIGNED LONG, p(6) AS xy, f(6)
  17.  
  18. restart:
  19. r = RND: g = .002: b = .002: i = 0
  20. FOR n = 1 TO 2
  21.     r1 = r: g1 = g: b1 = b
  22.     DO: r = RND: LOOP UNTIL ABS(r - r1) > .55
  23.  
  24.     FOR m = 0 TO 17: m1 = 17 - m
  25.         f1 = (m * r) / 18: f2 = (m * g) / 18: f3 = (m * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  26.     NEXT
  27.     FOR m = 0 TO 17: m1 = 17 - m
  28.         f1 = (m + m1 * r) / 18: f2 = (m + m1 * g) / 18: f3 = (m + m1 * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  29.     NEXT
  30.     FOR m = 0 TO 17: m1 = 17 - m
  31.         f1 = (m1 + m * r) / 18: f2 = (m1 + m * g) / 18: f3 = (m1 + m * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  32.     NEXT
  33.     FOR m = 0 TO 17: m1 = 17 - m
  34.         f1 = (m1 * r) / 18: f2 = (m1 * g) / 18: f3 = (m1 * b) / 18: c(i) = rgbf(f1, f2, f3): i = i + 1
  35.     NEXT
  36.  
  37. FOR n = 0 TO 2
  38.     p(n).x = RND * xmax: p(n).y = RND * ymax: p(n).dx = .25 * (RND * 2 - 1): p(n).dy = 2 * (RND * 2 - 1)
  39.     f(n) = .015
  40.  
  41.     CLS
  42.     IF INKEY$ = CHR$(27) THEN END
  43.     FOR i = 0 TO 6
  44.         p(i).x = p(i).x + p(i).dx
  45.         IF p(i).x > xmax - 500 OR p(i).x < 500 THEN p(i).dx = -p(i).dx
  46.         p(i).y = p(i).y + p(i).dy
  47.         IF p(i).y > ymax + 2000 OR p(i).y < -200 THEN p(i).dy = -p(i).dy
  48.     NEXT
  49.     FOR y = 0 TO ymax - 1 STEP 2
  50.         FOR x = 0 TO xmax - 1 STEP 2
  51.             d = 0
  52.             FOR n = 0 TO 2
  53.                 dx = x - p(n).x: dy = y - p(n).y
  54.                 k = SQR(dx * dx + dy * dy)
  55.                 d = d + (SIN(k * f(n)) + 1) / 2
  56.             NEXT n: d = d * 60
  57.             LINE (x, y)-STEP(2, 2), c(d), BF
  58.         NEXT
  59.     NEXT
  60.     _DISPLAY
  61.     _LIMIT 20
  62.  
  63. FUNCTION rgbf~& (n1, n2, n3)
  64.     rgbf~& = _RGB32(n1 * 255, n2 * 55, n3 * 55)
  65.  
  66.  
Title: Re: Ectoplasm
Post by: bplus on January 24, 2020, 06:58:04 pm
Quote
Do you happen to know who made the original code in SmallBasic where you got this from? I ask because I want to add their name to a comment in the code thanking them for posting it on a forum.

Hi Ken,
from reply #18 I left link to SmallBASIC Library and source code name
Quote
The program I (B+) translated and modified looked like this (plasmajvsh.bas from SmallBASIC code library,
http://smallbasic.github.io/pages/samples.html

That's all I know about it, that should be more than enough.
Title: Re: Ectoplasm
Post by: SierraKen on January 24, 2020, 07:14:41 pm
Thanks B+ :). So for the credit I have this now:

'Lava Lamp
_TITLE "Lava Lamp"
'This program creates a plasma surface, which looks oily or silky.
'By SmallBasic code plasmajvsh.bas from here: http://smallbasic.github.io/pages/samples.html
'and mods by B+ and SierraKen from the QB64.org forum.
Title: Re: Ectoplasm
Post by: bplus on January 26, 2020, 02:22:58 pm
Last night we played around with a Nautilus like Shell program from JB forum, yeah more eye candy but can you see the little gem in this code that may have great effect on the Plasmatic effect?

Code: QB64: [Select]
  1. _TITLE "Shell of another color" 'b+2020-01-25
  2. 'inspired by "shell-like thing" by tsh73 Jan 2020 at JB
  3.  
  4. SCREEN _NEWIMAGE(600, 600, 32)
  5. DIM x(1600), y(1600), c AS _UNSIGNED LONG
  6. cx = 300: cy = 300
  7. FOR a = 0 TO _PI(8) STEP _PI(2 / 400) ' load x, y arrays
  8.     x(i) = cx + ra * COS(a): y(i) = cy + ra * SIN(a)
  9.     dr = dr + 1 / 4800: ra = ra + dr
  10.     PSET (x(i), y(i)), &HFFFFFFFF
  11.     i = i + 1
  12.     r = RND: G = RND: B = RND: PN = 0
  13.     FOR i = 0 TO 399 'this block is a cheat to fill half a hole!
  14.         dx = x(i + 400) - x(i): dy = y(i + 400) - y(i)
  15.         dist = SQR(dx * dx + dy * dy)
  16.         dx = dx / dist: dy = dy / dist
  17.         PN = PN + .5
  18.         FOR j = 0 TO dist
  19.             shade = 1 - ((dist / 2 - j + 1 / 2) / (dist / 2)) ^ 2
  20.             c = _RGB32(shade * INT(127 + 127 * SIN(r * PN)), shade * INT(127 + 127 * SIN(G * PN)), shade * INT(127 + 127 * SIN(B * PN)))
  21.             fcirc cx + j * dx, cy + j * dy, 1, c
  22.         NEXT
  23.     NEXT
  24.     PN = PN - 200
  25.     FOR i = 0 TO 1199
  26.         dx = x(i + 400) - x(i): dy = y(i + 400) - y(i)
  27.         dist = SQR(dx * dx + dy * dy)
  28.         dx = dx / dist: dy = dy / dist
  29.         PN = PN + .5
  30.         FOR j = 0 TO dist
  31.             shade = 1 - ((dist / 2 - j + 1 / 2) / (dist / 2)) ^ 2
  32.             c = _RGB32(shade * INT(127 + 127 * SIN(r * PN)), shade * INT(127 + 127 * SIN(G * PN)), shade * INT(127 + 127 * SIN(B * PN)))
  33.             fcirc x(i) + j * dx, y(i) + j * dy, 2, c
  34.         NEXT
  35.     NEXT
  36.     _DISPLAY
  37.     _DELAY 2
  38.  
  39. 'from Steve Gold standard
  40. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  41.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  42.     DIM X AS INTEGER, Y AS INTEGER
  43.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  44.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  45.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  46.     WHILE X > Y
  47.         RadiusError = RadiusError + Y * 2 + 1
  48.         IF RadiusError >= 0 THEN
  49.             IF X <> Y + 1 THEN
  50.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  51.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  52.             END IF
  53.             X = X - 1
  54.             RadiusError = RadiusError - X * 2
  55.         END IF
  56.         Y = Y + 1
  57.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  58.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  59.     WEND
  60.  
  61.  


I haven't tried to recode Plasmatic yet but I am pretty sure it will be a very nice modification.
Title: Re: Ectoplasm
Post by: bplus on January 26, 2020, 03:46:32 pm
Yes the new color options are no longer so flat looking, so here is best yet Plasmatic 5:

Code: QB64: [Select]
  1. _TITLE "Plasmatic 5 Color Shading" ' b+ 2020-01-26
  2. ' Hopefully this will add shading to the new color options found in Pasmatic 4.
  3.  
  4. CONST xxmax = 800, yymax = 600, xmax = 900, ymax = 740, xoff = (xmax - xxmax) \ 2, yoff = (ymax - yymax) \ 2
  5. TYPE xy
  6.     x AS SINGLE
  7.     y AS SINGLE
  8.     dx AS SINGLE
  9.     dy AS SINGLE
  10. SCREEN _NEWIMAGE(xmax, ymax, 32)
  11. DIM c(360) AS _UNSIGNED LONG, p(6) AS xy, f(6)
  12. DIM i AS INTEGER, m AS INTEGER, n AS INTEGER, mode AS INTEGER, k$, t, x, y, d, dx, dy, dist, s
  13.  
  14. restart: 'select rgb1 and rgb2 based on mode of color mixing
  15. IF mode = 0 THEN 'new plasma option ANY color for border and ANY color for middle
  16.     r1 = RND * 255: g1 = RND * 255: b1 = RND * 255: r2 = RND * 255: g2 = RND * 255: b2 = RND * 255
  17. ELSE ' traditional high contrast plasma black borders, white centers
  18.     r1 = 0: g1 = 0: b1 = 0: r2 = 255: g2 = 255: b2 = 255 'regular Plasma
  19.  
  20. ' create 6 x 60 bands of color palette based on coloring mode (rgb1 set and rgb2 set)
  21. FOR i = 0 TO 360
  22.     IF i MOD 60 = 0 THEN r = RND * 255: g = RND * 255: b = RND * 255
  23.     m = i MOD 60
  24.     s = 1 - ((30 - m + .5) / 30) ^ 2
  25.     SELECT CASE m
  26.         CASE IS < 15: c(i) = midInk(s * r1, s * g1, s * b1, s * r, s * g, s * b, m / 15) '        1st stage increase rgb1 towards rgb color in 15 steps
  27.         CASE IS < 30: c(i) = midInk(s * r, s * g, s * b, s * r2, s * g2, s * b2, (m - 15) / 15) ' 2nd stage increase rgb color towards rgb2 set in 15 steps
  28.         CASE IS < 45: c(i) = midInk(s * r2, s * g2, s * b2, s * r, s * g, s * b, (m - 30) / 15) ' 3rd stage decrease rgb2 color back to rgb color in 15 steps
  29.         CASE IS < 60: c(i) = midInk(s * r, s * g, s * b, s * r1, s * g1, s * b1, (m - 45) / 15) ' 4th and finally decrease rgb back to starting rgb1 set in 15 steps
  30.     END SELECT
  31.  
  32. ' behind the scenes variables for motion, weighting and shaping color mixing
  33. FOR n = 0 TO 5
  34.     p(n).x = RND * xmax: p(n).y = RND * yymax: p(n).dx = RND * 2 - 1: p(n).dy = RND * 2 - 1
  35.     f(n) = .1 * RND
  36.  
  37. 'screen labeling 3 lines for title above, 1 line instructions below
  38. IF mode = 0 THEN
  39.     yCP yoff - 60, "New Color Options for Plasma:"
  40.     yCP yoff - 60, "Traditional High Contrast Plasma: Black Borders and White Centers"
  41. yCP yoff - 40, "Shaded Borders: RGB(" + TS$(r1 \ 1) + ", " + TS$(g1 \ 1) + ", " + TS$(b1 \ 1) + ")"
  42. yCP yoff - 20, "Centers: RGB(" + TS$(r2 \ 1) + ", " + TS$(g2 \ 1) + ", " + TS$(b2 \ 1) + ")"
  43. yCP yoff + yymax + 10, "Press t to toggle between Traditional and New Color Options Plasma"
  44. yCP yoff + yymax + 30, "Press spacebar to get a new color set."
  45.  
  46. WHILE _KEYDOWN(27) = 0
  47.     k$ = INKEY$
  48.     IF k$ = " " THEN GOTO restart
  49.     IF k$ = "t" THEN mode = 1 - mode: GOTO restart
  50.     t = TIMER(.001)
  51.     FOR i = 0 TO 5
  52.         p(i).x = p(i).x + p(i).dx
  53.         IF p(i).x > xxmax THEN p(i).dx = -p(i).dx: p(i).x = xxmax
  54.         IF p(i).x < 0 THEN p(i).dx = -p(i).dx: p(i).x = 0
  55.         p(i).y = p(i).y + p(i).dy
  56.         IF p(i).y > xxmax THEN p(i).dy = -p(i).dy: p(i).y = yymax
  57.         IF p(i).y < 0 THEN p(i).dy = -p(i).dy: p(i).y = 0
  58.     NEXT
  59.     FOR y = 0 TO yymax - 1 STEP 2
  60.         FOR x = 0 TO xxmax - 1 STEP 2
  61.             d = 0
  62.             FOR n = 0 TO 5
  63.                 dx = x - p(n).x: dy = y - p(n).y
  64.                 dist = SQR(dx * dx + dy * dy)
  65.                 'dist = _HYPOT(dx, dy)    'this may work faster on another system
  66.                 d = d + (SIN(dist * f(n)) + 1) / 2
  67.             NEXT n: d = d * 60
  68.             LINE (x + xoff, y + yoff)-STEP(2, 2), c(d), BF
  69.         NEXT
  70.     NEXT
  71.     yCP yoff + yymax + 50, SPACE$(50)
  72.     yCP yoff + yymax + 50, TS$(INT(1000 * (TIMER(.001) - t))) + " ms per frame"
  73.     _DISPLAY
  74.  
  75. FUNCTION midInk~& (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  76.     midInk~& = _RGBA32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##, 255)
  77.  
  78. SUB yCP (y, s$) 'for xmax pixel wide graphics screen Center Print at pixel y row
  79.     _PRINTSTRING ((_WIDTH - LEN(s$) * 8) / 2, y), s$
  80.  
  81.     TS$ = _TRIM$(STR$(n))
  82.  
  83.  

Title: Re: Ectoplasm
Post by: STxAxTIC on January 26, 2020, 04:07:35 pm
Heya bplus-

Pretty bang-up job, lots of results crammed into a relatively small amount of code.

Maybe it's my system, or maybe this is a familiar demon from the old plasma days, but it runs slow on my end. This immediately caused me to look at this part:

Code: QB64: [Select]
  1.                 dx = x - p(n).x: dy = y - p(n).y
  2.                 dist = SQR(dx * dx + dy * dy)
  3.                 'dist = _HYPOT(dx, dy)    'this may work faster on another system
  4.                 d = d + (SIN(dist * f(n)) + 1) / 2

Two things that probably don't need pointing out, but here they are:

1) You can speed things up by using a lookup table for the SIN() function. Even a crappy lookup table with an interpolation formula will certainly get you the precision you need, but probably be faster than the native SIN() function. They did this in the old days, I can only imagine it works now.

2) I see you fiddled with different ways to calculate the square root. Two-and-a-half thoughts on this: (1) Just leave it squared, you'll probably get the same kind of results anyway. (1a) Leave it squared but modify f(n) to compensate, if you can. (2) Use a lookup table for square roots. Linear interpolation for the in-between values will only be arithmetic and won't ever involve a square root in the loop.

I suppose you can also optimize in the direction of _MEM, but it becomes very nontransparent after that.

The third option is I upgrade my system........
Title: Re: Ectoplasm
Post by: bplus on January 26, 2020, 04:20:34 pm
Hi STxAxTIC,

How slow is it running for you?

More options for speed,
- decrease xxmax, yymax those are the inner screen dimensions
- decrease number n of points, really 2 or 3 are enough each point is another cycle over the whole drawing area.
- increase step size on x, y through xxmax and yymaxx
I had to employ all these for SmallBASIC which is only interpreted Basic.

I don't think tables would be practical (800 * 600)^2 x1, y1, x2, y2 the distance from any point to any other = 2.304*10^11 values.

I will try the suggestion of not squaring.
Title: Re: Ectoplasm
Post by: STxAxTIC on January 26, 2020, 04:24:11 pm
This part riiight here:

Quote
I don't think tables would be practical (800 * 600)^2 x1, y1, x2, y2 the distance from any point to any other = 2.304*10^11 values.

That's where interpolation comes in handy. The table need only contain crude known values, like 100, 105, 110, 120, etc. So that when a request for 103 comes in, it fakes the value by using its neighbors, 100 and 105. Same goes for a trig table, just wrap SIN() around each of the numbers I just used.

Not to mention the number of "values" might overcount. You want the number of pair-to-pair distances in a table? I think this is just a bunch of radii. Thats what I think i mean. Will have to look closer if not. Meh, take or leave this statement.
Title: Re: Ectoplasm
Post by: bplus on January 26, 2020, 07:16:26 pm
OK here is a nice set of settings, I added more colors to palette and stretched cells over 2 bands. SQR or no doesn't make a bunch of difference but stepper makes huge difference, recommend 2, 3 or 4 depending on your system:
Code: QB64: [Select]
  1. _TITLE "Plasmatic 5.1 Speed Tests" ' b+ 2020-01-26
  2. ' Try no SQR for distance
  3.  
  4. CONST xxmax = 700, yymax = 500, xmax = 900, ymax = 740, xoff = (xmax - xxmax) \ 2, yoff = (ymax - yymax) \ 2
  5. TYPE xy
  6.     x AS SINGLE
  7.     y AS SINGLE
  8.     dx AS SINGLE
  9.     dy AS SINGLE
  10. SCREEN _NEWIMAGE(xmax, ymax, 32)
  11. DIM c(1440) AS _UNSIGNED LONG, p(6) AS xy, f(6)
  12. DIM i AS INTEGER, m AS INTEGER, n AS INTEGER, mode AS INTEGER, cnt AS INTEGER, k$, t, x, y, d, dx, dy, dist, s, stepper, tot
  13.  
  14. restart: 'select rgb1 and rgb2 based on mode of color mixing
  15. IF mode = 0 THEN 'new plasma option ANY color for border and ANY color for middle
  16.     r1 = RND * 255: g1 = RND * 255: b1 = RND * 255: r2 = RND * 255: g2 = RND * 255: b2 = RND * 255
  17. ELSE ' traditional high contrast plasma black borders, white centers
  18.     r1 = 0: g1 = 0: b1 = 0: r2 = 255: g2 = 255: b2 = 255 'regular Plasma
  19.  
  20. ' create 6 x 60 bands of color palette based on coloring mode (rgb1 set and rgb2 set)
  21. FOR i = 0 TO 720
  22.     IF i MOD 60 = 0 THEN r = RND * 255: g = RND * 255: b = RND * 255
  23.     m = i MOD 60
  24.     s = 1 - ((30 - m + .5) / 30) ^ 2
  25.     SELECT CASE m
  26.         CASE IS < 15: c(i) = midInk(s * r1, s * g1, s * b1, s * r, s * g, s * b, m / 15) '        1st stage increase rgb1 towards rgb color in 15 steps
  27.         CASE IS < 30: c(i) = midInk(s * r, s * g, s * b, s * r2, s * g2, s * b2, (m - 15) / 15) ' 2nd stage increase rgb color towards rgb2 set in 15 steps
  28.         CASE IS < 45: c(i) = midInk(s * r2, s * g2, s * b2, s * r, s * g, s * b, (m - 30) / 15) ' 3rd stage decrease rgb2 color back to rgb color in 15 steps
  29.         CASE IS < 60: c(i) = midInk(s * r, s * g, s * b, s * r1, s * g1, s * b1, (m - 45) / 15) ' 4th and finally decrease rgb back to starting rgb1 set in 15 steps
  30.     END SELECT
  31.  
  32. ' behind the scenes variables for motion, weighting and shaping color mixing
  33. FOR n = 0 TO 6
  34.     p(n).x = RND * xmax: p(n).y = RND * yymax: p(n).dx = RND * 2 - 1: p(n).dy = RND * 2 - 1
  35.     f(n) = .09 * RND
  36.  
  37. 'screen labeling 3 lines for title above, 1 line instructions below
  38. IF mode = 0 THEN
  39.     yCP yoff - 60, "New Color Options for Plasma:"
  40.     yCP yoff - 60, "Traditional High Contrast Plasma: Black Borders and White Centers"
  41. yCP yoff - 40, "Shaded Borders: RGB(" + TS$(r1 \ 1) + ", " + TS$(g1 \ 1) + ", " + TS$(b1 \ 1) + ")"
  42. yCP yoff - 20, "Centers: RGB(" + TS$(r2 \ 1) + ", " + TS$(g2 \ 1) + ", " + TS$(b2 \ 1) + ")"
  43. yCP yoff + yymax + 10, "Press t to toggle between Traditional and New Color Options Plasma"
  44. yCP yoff + yymax + 30, "Press spacebar to get a new color set."
  45.  
  46. WHILE _KEYDOWN(27) = 0
  47.     k$ = INKEY$
  48.     IF k$ = " " THEN GOTO restart
  49.     IF k$ = "t" THEN mode = 1 - mode: GOTO restart
  50.     t = TIMER(.001)
  51.     FOR i = 0 TO 6
  52.         p(i).x = p(i).x + p(i).dx
  53.         IF p(i).x > 2 * xxmax THEN p(i).dx = -p(i).dx: p(i).x = 2 * xxmax
  54.         IF p(i).x < -xxmax THEN p(i).dx = -p(i).dx: p(i).x = -xxmax
  55.         p(i).y = p(i).y + p(i).dy
  56.         IF p(i).y > 2 * yymax THEN p(i).dy = -p(i).dy: p(i).y = 2 * yymax
  57.         IF p(i).y < -yymax THEN p(i).dy = -p(i).dy: p(i).y = -yymax
  58.     NEXT
  59.     stepper = 3
  60.     FOR y = 0 TO yymax - 1 STEP stepper
  61.         FOR x = 0 TO xxmax - 1 STEP stepper
  62.             d = 0
  63.             FOR n = 0 TO 6
  64.                 dx = x - p(n).x: dy = y - p(n).y
  65.                 dist = .0005 * (dx * dx + dy * dy)
  66.                 'dist = SQR(dx * dx + dy * dy)
  67.                 'dist = _HYPOT(dx, dy)    'this may work faster on another system
  68.                 d = d + (SIN(dist * f(n)) + 1) / 2
  69.             NEXT n: d = d * 120
  70.             LINE (x + xoff, y + yoff)-STEP(stepper, stepper), c(d), BF
  71.         NEXT
  72.     NEXT
  73.     cnt = cnt + 1
  74.     tot = tot + TIMER(.001) - t
  75.     IF cnt = 100 THEN
  76.         yCP yoff + yymax + 50, SPACE$(50)
  77.         yCP yoff + yymax + 50, RIGHT$("   " + TS$(INT(1000 * tot / 100)), 4) + " ms per frame"
  78.         cnt = 0: tot = 0
  79.     END IF
  80.     _DISPLAY
  81.  
  82. FUNCTION midInk~& (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  83.     midInk~& = _RGBA32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##, 255)
  84.  
  85. SUB yCP (y, s$) 'for xmax pixel wide graphics screen Center Print at pixel y row
  86.     _PRINTSTRING ((_WIDTH - LEN(s$) * 8) / 2, y), s$
  87.  
  88.     TS$ = _TRIM$(STR$(n))
  89.  
  90.  

Plasma now gets holes in it, cool!
Title: Re: Ectoplasm
Post by: johnno56 on January 26, 2020, 08:03:01 pm
Cool version. Runs much better than the previous... Averaging 13-14ms / frame...
Makes one nostalgic for the 70's... The decade that fashion forgot... lol
Title: Re: Ectoplasm
Post by: bplus on January 27, 2020, 07:06:45 pm
Update to the shell program:
Code: QB64: [Select]
  1. _TITLE "Shell of another color 3" 'b+2020-01-25
  2. 'inspired by "shell-like thing" by tsh73 Jan 2020 at JB
  3. ' 2020-01-27 Shell of another color 3 adds more improvements
  4.  
  5. SCREEN _NEWIMAGE(660, 660, 32)
  6. _SCREENMOVE 300, 40
  7. DIM x(1600), y(1600), c AS _UNSIGNED LONG
  8. cx = 340: cy = 390
  9. FOR a = 0 TO _PI(8) STEP _PI(2 / 400) ' load x, y arrays
  10.     x(i) = cx + ra * COS(a): y(i) = cy + ra * SIN(a)
  11.     dr = dr + 1 / 1700: ra = ra + dr ^ 2: i = i + 1
  12.     R = RND ^ 2: G = RND ^ 2: B = RND ^ 2: PN = 0: size = 1
  13.     FOR i = 0 TO 1139
  14.         dx = x(i + 400) - x(i): dy = y(i + 400) - y(i)
  15.         dist = SQR(dx * dx + dy * dy): dx = dx / dist: dy = dy / dist: PN = PN + .73
  16.         IF i > 820 THEN
  17.             size = 3
  18.         ELSEIF i > 380 THEN
  19.             size = 2
  20.         END IF
  21.         FOR j = 0 TO dist
  22.             shade = 1 - ((dist / 2 - j + 1 / 2) / (dist / 2)) ^ 2
  23.             c = _RGB32(shade * INT(127 + 127 * SIN(R * PN)), shade * INT(127 + 127 * SIN(G * PN)), shade * INT(127 + 127 * SIN(B * PN)))
  24.             fcirc x(i) + j * dx, y(i) + j * dy, size, c
  25.         NEXT
  26.     NEXT
  27.     _DISPLAY
  28.     _DELAY 2
  29.  
  30. 'from Steve Gold standard
  31. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  32.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  33.     DIM X AS INTEGER, Y AS INTEGER
  34.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  35.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  36.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  37.     WHILE X > Y
  38.         RadiusError = RadiusError + Y * 2 + 1
  39.         IF RadiusError >= 0 THEN
  40.             IF X <> Y + 1 THEN
  41.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  42.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  43.             END IF
  44.             X = X - 1
  45.             RadiusError = RadiusError - X * 2
  46.         END IF
  47.         Y = Y + 1
  48.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  49.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  50.     WEND
  51.  
  52.