Author Topic: Ectoplasm  (Read 9708 times)

0 Members and 1 Guest are viewing this topic.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Ectoplasm
« Reply #15 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...

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ectoplasm
« Reply #16 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
 
Crescent Pattern Cog Layout.PNG


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.  
wavy.PNG
« Last Edit: July 01, 2019, 12:21:13 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ectoplasm
« Reply #17 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.

plasmatic.PNG
* plasmatic.PNG (Filesize: 201.75 KB, Dimensions: 798x624, Views: 204)
« Last Edit: January 20, 2020, 10:41:19 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ectoplasm
« Reply #18 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!


 
« Last Edit: January 21, 2020, 11:46:08 am by bplus »

Offline dajan

  • Newbie
  • Posts: 41
    • View Profile
Re: Ectoplasm
« Reply #19 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.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Ectoplasm
« Reply #20 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.
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ectoplasm
« Reply #21 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.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Ectoplasm
« Reply #22 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. :)
« Last Edit: January 21, 2020, 10:38:57 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Ectoplasm
« Reply #23 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.  
Plasmatic-Tron.jpg
* Plasmatic-Tron.jpg (Filesize: 122.17 KB, Dimensions: 800x629, Views: 236)
« Last Edit: January 26, 2020, 11:29:50 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ectoplasm
« Reply #24 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.
Pasmatic nPoints Test mod.PNG
* Pasmatic nPoints Test mod.PNG (Filesize: 198.55 KB, Dimensions: 807x628, Views: 206)
« Last Edit: January 22, 2020, 10:05:25 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Ectoplasm
« Reply #25 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?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ectoplasm
« Reply #26 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.

« Last Edit: January 22, 2020, 02:54:30 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Ectoplasm
« Reply #27 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?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ectoplasm
« Reply #28 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.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ectoplasm
« Reply #29 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.  
Dance of 3 points.PNG
* Dance of 3 points.PNG (Filesize: 223.4 KB, Dimensions: 806x626, Views: 200)
« Last Edit: January 22, 2020, 11:26:46 pm by bplus »