Author Topic: Ectoplasm  (Read 11537 times)

0 Members and 1 Guest are viewing this topic.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Ectoplasm
« Reply #45 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.
« Last Edit: January 26, 2020, 04:26:42 pm by STxAxTIC »
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 #46 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!
Plasmatic 5.1 speed tests.PNG
* Plasmatic 5.1 speed tests.PNG (Filesize: 110.45 KB, Dimensions: 904x765, Views: 267)

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Ectoplasm
« Reply #47 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
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Ectoplasm
« Reply #48 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.  
QB Shell 3.PNG
* QB Shell 3.PNG (Filesize: 349.01 KB, Dimensions: 659x658, Views: 251)
« Last Edit: January 27, 2020, 07:09:31 pm by bplus »