Author Topic: Cube Plasma  (Read 12707 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cube Plasma
« Reply #15 on: June 13, 2018, 11:21:04 am »
Hi Petr,

Don't worry, it's nice demo I can see why you want to show it off.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Cube Plasma
« Reply #16 on: June 14, 2018, 04:55:57 am »
I don't know how a 3D plasma actually look like.
Maybe it looks like this -

Code: QB64: [Select]
  1. '3D plasma, coded by Ashish  14 June, 2018
  2. 'Twitter : @KingOfCoders
  3. 'http://lodev.org/cgtutor/plasma.html
  4.  
  5. _TITLE "3D Plasma"
  6. SCREEN _NEWIMAGE(600, 600, 32)
  7.  
  8.  
  9.     'for camera
  10.     SUB gluLookAt (BYVAL eyeX#, BYVAL eyeY#, BYVAL eyeZ#, BYVAL centerX#, BYVAL centerY#, BYVAL centerZ#, BYVAL upX#, BYVAL upY#, BYVAL upZ#)
  11.  
  12. DIM SHARED mapSize
  13. mapSize = 200
  14. DIM SHARED glAllow AS _BYTE, textureImage&(258), tmp_buffer_image&
  15. DIM SHARED tmp_height_map&, height_map_buffer AS _MEM 'New height maps
  16.  
  17. tmp_buffer_image& = _NEWIMAGE(mapSize, mapSize, 32)
  18. tmp_height_map& = _NEWIMAGE(mapSize, mapSize, 32) 'this image will be treated as height map
  19. height_map_buffer = _MEMIMAGE(tmp_height_map&) 'the data in above image will access by this _MEM buffer
  20.  
  21.  
  22. _DEST tmp_buffer_image&
  23. 'storing calculation in memory for faster rendering
  24. DIM sin1(_WIDTH - 1, _HEIGHT - 1), sin2(_WIDTH - 1, _HEIGHT - 1), sin3(_WIDTH - 1, _HEIGHT - 1)
  25. FOR y = 0 TO _HEIGHT - 1
  26.     FOR x = 0 TO _WIDTH - 1
  27.         sin1(x, y) = SIN(SQR(x ^ 2 + y ^ 2) * .09)
  28.         sin2(x, y) = SIN(y * .03)
  29.         sin3(x, y) = COS(((_WIDTH / 2 - x) ^ 2 + (_HEIGHT / 2 - y) ^ 2) ^ .5 * .07)
  30. NEXT x, y
  31.  
  32.     _DEST 0
  33.     CLS
  34.     PRINT "Generating Textures "; f; "/"; UBOUND(textureImage&) - 1
  35.     f = f + 1
  36.     FOR y = 0 TO _HEIGHT(tmp_buffer_image&) - 1
  37.         FOR x = 0 TO _WIDTH(tmp_buffer_image&) - 1
  38.             col = sin1(x, y) * 64 + sin2(x, y) * 64 + sin3(x, y) * 64 + 255 + f
  39.             col2 = col MOD 255
  40.             _DEST tmp_buffer_image&
  41.             PSET (x, y), hsb(col2, 255, 128, 255)
  42.     NEXT x, y
  43.     textureImage&(f) = _COPYIMAGE(tmp_buffer_image&)
  44. LOOP UNTIL f > UBOUND(textureImage&) - 1
  45. _FREEIMAGE tmp_buffer_image&
  46.  
  47.  
  48.  
  49. _DEST tmp_height_map&
  50. glAllow = -1
  51.     f = f + 1
  52.     FOR y = 0 TO _HEIGHT - 1
  53.         FOR x = 0 TO _WIDTH - 1
  54.             col = sin1(x, y) * 64 + sin2(x, y) * 64 + sin3(x, y) * 64 + 255 + f
  55.             col = SIN(col * .01) * 64 + 128
  56.             PSET (x, y), _RGB(col, col, col)
  57.     NEXT x, y
  58.  
  59. SUB _GL ()
  60.     STATIC cubeTexture&(257), glSetup
  61.     STATIC aspect#, frame
  62.  
  63.  
  64.     IF NOT glAllow THEN EXIT SUB
  65.  
  66.     IF NOT glSetup THEN
  67.         glSetup = -1
  68.         _glViewport 0, 0, _WIDTH, _HEIGHT
  69.         'Convert all images to GL textures
  70.         FOR i = 1 TO UBOUND(textureImage&) - 1
  71.             _glGenTextures 1, _OFFSET(cubeTexture&(i))
  72.             DIM m AS _MEM
  73.             m = _MEMIMAGE(textureImage&(i))
  74.  
  75.             _glBindTexture _GL_TEXTURE_2D, cubeTexture&(i)
  76.             _glTexImage2D _GL_TEXTURE_2D, 0, _GL_RGB, _WIDTH(textureImage&(i)), _HEIGHT(textureImage&(i)), 0, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, m.OFFSET
  77.  
  78.             _MEMFREE m
  79.  
  80.             _glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MAG_FILTER, _GL_LINEAR
  81.             _glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MIN_FILTER, _GL_NEAREST
  82.             _FREEIMAGE textureImage&(i)
  83.         NEXT
  84.         aspect# = _WIDTH / _HEIGHT
  85.     END IF
  86.  
  87.     _glEnable _GL_TEXTURE_2D
  88.     _glEnable _GL_DEPTH_TEST
  89.  
  90.     _glMatrixMode _GL_PROJECTION
  91.     _gluPerspective 45.0, aspect#, 1, 100
  92.  
  93.     _glMatrixMode _GL_MODELVIEW
  94.  
  95.     _glShadeModel _GL_SMOOTH
  96.  
  97.     gluLookAt 0, 0, 4, 0, 0, 0, 0, 1, 0
  98.  
  99.     i = (frame MOD (UBOUND(textureImage&) - 1)) + 1
  100.  
  101.     'select our texture
  102.     _glBindTexture _GL_TEXTURE_2D, cubeTexture&(i)
  103.  
  104.     'rotation
  105.     _glRotatef -45, 1, 0, 0
  106.  
  107.     drawPlane 2, 2, .05, height_map_buffer
  108.  
  109.     frame = frame + 1
  110.  
  111. SUB drawPlane (w, h, detail, height_map AS _MEM)
  112.  
  113.     'texture coordinates
  114.     tx1 = 0: ty1 = 0
  115.     tx2 = 0: ty2 = 0
  116.  
  117.     depth1 = 0 'used for depth effect by using height maps
  118.     depth2 = 0
  119.  
  120.     hx1% = 0: hy1% = 0
  121.     hx2% = 0: hy2% = 0
  122.     _glBegin _GL_TRIANGLE_STRIP
  123.     FOR y = -h / 2 TO h / 2 - detail STEP detail
  124.         FOR x = -w / 2 TO w / 2 - detail STEP detail
  125.             tx1 = map(x, -w / 2, w / 2, 0, 1)
  126.             ty1 = map(y, -h / 2, h / 2, 1, 0)
  127.             ty2 = map(y + detail, -h / 2, h / 2, 1, 0)
  128.  
  129.             hx1% = map(tx1, 0, 1, 1, mapSize - 1)
  130.             hy1% = map(ty1, 0, 1, mapSize - 1, 1)
  131.             hy2% = map(ty2, 0, 1, mapSize - 1, 1)
  132.  
  133.             depth1 = _MEMGET(height_map, height_map.OFFSET + memImageIndex(hx1%, hy1%, mapSize), _UNSIGNED _BYTE) / 400
  134.             depth2 = _MEMGET(height_map, height_map.OFFSET + memImageIndex(hx1%, hy2%, mapSize), _UNSIGNED _BYTE) / 400
  135.  
  136.             _glTexCoord2f tx1, ty1
  137.             _glVertex3f x, y, depth1
  138.             _glTexCoord2f tx1, ty2
  139.             _glVertex3f x, y + detail, depth2
  140.         NEXT x
  141.     NEXT y
  142.  
  143.     _glEnd
  144.  
  145.  
  146. FUNCTION memImageIndex& (x, y, w)
  147.     memImageIndex& = (x + y * w) * 4
  148.  
  149.  
  150. FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  151.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  152.  
  153. 'method adapted form http://stackoverflow.com/questions/4106363/converting-rgb-to-hsb-colors
  154. FUNCTION hsb~& (__H AS _FLOAT, __S AS _FLOAT, __B AS _FLOAT, A AS _FLOAT)
  155.     DIM H AS _FLOAT, S AS _FLOAT, B AS _FLOAT
  156.  
  157.     H = map(__H, 0, 255, 0, 360)
  158.     S = map(__S, 0, 255, 0, 1)
  159.     B = map(__B, 0, 255, 0, 1)
  160.  
  161.     IF S = 0 THEN
  162.         hsb~& = _RGBA32(B * 255, B * 255, B * 255, A)
  163.         EXIT FUNCTION
  164.     END IF
  165.  
  166.     DIM fmx AS _FLOAT, fmn AS _FLOAT
  167.     DIM fmd AS _FLOAT, iSextant AS INTEGER
  168.     DIM imx AS INTEGER, imd AS INTEGER, imn AS INTEGER
  169.  
  170.     IF B > .5 THEN
  171.         fmx = B - (B * S) + S
  172.         fmn = B + (B * S) - S
  173.     ELSE
  174.         fmx = B + (B * S)
  175.         fmn = B - (B * S)
  176.     END IF
  177.  
  178.     iSextant = INT(H / 60)
  179.  
  180.     IF H >= 300 THEN
  181.         H = H - 360
  182.     END IF
  183.  
  184.     H = H / 60
  185.     H = H - (2 * INT(((iSextant + 1) MOD 6) / 2))
  186.  
  187.     IF iSextant MOD 2 = 0 THEN
  188.         fmd = (H * (fmx - fmn)) + fmn
  189.     ELSE
  190.         fmd = fmn - (H * (fmx - fmn))
  191.     END IF
  192.  
  193.     imx = _ROUND(fmx * 255)
  194.     imd = _ROUND(fmd * 255)
  195.     imn = _ROUND(fmn * 255)
  196.  
  197.     SELECT CASE INT(iSextant)
  198.         CASE 1
  199.             hsb~& = _RGBA32(imd, imx, imn, A)
  200.         CASE 2
  201.             hsb~& = _RGBA32(imn, imx, imd, A)
  202.         CASE 3
  203.             hsb~& = _RGBA32(imn, imd, imx, A)
  204.         CASE 4
  205.             hsb~& = _RGBA32(imd, imn, imx, A)
  206.         CASE 5
  207.             hsb~& = _RGBA32(imx, imn, imd, A)
  208.         CASE ELSE
  209.             hsb~& = _RGBA32(imx, imd, imn, A)
  210.     END SELECT
  211.  
  212.  
  213.  
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cube Plasma
« Reply #17 on: June 14, 2018, 09:33:04 am »
Another great effect!

Ashish, you changed your avatar!

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Cube Plasma
« Reply #18 on: June 14, 2018, 09:39:58 am »
Another great effect!

Ashish, you changed your avatar!
Thanks bplus! Yeah, I changed my avatar. Is my new avatar is not looking good? If yes, I will bring back my old avatar.
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cube Plasma
« Reply #19 on: June 14, 2018, 09:41:55 am »
It is fine example of infinity! I wish I could see a bigger version. Did you make it?

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Cube Plasma
« Reply #20 on: June 14, 2018, 09:51:35 am »
It is fine example of infinity! I wish I could see a bigger version. Did you make it?
Nope! I'm not a good artist. This image is from here - http://tharyn.me/wp-content/uploads/2013/12/Infinity_Symbol.jpg
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cube Plasma
« Reply #21 on: June 14, 2018, 01:04:34 pm »
I try:
Code: QB64: [Select]
  1. _TITLE "Infinity B+ started 2018-06-14 mod of Vince Hour Glass"
  2. CONST xmax = 800
  3. CONST ymax = 600
  4.  
  5. SCREEN _NEWIMAGE(xmax, ymax, 32)
  6. _SCREENMOVE 360, 60
  7. pi = _ACOS(-1)
  8. p2 = pi * 2
  9.     b = b + .01
  10.     IF b > p2 THEN b = 0
  11.     FOR r = 40 TO 1 STEP -1
  12.         COLOR _RGB(r * (6 * SIN(b)), r * 6 * (1 - SIN(b)), 0)
  13.         fcirc 400 + 300 * COS(b), 300 + 150 * SIN(2 * b), r
  14.     NEXT
  15.     _DISPLAY
  16.  
  17. 'Steve McNeil's  copied from his forum  note: Radius is too common a name ;-)
  18. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  19.     DIM subRadius AS LONG, RadiusError AS LONG
  20.     DIM X AS LONG, Y AS LONG
  21.  
  22.     subRadius = ABS(R)
  23.     RadiusError = -subRadius
  24.     X = subRadius
  25.     Y = 0
  26.  
  27.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  28.  
  29.     ' Draw the middle span here so we don't draw it twice in the main loop,
  30.     ' which would be a problem with blending turned on ;-)
  31.     LINE (CX - X, CY)-(CX + X, CY), , BF
  32.  
  33.     WHILE X > Y
  34.         RadiusError = RadiusError + Y * 2 + 1
  35.         IF RadiusError >= 0 THEN
  36.             IF X <> Y + 1 THEN
  37.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  38.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  39.             END IF
  40.             X = X - 1
  41.             RadiusError = RadiusError - X * 2
  42.         END IF
  43.         Y = Y + 1
  44.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  45.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  46.     WEND
  47.  
  48.  
Infinity.PNG
* Infinity.PNG (Filesize: 43.67 KB, Dimensions: 802x608, Views: 453)

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Cube Plasma
« Reply #22 on: June 14, 2018, 09:05:41 pm »
It's nice bplus. I didn't know that you were talking about this. :)
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Cube Plasma
« Reply #23 on: June 15, 2018, 08:53:20 am »
@bplus, changing the sin multiplier gives it a thinner profile, like 100*sin

Here's the program in freebasic, fyi:
Code: QB64: [Select]
  1. #lang "fblite"
  2.  
  3. defsng a-z
  4.  
  5. CONST xmax = 800
  6. CONST ymax = 600
  7.  
  8. declare SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  9.  
  10. screenres xmax, ymax, 32
  11.  
  12. pi = ACOS(-1)
  13. p2 = pi * 2
  14.     b = b + .01
  15.     IF b > p2 THEN b = 0
  16.     FOR r = 40 TO 1 STEP -1
  17.         COLOR rgb(r * (6 * SIN(b)), r * 6 * (1 - SIN(b)), 0)
  18.         fcirc 400 + 300 * COS(b), 300 + 100 * SIN(2 * b), int(r)
  19.     NEXT
  20.         screensync
  21.  
  22. 'Steve McNeil's  copied from his forum  note: Radius is too common a name ;-)
  23. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  24.     DIM subRadius AS LONG, RadiusError AS LONG
  25.     DIM X AS LONG, Y AS LONG
  26.  
  27.     subRadius = ABS(R)
  28.     RadiusError = -subRadius
  29.     X = subRadius
  30.     Y = 0
  31.  
  32.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  33.  
  34.     ' Draw the middle span here so we don't draw it twice in the main loop,
  35.     ' which would be a problem with blending turned on ;-)
  36.     LINE (CX - X, CY)-(CX + X, CY), , BF
  37.  
  38.     WHILE X > Y
  39.         RadiusError = RadiusError + Y * 2 + 1
  40.         IF RadiusError >= 0 THEN
  41.             IF X <> Y + 1 THEN
  42.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  43.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  44.             END IF
  45.             X = X - 1
  46.             RadiusError = RadiusError - X * 2
  47.         END IF
  48.         Y = Y + 1
  49.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  50.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  51.     WEND
  52.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cube Plasma
« Reply #24 on: June 15, 2018, 10:16:04 am »
Hi V,

Watch that language! :D

Here is a mod, I do like shape better. Somewhere between 80 and 100...

Code: QB64: [Select]
  1. _TITLE "Infinity B+ started 2018-06-15 mod of mod of Vince Hour Glass"
  2. CONST xmax = 800
  3. CONST ymax = 600
  4.  
  5. SCREEN _NEWIMAGE(xmax, ymax, 32)
  6. _SCREENMOVE 360, 60
  7. pi = _ACOS(-1)
  8. p2 = pi * 2
  9. FOR r = 40 TO 0 STEP -1
  10.     COLOR _RGBA32(255 - r * 4, 255 - r * 4, 0, 1)
  11.     FOR a = 0 TO p2 STEP .01
  12.         fcirc 400 + 300 * COS(a), 300 + 80 * SIN(2 * a), r
  13.     NEXT
  14. FOR b = 0 TO p2 STEP .001
  15.     b = b + .001
  16.     IF b > p2 THEN b = 0
  17.     COLOR _RGB(255 * SIN(b), 255 * (1 - SIN(b)), 0)
  18.     fcirc 400 + 300 * COS(b), 300 + 80 * SIN(2 * b), r
  19. PRINT "Press any... "
  20.     b = b + .01
  21.     IF b > p2 THEN b = 0
  22.     FOR r = 40 TO 1 STEP -1
  23.         COLOR _RGB(r * (6 * SIN(b)), r * 6 * (1 - SIN(b)), 0)
  24.         fcirc 400 + 300 * COS(b), 300 + 90 * SIN(2 * b), r
  25.     NEXT
  26.     _DISPLAY
  27.  
  28. 'Steve McNeil's  copied from his forum  note: Radius is too common a name ;-)
  29. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  30.     DIM subRadius AS LONG, RadiusError AS LONG
  31.     DIM X AS LONG, Y AS LONG
  32.  
  33.     subRadius = ABS(R)
  34.     RadiusError = -subRadius
  35.     X = subRadius
  36.     Y = 0
  37.  
  38.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  39.  
  40.     ' Draw the middle span here so we don't draw it twice in the main loop,
  41.     ' which would be a problem with blending turned on ;-)
  42.     LINE (CX - X, CY)-(CX + X, CY), , BF
  43.  
  44.     WHILE X > Y
  45.         RadiusError = RadiusError + Y * 2 + 1
  46.         IF RadiusError >= 0 THEN
  47.             IF X <> Y + 1 THEN
  48.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  49.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  50.             END IF
  51.             X = X - 1
  52.             RadiusError = RadiusError - X * 2
  53.         END IF
  54.         Y = Y + 1
  55.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  56.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  57.     WEND
  58.  
  59.  
Infinity mod.PNG
* Infinity mod.PNG (Filesize: 84.37 KB, Dimensions: 799x589, Views: 417)
« Last Edit: June 15, 2018, 10:24:18 am by bplus »