QB64.org Forum

Active Forums => Programs => Topic started by: Ashish on June 12, 2018, 05:45:28 am

Title: Cube Plasma
Post by: Ashish on June 12, 2018, 05:45:28 am
Hi everyone! Here's a simple effect of plasma on cube. I have learn about plasma
in detail from here http://lodev.org/cgtutor/plasma.html

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

EDIT : Code has been clean up.
Title: Re: Cube Plasma
Post by: bplus on June 12, 2018, 10:32:27 am
Wow! nice one Ashish!
Title: Re: Cube Plasma
Post by: Petr on June 12, 2018, 10:44:43 am
Very nice work, Ashish!
Title: Re: Cube Plasma
Post by: Ashish on June 12, 2018, 11:38:49 am
Thank you, Bplus and Petr! :)
Title: Re: Cube Plasma
Post by: FellippeHeitor on June 12, 2018, 11:50:15 am
Wow, dynamic texture! This is gorgeous, Ashish.
Title: Re: Cube Plasma
Post by: _vince on June 12, 2018, 11:43:41 pm
Very neat, it took me a while to notice the texture's animated and not an illusion due to the rotation.  A 3D plasma, instead of a 2D plasma on a surface, would be quite neat.
Title: Re: Cube Plasma
Post by: Ashish on June 13, 2018, 02:40:00 am
Wow, dynamic texture! This is gorgeous, Ashish.
Thanks Fellippe! :D

Very neat, it took me a while to notice the texture's animated and not an illusion due to the rotation.  A 3D plasma, instead of a 2D plasma on a surface, would be quite neat.
Thanks Vince! A 3D plasma ? Interesting... never heard about it before... :)
Title: Re: Cube Plasma
Post by: bplus on June 13, 2018, 09:24:47 am
That is an interesting idea! I have to another look at how plasma effect works (in 2D).
Title: Re: Cube Plasma
Post by: Petr on June 13, 2018, 09:28:07 am
 I just had to try do modification with video ...

Code: QB64: [Select]
  1. 'Cube plasma, coded by Ashish  6/12/2018
  2. 'Twitter : @KingOfCoders
  3. 'http://lodev.org/cgtutor/plasma.html
  4.  
  5.     'for camera
  6.     SUB gluLookAt (BYVAL eyeX#, BYVAL eyeY#, BYVAL eyeZ#, BYVAL centerX#, BYVAL centerY#, BYVAL centerZ#, BYVAL upX#, BYVAL upY#, BYVAL upZ#)
  7.  
  8.     SUB initQuadric ()
  9.     SUB drawCylinder ()
  10.     SUB drawDisk ()
  11.     SUB drawSphere ()
  12.     SUB drawCone ()
  13.     SUB drawPartialDisk (BYVAL a AS DOUBLE, BYVAL b AS DOUBLE)
  14.  
  15.  
  16.  
  17. _TITLE "Reply for Ashish"
  18. SCREEN _NEWIMAGE(600, 600, 32)
  19.  
  20. DIM SHARED glAllow AS _BYTE, textureImage&(11), tmp_buffer_image&
  21.  
  22. tmp_buffer_image& = _NEWIMAGE(200, 200, 32)
  23. horse& = _LOADIMAGE("horseU.jpg", 32)
  24.  
  25. TYPE FRAME ' generate to memory correct coordinates (no images!) to play video from source file
  26.     Source AS LONG
  27.     X_Start AS INTEGER
  28.     Y_Start AS INTEGER
  29.     X_End AS INTEGER
  30.     Y_End AS INTEGER
  31.     Index AS _UNSIGNED _BYTE
  32.  
  33. REDIM SHARED OhenVideo(0) AS FRAME
  34. REDIM SHARED Horse(0) AS FRAME
  35.  
  36. VideoLoad Horse(), horse&, 4, 3, 146, 95, 0, 0
  37.  
  38.     f = f + 1
  39.     _DEST tmp_buffer_image&
  40.     _SOURCE tmp_buffer_image&
  41.     CLS
  42.     _DEST tmp_buffer_image&
  43.     IF f < UBOUND(textureImage&) - 1 / 2 THEN VideoPlay OhenVideo(), 100, 100, 1 ELSE VideoPlay Horse(), 100, 100, 1
  44.     textureImage&(f) = _COPYIMAGE(tmp_buffer_image&) 'sem vlozit
  45. LOOP UNTIL f > UBOUND(textureImage&) - 1
  46. n:
  47.  
  48. _DEST tmp_buffer_image&
  49. CLS , _RGB32(22, 22, 249)
  50.  
  51. FOR f = 0 TO 11
  52.     CLS , _RGB32(22, 22, 249)
  53.     VideoPlay Horse(), -5, 25, 1.5 'I have only redirected function output to your virtual screen and it works great!
  54.     _DISPLAY
  55.     textureImage&(f) = _COPYIMAGE(tmp_buffer_image&)
  56.  
  57. _FREEIMAGE tmp_buffer_image&
  58.  
  59. glAllow = -1
  60.     _LIMIT 30 '?
  61.  
  62. SUB VideoLoad (Array() AS FRAME, Source AS LONG, FramesX AS INTEGER, FramesY AS INTEGER, ResFrameX AS INTEGER, ResFrameY AS INTEGER, CorrX AS _BYTE, CorrY AS _BYTE)
  63.     FOR T = 0 TO FramesX * FramesY
  64.         REDIM _PRESERVE Array(T) AS FRAME
  65.         Array(T).Source = Source&
  66.         Array(T).X_Start = X
  67.         Array(T).Y_Start = Y
  68.         Array(T).X_End = X + ResFrameX - CorrX
  69.         Array(T).Y_End = Y + ResFrameY - CorrY
  70.         X = X + ResFrameX + CorrX: IF X > _WIDTH(Source&) THEN X = 0: Y = Y + ResFrameY + CorrY
  71.     NEXT T
  72.  
  73. SUB VideoPlay (array() AS FRAME, X AS INTEGER, Y AS INTEGER, Zoom AS SINGLE)
  74.     IF array(0).Index + 1 > UBOUND(array) THEN array(0).Index = 0 ELSE array(0).Index = array(0).Index + 1
  75.     Frame = array(0).Index
  76.     PosXs = array(Frame).X_Start
  77.     PosXe = array(Frame).X_End
  78.     PosYs = array(Frame).Y_Start
  79.     PosYe = array(Frame).Y_End
  80.     ResX = PosXe - PosXs
  81.     ResY = PosYe - PosYs
  82.     S& = array(Frame).Source&
  83.     _PUTIMAGE (X, Y)-(Zoom * (X + ResX), Zoom * (Y + ResY)), S&, tmp_buffer_image&, (PosXs, PosYs)-(PosXe, PosYe)
  84.  
  85.  
  86. SUB _GL ()
  87.     STATIC cubeTexture&(11), glSetup, aspect#, frame
  88.  
  89.     IF NOT glAllow THEN EXIT SUB
  90.  
  91.     IF NOT glSetup THEN
  92.         glSetup = -1
  93.         _glViewport 0, 0, _WIDTH, _HEIGHT
  94.         'Convert all images to GL textures
  95.         FOR i = 1 TO UBOUND(textureImage&) - 1
  96.             _glGenTextures 1, _OFFSET(cubeTexture&(i))
  97.             DIM m AS _MEM
  98.             m = _MEMIMAGE(textureImage&(i))
  99.  
  100.             _glBindTexture _GL_TEXTURE_2D, cubeTexture&(i)
  101.             _glTexImage2D _GL_TEXTURE_2D, 0, _GL_RGB, _WIDTH(textureImage&(i)), _HEIGHT(textureImage&(i)), 0, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, m.OFFSET
  102.             _MEMFREE m
  103.             _glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MAG_FILTER, _GL_LINEAR
  104.             _glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MIN_FILTER, _GL_NEAREST
  105.             _FREEIMAGE textureImage&(i)
  106.         NEXT
  107.         aspect# = _WIDTH / _HEIGHT
  108.         initQuadric
  109.     END IF
  110.  
  111.     _glEnable _GL_TEXTURE_2D
  112.     _glEnable _GL_DEPTH_TEST
  113.  
  114.     _glMatrixMode _GL_PROJECTION
  115.     _gluPerspective 45.0, aspect#, 1, 100
  116.  
  117.     _glMatrixMode _GL_MODELVIEW
  118.  
  119.     gluLookAt 0, 0, 5, 0, 0, 0, 0, 1, 0
  120.     i = (frame MOD (UBOUND(textureImage&) - 1)) + 1
  121.     'select our texture
  122.     _LIMIT 25
  123.     _glBindTexture _GL_TEXTURE_2D, cubeTexture&(i)
  124.     'rotation
  125.     _glRotatef frame * .01 * 120, 1.1, .5, .3
  126.     drawDisk
  127.     frame = frame + 1
  128.  

and works perfectly!
Title: Re: Cube Plasma
Post by: Ashish on June 13, 2018, 10:05:52 am
+Petr
Amazing! Dynamic texturing is really cool thing to play with. :D
Title: Re: Cube Plasma
Post by: bplus on June 13, 2018, 10:06:56 am
Hi Petr,

Is the library "help" commonly found somewhere?
Title: Re: Cube Plasma
Post by: Petr on June 13, 2018, 10:09:07 am
Hi Bplus, is in ZIP file. Copy it to your QB64 dir.
Title: Re: Cube Plasma
Post by: FellippeHeitor on June 13, 2018, 10:58:18 am
Yeah, it was in the zip when I downloaded it too.

BTW, Petr, you can keep libraries in the same folder as your .bas file if you add them with a relative path:

DECLARE LIBRARY "./help"

Otherwise QB64 always looks for them in its own root folder.
Title: Re: Cube Plasma
Post by: bplus on June 13, 2018, 11:11:26 am
Ah that helps! Thanks Fellippe

I was not expecting an help.h file. I saw the Horse.bas and wondered if I got a mod of Cube Plasma.

No, but with line change recommended by Fellippe I did get the code working:
Title: Re: Cube Plasma
Post by: Petr on June 13, 2018, 11:17:38 am
Fellippe, thank you for the information. Bplus, sorry that the program is out of the Plasma theme. I'm returning to collisions.
Title: Re: Cube Plasma
Post by: bplus 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.
Title: Re: Cube Plasma
Post by: Ashish 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.  
Title: Re: Cube Plasma
Post by: bplus on June 14, 2018, 09:33:04 am
Another great effect!

Ashish, you changed your avatar!
Title: Re: Cube Plasma
Post by: Ashish 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.
Title: Re: Cube Plasma
Post by: bplus 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?
Title: Re: Cube Plasma
Post by: Ashish 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
Title: Re: Cube Plasma
Post by: bplus 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.  
Title: Re: Cube Plasma
Post by: Ashish on June 14, 2018, 09:05:41 pm
It's nice bplus. I didn't know that you were talking about this. :)
Title: Re: Cube Plasma
Post by: _vince 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.  
Title: Re: Cube Plasma
Post by: bplus 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.