Author Topic: Cube Wave  (Read 4848 times)

0 Members and 1 Guest are viewing this topic.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
Cube Wave
« on: March 12, 2018, 12:34:58 pm »
Hello everyone! :D
Now the harmonic motion comes in 3D. :)
Enjoy the cube waves.

Code: QB64: [Select]
  1. 'Coded by Ashish on 12 March, 2018
  2. 'Originally By @BeesandBombs
  3. '[youtube]https://youtu.be/H81Tdrmz2LA[/youtube]
  4.  
  5. _TITLE "Cube Wave"
  6.  
  7. SCREEN _NEWIMAGE(800, 600, 32)
  8.  
  9. TYPE vec4
  10.     x AS SINGLE
  11.     y AS SINGLE
  12.     z AS SINGLE
  13.     w AS SINGLE
  14.  
  15. TYPE vec3
  16.     x AS SINGLE
  17.     y AS SINGLE
  18.     z AS SINGLE
  19.  
  20.     'for camera
  21.     SUB gluLookAt (BYVAL eyeX#, BYVAL eyeY#, BYVAL eyeZ#, BYVAL centerX#, BYVAL centerY#, BYVAL centerZ#, BYVAL upX#, BYVAL upY#, BYVAL upZ#)
  22.  
  23. DIM SHARED glAllow AS _BYTE
  24. DIM SHARED cubeSize
  25. cubeSize = .2
  26.  
  27. glAllow = -1
  28.     _DISPLAY
  29.     _LIMIT 40
  30.  
  31.  
  32.  
  33. SUB _GL ()
  34.     STATIC glInit, aspect#, clock#, angOff#
  35.  
  36.     DIM lightAmb AS vec3, lightDiff AS vec3, lightSpec AS vec3, lightPos AS vec4
  37.     DIM matAmb AS vec3, matDiff AS vec3, matSpec AS vec3, matShin AS SINGLE
  38.  
  39.     'light color settings
  40.     lightAmb.x = .2: lightDiff.x = .79: lightSpec.x = .99
  41.     lightAmb.y = .2: lightDiff.y = .79: lightSpec.x = .99
  42.     lightAmb.z = .2: lightDiff.z = .79: lightSpec.x = .99
  43.     'light direction settings ,when w=0 it is directional light, when w =1, it is a point light
  44.     lightPos.x = 0
  45.     lightPos.y = 0
  46.     lightPos.z = 1
  47.     lightPos.w = 0
  48.     'material settings
  49.     'try to play with it! but the value of any of these must be between 0 and 1.
  50.     matAmb.x = .4: matDiff.x = .7: matSpec.x = .999
  51.     matAmb.y = .7: matDiff.y = 1: matSpec.y = .999
  52.     matAmb.z = .7: matDiff.z = 1: matSpec.z = .999
  53.     matShin = .6
  54.     '
  55.  
  56.     IF NOT glAllow THEN EXIT SUB
  57.  
  58.     _glEnable _GL_DEPTH_TEST
  59.  
  60.     IF NOT glInit THEN
  61.         glInit = -1
  62.         aspect# = _WIDTH / _HEIGHT
  63.         _glViewport 0, 0, _WIDTH, _HEIGHT
  64.     END IF
  65.  
  66.     'setuping light
  67.     _glEnable _GL_LIGHTING
  68.     _glEnable _GL_LIGHT0
  69.     addLight _GL_LIGHT0, lightAmb, lightSpec, lightDiff, lightPos
  70.  
  71.     _glMatrixMode _GL_PROJECTION
  72.     'we will be using orthographic projection
  73.     _glOrtho -5, 5, -5, 5, -5, 5
  74.  
  75.     _glMatrixMode _GL_MODELVIEW
  76.  
  77.     _glTranslatef 0, 0, 0
  78.     _glRotatef 45, 0, 1, 0
  79.     _glRotatef 23, 0, 0, 1
  80.  
  81.     'give our materials.
  82.     setMaterial matAmb, matSpec, matDiff, matShin
  83.  
  84.     'draw our cubes
  85.     FOR z = -3 TO 3 STEP cubeSize + cubeSize / 1.5
  86.         FOR x = -3 TO 3 STEP cubeSize + cubeSize / 1.5
  87.             d = dist(0, 0, x, z) 'angle will be shifted according to the distance from the center, i.e., (0,0,0)
  88.             offset = map(d, 0, SQR(18), _PI, -_PI)
  89.  
  90.             s# = map(SIN(offset + angOff#), -1, 1, 1, 4)
  91.  
  92.             _glPushMatrix
  93.  
  94.             _glTranslatef x, 0, z
  95.             drawBox cubeSize, s#, cubeSize
  96.  
  97.             _glPopMatrix
  98.         NEXT x
  99.     NEXT z
  100.  
  101.     _glFlush
  102.     angOff# = angOff# + .07
  103.     clock# = clock# + .01
  104.  
  105.  
  106. SUB addLight (light, ambient AS vec3, specular AS vec3, diffuse AS vec3, __pos AS vec4)
  107.     _glLightfv light, _GL_AMBIENT, glVec3(ambient.x, ambient.y, ambient.z)
  108.     _glLightfv light, _GL_SPECULAR, glVec3(specular.x, specular.y, specular.z)
  109.     _glLightfv light, _GL_DIFFUSE, glVec3(diffuse.x, diffuse.y, diffuse.z)
  110.     _glLightfv light, _GL_POSITION, glVec4(__pos.x, __pos.y, __pos.z, __pos.w)
  111.  
  112. SUB setMaterial (ambient AS vec3, specular AS vec3, diffuse AS vec3, shineness AS SINGLE)
  113.     _glMaterialfv _GL_FRONT, _GL_AMBIENT, glVec3(ambient.x, ambient.y, ambient.z)
  114.     _glMaterialfv _GL_FRONT, _GL_DIFFUSE, glVec3(diffuse.x, diffuse.y, diffuse.z)
  115.     _glMaterialfv _GL_FRONT, _GL_SPECULAR, glVec3(specular.x, specular.y, specular.z)
  116.     _glMaterialfv _GL_FRONT, _GL_SHININESS, glVec3(128 * shineness, 0, 0)
  117.  
  118. 'sub to draw a custom box with given width, height and depth.
  119. SUB drawBox (w, h, d)
  120.     _glBegin _GL_QUADS
  121.     'front
  122.     _glNormal3f 0, 0, 1
  123.     _glVertex3f -w / 2, h / 2, d / 2
  124.     _glVertex3f w / 2, h / 2, d / 2
  125.     _glVertex3f w / 2, -h / 2, d / 2
  126.     _glVertex3f -w / 2, -h / 2, d / 2
  127.     'back
  128.     _glNormal3f 0, 0, -1
  129.     _glVertex3f -w / 2, h / 2, -d / 2
  130.     _glVertex3f w / 2, h / 2, -d / 2
  131.     _glVertex3f w / 2, -h / 2, -d / 2
  132.     _glVertex3f -w / 2, -h / 2, -d / 2
  133.     'right
  134.     _glNormal3f 1, 0, 0
  135.     _glVertex3f w / 2, h / 2, d / 2
  136.     _glVertex3f w / 2, h / 2, -d / 2
  137.     _glVertex3f w / 2, -h / 2, -d / 2
  138.     _glVertex3f w / 2, -h / 2, d / 2
  139.     'left
  140.     _glNormal3f -1, 0, 0
  141.     _glVertex3f -w / 2, h / 2, d / 2
  142.     _glVertex3f -w / 2, h / 2, -d / 2
  143.     _glVertex3f -w / 2, -h / 2, -d / 2
  144.     _glVertex3f -w / 2, -h / 2, d / 2
  145.     'top
  146.     _glNormal3f 0, 1, 0
  147.     _glVertex3f -w / 2, h / 2, d / 2
  148.     _glVertex3f -w / 2, h / 2, -d / 2
  149.     _glVertex3f w / 2, h / 2, -d / 2
  150.     _glVertex3f w / 2, h / 2, d / 2
  151.     'bottom
  152.     _glNormal3f 0, -1, 0
  153.     _glVertex3f -w / 2, -h / 2, d / 2
  154.     _glVertex3f -w / 2, -h / 2, -d / 2
  155.     _glVertex3f w / 2, -h / 2, -d / 2
  156.     _glVertex3f w / 2, -h / 2, d / 2
  157.  
  158.     _glEnd
  159.  
  160. 'used for passing pointers to the OpenGL.
  161. FUNCTION glVec3%& (x, y, z)
  162.     STATIC internal_vec3(2)
  163.     internal_vec3(0) = x
  164.     internal_vec3(1) = y
  165.     internal_vec3(2) = z
  166.     glVec3%& = _OFFSET(internal_vec3())
  167.  
  168. FUNCTION glVec4%& (x, y, z, w)
  169.     STATIC internal_vec4(3)
  170.     internal_vec4(0) = x
  171.     internal_vec4(1) = y
  172.     internal_vec4(2) = z
  173.     internal_vec4(3) = w
  174.     glVec4%& = _OFFSET(internal_vec4())
  175.  
  176. 'taken from p5js.bas
  177. FUNCTION dist! (x1!, y1!, x2!, y2!)
  178.     dist! = SQR((x2! - x1!) ^ 2 + (y2! - y1!) ^ 2)
  179.  
  180.  
  181. FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  182.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  183.  
  184.  
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 + ...
Re: Cube Wave
« Reply #1 on: March 13, 2018, 08:14:21 pm »
Once again I am inspired by Ashish example and attempt a similar thing from a different angle.

Here is Johnno's Gold Wave translated from SmallBASIC to QB64 in 2 ways:
1. First I tried the old fashioned way with line filled triangles.
2. Then I tried a very simple _MAPTRIANGLE method which turns out to be allot speedier if you remember _FREEIMAGE

Code: QB64: [Select]
  1. _TITLE "Gold Wave bplus 2018-03-13"
  2. 'translated from SmallBASIC: Goldwave by johnno copied and mod by bplus 2018-01-28
  3.  
  4. 'QB64 version 2017 1106/82 (the day before they switched to version 1.2)
  5. CONST xmax = 600
  6. CONST ymax = 480
  7. SCREEN _NEWIMAGE(xmax, ymax, 32)
  8. _SCREENMOVE 360, 60
  9.  
  10.  
  11. '                  compare fill triangle subs:  one uses very simple  _MAPTRIANGLE opt = 1
  12. '                                               2nd uses primative line graphic0s  opt <> 1
  13.  
  14.  
  15. opt = 1 ' << opt 1 uses _MAPTRIANGLE to fill triangles, any other uses line filled triangles
  16.     FOR t = 1 TO 60 STEP .1 '< changed
  17.         CLS 'changed
  18.         FOR y1 = 0 TO 24
  19.             FOR x1 = 0 TO 24
  20.                 x = (12 * (24 - x1)) + (12 * y1)
  21.                 y = (-6 * (24 - x1)) + (6 * y1) + 300
  22.                 d = ((10 - x1) ^ 2 + (10 - y1) ^ 2) ^ .5
  23.                 h = 60 * SIN(x1 / 4 + t) + 65
  24.                 IF t > 10 AND t < 20 THEN h = 60 * SIN(y1 / 4 + t) + 65
  25.                 IF t > 20 AND t < 30 THEN h = 60 * SIN((x1 - y1) / 4 + t) + 65
  26.                 IF t > 30 AND t < 40 THEN h = 30 * SIN(x1 / 2 + t) + 30 * SIN(y1 / 2 + t) + 65
  27.                 IF t > 40 AND t < 50 THEN h = 60 * SIN((x1 + y1) / 4 + t) + 65
  28.                 IF t > 50 AND t < 60 THEN h = 60 * SIN(d * .3 + t) + 65
  29.                 IF opt = 1 THEN
  30.                     'TOP
  31.                     ccc = _RGB32(242 + .1 * h, 242 + .1 * h, h)
  32.                     filltri x, y - h, x + 10, y + 5 - h, x + 20, y - h, ccc
  33.                     filltri x, y - h, x + 10, y - 5 - h, x + 20, y - h, ccc
  34.                     'FRONT-LEFT
  35.                     ccc = _RGB(255, 80, 0)
  36.                     filltri x, y - h, x + 10, y + 5 - h, x + 10, y, ccc
  37.                     filltri x, y - h, x, y - 5, x + 10, y, ccc
  38.                     'FRONT-RIGHT
  39.                     ccc = _RGB32(255, 150, 0)
  40.                     filltri x + 10, y + 5 - h, x + 10, y, x + 20, y - 5, ccc
  41.                     filltri x + 10, y + 5 - h, x + 20, y - h, x + 20, y - 5, ccc
  42.                 ELSE
  43.                     COLOR _RGB32(242 + .1 * h, 242 + .1 * h, h)
  44.                     filltri2 x, y - h, x + 10, y + 5 - h, x + 20, y - h
  45.                     filltri2 x, y - h, x + 10, y - 5 - h, x + 20, y - h
  46.                     'FRONT-LEFT
  47.                     COLOR _RGB32(255, 80, 0)
  48.                     filltri2 x, y - h, x + 10, y + 5 - h, x + 10, y
  49.                     filltri2 x, y - h, x, y - 5, x + 10, y
  50.                     COLOR _RGB32(255, 150, 0)
  51.                     filltri2 x + 10, y + 5 - h, x + 10, y, x + 20, y - 5
  52.                     filltri2 x + 10, y + 5 - h, x + 20, y - h, x + 20, y - 5
  53.                 END IF
  54.  
  55.                 IF INKEY$ = CHR$(27) THEN END
  56.             NEXT
  57.         NEXT
  58.         _DISPLAY
  59.         _LIMIT 200  'to compare speeds
  60.     NEXT
  61.  
  62. 'Andy Amaya's modified FillTriangle
  63. SUB filltri2 (xx1, yy1, xx2, yy2, xx3, yy3)
  64.     'make copies before swapping
  65.     x1 = xx1: y1 = yy1: x2 = xx2: y2 = yy2: x3 = xx3: y3 = yy3
  66.     'thanks Andy Amaya!
  67.     'triangle coordinates must be ordered: where x1 < x2 < x3
  68.     IF x2 < x1 THEN SWAP x1, x2: SWAP y1, y2
  69.     IF x3 < x1 THEN SWAP x1, x3: SWAP y1, y3
  70.     IF x3 < x2 THEN SWAP x2, x3: SWAP y2, y3
  71.     IF x1 <> x3 THEN slope1 = (y3 - y1) / (x3 - x1)
  72.  
  73.     'draw the first half of the triangle
  74.     length = x2 - x1
  75.     IF length <> 0 THEN
  76.         slope2 = (y2 - y1) / (x2 - x1)
  77.         FOR x = 0 TO length
  78.             LINE (INT(x + x1), INT(x * slope1 + y1))-(INT(x + x1), INT(x * slope2 + y1))
  79.             'lastx2% = lastx%
  80.             lastx% = INT(x + x1)
  81.         NEXT
  82.     END IF
  83.  
  84.     'draw the second half of the triangle
  85.     y = length * slope1 + y1: length = x3 - x2
  86.     IF length <> 0 THEN
  87.         slope3 = (y3 - y2) / (x3 - x2)
  88.         FOR x = 0 TO length
  89.             'IF INT(x + x2) <> lastx% AND INT(x + x2) <> lastx2% THEN  'works! but need 2nd? check
  90.             IF INT(x + x2) <> lastx% THEN
  91.                 LINE (INT(x + x2), INT(x * slope1 + y))-(INT(x + x2), INT(x * slope3 + y2))
  92.             END IF
  93.         NEXT
  94.     END IF
  95.  
  96. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  97. SUB filltri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  98.     a = _NEWIMAGE(1, 1, 32)
  99.     _DEST a
  100.     PSET (0, 0), K
  101.     _DEST 0
  102.     _MAPTRIANGLE (0, 0)-(0, 0)-(0, 0), a TO(x1, y1)-(x2, y2)-(x3, y3)
  103.     _FREEIMAGE a '<<< this is important!
  104.  
  105.  
GW1.PNG
* GW1.PNG (Filesize: 42.64 KB, Dimensions: 607x506, Views: 528)
GW2.PNG
* GW2.PNG (Filesize: 35.1 KB, Dimensions: 600x508, Views: 516)

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
Re: Cube Wave
« Reply #2 on: March 14, 2018, 01:44:23 am »
This is really cool bplus! I like it a lot!
« Last Edit: March 14, 2018, 09:17:48 am by Ashish »
if (Me.success) {Me.improve()} else {Me.tryAgain()}


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

FellippeHeitor

  • Guest
Re: Cube Wave
« Reply #3 on: March 14, 2018, 08:40:48 am »
Amazing results both with OpenGL and with pure QB64. Kudos to both of you guys. These are really cool.

FellippeHeitor

  • Guest
Re: Cube Wave
« Reply #4 on: March 14, 2018, 09:14:43 am »
My mod to gold wave to turn it into "Trippy Bedsheet Swing With Morphing Colors":

Code: QB64: [Select]
  1. _TITLE "Trippy Bedsheet Swing With Morphing Colors"
  2. 'translated from SmallBASIC: Goldwave by johnno copied and mod by bplus 2018-01-28
  3. 'trippy bedsheet mod by fellippeheitor 2018-03-14
  4.  
  5. CONST xmax = 600
  6. CONST ymax = 480
  7. SCREEN _NEWIMAGE(xmax, ymax, 32)
  8. _SCREENMOVE 360, 60
  9.  
  10.  
  11. '                  compare fill triangle subs:  one uses very simple  _MAPTRIANGLE opt = 1
  12. '                                               2nd uses primative line graphic0s  opt <> 1
  13.  
  14.  
  15. opt = 1 ' << opt 1 uses _MAPTRIANGLE to fill triangles, any other uses line filled triangles
  16.  
  17. r = 0
  18. g = 65
  19. b = 127
  20.     r = r + 15
  21.     g = g + 15
  22.     b = b + 15
  23.     ccc = _RGB32(r, g, b)
  24.     FOR t = 50.5 TO 56.6 STEP .1 '< changed
  25.         CLS 'changed
  26.         FOR y1 = 0 TO 24
  27.             FOR x1 = 0 TO 24
  28.                 x = (12 * (24 - x1)) + (12 * y1)
  29.                 y = (-6 * (24 - x1)) + (6 * y1) + 300
  30.                 d = ((10 - x1) ^ 2 + (10 - y1) ^ 2) ^ .5
  31.                 h = 60 * SIN(x1 / 4 + t) + 65
  32.                 IF t > 10 AND t < 20 THEN h = 60 * SIN(y1 / 4 + t) + 65
  33.                 IF t > 20 AND t < 30 THEN h = 60 * SIN((x1 - y1) / 4 + t) + 65
  34.                 IF t > 30 AND t < 40 THEN h = 30 * SIN(x1 / 2 + t) + 30 * SIN(y1 / 2 + t) + 65
  35.                 IF t > 40 AND t < 50 THEN h = 60 * SIN((x1 + y1) / 4 + t) + 65
  36.                 IF t > 50 AND t < 60 THEN h = 60 * SIN(d * .3 + t) + 65
  37.                 IF opt = 1 THEN
  38.                     'TOP
  39.                     filltri x, y - h, x + 10, y + 5 - h, x + 20, y - h, Shade(ccc, h)
  40.                     filltri x, y - h, x + 10, y - 5 - h, x + 20, y - h, Shade(ccc, h)
  41.                     ''FRONT-LEFT
  42.                     'filltri x, y - h, x + 10, y + 5 - h, x + 10, y, Shade(ccc, 40)
  43.                     'filltri x, y - h, x, y - 5, x + 10, y, Shade(ccc, 40)
  44.                     ''FRONT-RIGHT
  45.                     'filltri x + 10, y + 5 - h, x + 10, y, x + 20, y - 5, Shade(ccc, 120)
  46.                     'filltri x + 10, y + 5 - h, x + 20, y - h, x + 20, y - 5, Shade(ccc, 120)
  47.                 ELSE
  48.                     COLOR _RGB32(242 + .1 * h, 242 + .1 * h, h)
  49.                     filltri2 x, y - h, x + 10, y + 5 - h, x + 20, y - h
  50.                     filltri2 x, y - h, x + 10, y - 5 - h, x + 20, y - h
  51.                     'FRONT-LEFT
  52.                     COLOR _RGB32(255, 80, 0)
  53.                     filltri2 x, y - h, x + 10, y + 5 - h, x + 10, y
  54.                     filltri2 x, y - h, x, y - 5, x + 10, y
  55.                     COLOR _RGB32(255, 150, 0)
  56.                     filltri2 x + 10, y + 5 - h, x + 10, y, x + 20, y - 5
  57.                     filltri2 x + 10, y + 5 - h, x + 20, y - h, x + 20, y - 5
  58.                 END IF
  59.  
  60.                 IF INKEY$ = CHR$(27) THEN END
  61.             NEXT
  62.         NEXT
  63.         _DISPLAY
  64.         _LIMIT 30 'to compare speeds
  65.     NEXT
  66.  
  67. 'Andy Amaya's modified FillTriangle
  68. SUB filltri2 (xx1, yy1, xx2, yy2, xx3, yy3)
  69.     'make copies before swapping
  70.     x1 = xx1: y1 = yy1: x2 = xx2: y2 = yy2: x3 = xx3: y3 = yy3
  71.     'thanks Andy Amaya!
  72.     'triangle coordinates must be ordered: where x1 < x2 < x3
  73.     IF x2 < x1 THEN SWAP x1, x2: SWAP y1, y2
  74.     IF x3 < x1 THEN SWAP x1, x3: SWAP y1, y3
  75.     IF x3 < x2 THEN SWAP x2, x3: SWAP y2, y3
  76.     IF x1 <> x3 THEN slope1 = (y3 - y1) / (x3 - x1)
  77.  
  78.     'draw the first half of the triangle
  79.     length = x2 - x1
  80.     IF length <> 0 THEN
  81.         slope2 = (y2 - y1) / (x2 - x1)
  82.         FOR x = 0 TO length
  83.             LINE (INT(x + x1), INT(x * slope1 + y1))-(INT(x + x1), INT(x * slope2 + y1))
  84.             'lastx2% = lastx%
  85.             lastx% = INT(x + x1)
  86.         NEXT
  87.     END IF
  88.  
  89.     'draw the second half of the triangle
  90.     y = length * slope1 + y1: length = x3 - x2
  91.     IF length <> 0 THEN
  92.         slope3 = (y3 - y2) / (x3 - x2)
  93.         FOR x = 0 TO length
  94.             'IF INT(x + x2) <> lastx% AND INT(x + x2) <> lastx2% THEN  'works! but need 2nd? check
  95.             IF INT(x + x2) <> lastx% THEN
  96.                 LINE (INT(x + x2), INT(x * slope1 + y))-(INT(x + x2), INT(x * slope3 + y2))
  97.             END IF
  98.         NEXT
  99.     END IF
  100.  
  101. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  102. SUB filltri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  103.     a = _NEWIMAGE(1, 1, 32)
  104.     _DEST a
  105.     PSET (0, 0), K
  106.     _DEST 0
  107.     _MAPTRIANGLE (0, 0)-(0, 0)-(0, 0), a TO(x1, y1)-(x2, y2)-(x3, y3)
  108.     _FREEIMAGE a '<<< this is important!
  109.  
  110. FUNCTION Shade~& (WhichColor~&, ByHowMuch%)
  111.     Shade~& = _RGB32(_RED32(WhichColor~&) * (ByHowMuch% / 100), _GREEN32(WhichColor~&) * (ByHowMuch% / 100), _BLUE32(WhichColor~&) * (ByHowMuch% / 100))
  112.  

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
Re: Cube Wave
« Reply #5 on: March 14, 2018, 09:20:35 am »
@Fellippe
Very nice mod! Amazing effect with shading colors.
if (Me.success) {Me.improve()} else {Me.tryAgain()}


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

FellippeHeitor

  • Guest
Re: Cube Wave
« Reply #6 on: March 14, 2018, 02:07:41 pm »
Modded once again (my last, I promisse) to use HSB color space and provide smooth color transition.

Code: QB64: [Select]
  1. _TITLE "Trippy Bedsheet Swing With Morphing Colors"
  2. 'translated from SmallBASIC: Goldwave by johnno copied and mod by bplus 2018-01-28
  3. 'trippy bedsheet mod by fellippeheitor 2018-03-14
  4.  
  5. CONST xmax = 600
  6. CONST ymax = 480
  7. SCREEN _NEWIMAGE(xmax, ymax, 32)
  8. _SCREENMOVE 360, 60
  9. '_FULLSCREEN _SQUAREPIXELS , _SMOOTH
  10.  
  11. '                  compare fill triangle subs:  one uses very simple  _MAPTRIANGLE opt = 1
  12. '                                               2nd uses primative line graphic0s  opt <> 1
  13.  
  14.  
  15. opt = 1 ' << opt 1 uses _MAPTRIANGLE to fill triangles, any other uses line filled triangles
  16.  
  17. DIM angle
  18.     ccc = hsb(angle, 127, 127, 255)
  19.     angle = angle + 10
  20.     FOR t = 50.5 TO 56.7 STEP .1 '< changed
  21.         CLS 'changed
  22.         FOR y1 = 0 TO 24
  23.             FOR x1 = 0 TO 24
  24.                 x = (12 * (24 - x1)) + (12 * y1)
  25.                 y = (-6 * (24 - x1)) + (6 * y1) + 300
  26.                 d = ((10 - x1) ^ 2 + (10 - y1) ^ 2) ^ .5
  27.                 h = 60 * SIN(x1 / 4 + t) + 65
  28.                 IF t > 10 AND t < 20 THEN h = 60 * SIN(y1 / 4 + t) + 65
  29.                 IF t > 20 AND t < 30 THEN h = 60 * SIN((x1 - y1) / 4 + t) + 65
  30.                 IF t > 30 AND t < 40 THEN h = 30 * SIN(x1 / 2 + t) + 30 * SIN(y1 / 2 + t) + 65
  31.                 IF t > 40 AND t < 50 THEN h = 60 * SIN((x1 + y1) / 4 + t) + 65
  32.                 IF t > 50 AND t < 60 THEN h = 60 * SIN(d * .3 + t) + 65
  33.                 IF opt = 1 THEN
  34.                     'TOP
  35.                     filltri x, y - h, x + 10, y + 5 - h, x + 20, y - h, Shade(ccc, h)
  36.                     filltri x, y - h, x + 10, y - 5 - h, x + 20, y - h, Shade(ccc, h)
  37.                     ''FRONT-LEFT
  38.                     'filltri x, y - h, x + 10, y + 5 - h, x + 10, y, Shade(ccc, h * .4)
  39.                     'filltri x, y - h, x, y - 5, x + 10, y, Shade(ccc, h * .4)
  40.                     ''FRONT-RIGHT
  41.                     'filltri x + 10, y + 5 - h, x + 10, y, x + 20, y - 5, Shade(ccc, h * 1.2)
  42.                     'filltri x + 10, y + 5 - h, x + 20, y - h, x + 20, y - 5, Shade(ccc, h * 1.2)
  43.                 ELSE
  44.                     COLOR _RGB32(242 + .1 * h, 242 + .1 * h, h)
  45.                     filltri2 x, y - h, x + 10, y + 5 - h, x + 20, y - h
  46.                     filltri2 x, y - h, x + 10, y - 5 - h, x + 20, y - h
  47.                     'FRONT-LEFT
  48.                     COLOR _RGB32(255, 80, 0)
  49.                     filltri2 x, y - h, x + 10, y + 5 - h, x + 10, y
  50.                     filltri2 x, y - h, x, y - 5, x + 10, y
  51.                     COLOR _RGB32(255, 150, 0)
  52.                     filltri2 x + 10, y + 5 - h, x + 10, y, x + 20, y - 5
  53.                     filltri2 x + 10, y + 5 - h, x + 20, y - h, x + 20, y - 5
  54.                 END IF
  55.  
  56.                 IF INKEY$ = CHR$(27) THEN SYSTEM
  57.             NEXT
  58.         NEXT
  59.         _DISPLAY
  60.         IF iconSetup = 0 THEN iconSetup = -1: _ICON _DEST
  61.         _LIMIT 24 'to compare speeds
  62.     NEXT
  63.  
  64. 'Andy Amaya's modified FillTriangle
  65. SUB filltri2 (xx1, yy1, xx2, yy2, xx3, yy3)
  66.     'make copies before swapping
  67.     x1 = xx1: y1 = yy1: x2 = xx2: y2 = yy2: x3 = xx3: y3 = yy3
  68.     'thanks Andy Amaya!
  69.     'triangle coordinates must be ordered: where x1 < x2 < x3
  70.     IF x2 < x1 THEN SWAP x1, x2: SWAP y1, y2
  71.     IF x3 < x1 THEN SWAP x1, x3: SWAP y1, y3
  72.     IF x3 < x2 THEN SWAP x2, x3: SWAP y2, y3
  73.     IF x1 <> x3 THEN slope1 = (y3 - y1) / (x3 - x1)
  74.  
  75.     'draw the first half of the triangle
  76.     length = x2 - x1
  77.     IF length <> 0 THEN
  78.         slope2 = (y2 - y1) / (x2 - x1)
  79.         FOR x = 0 TO length
  80.             LINE (INT(x + x1), INT(x * slope1 + y1))-(INT(x + x1), INT(x * slope2 + y1))
  81.             'lastx2% = lastx%
  82.             lastx% = INT(x + x1)
  83.         NEXT
  84.     END IF
  85.  
  86.     'draw the second half of the triangle
  87.     y = length * slope1 + y1: length = x3 - x2
  88.     IF length <> 0 THEN
  89.         slope3 = (y3 - y2) / (x3 - x2)
  90.         FOR x = 0 TO length
  91.             'IF INT(x + x2) <> lastx% AND INT(x + x2) <> lastx2% THEN  'works! but need 2nd? check
  92.             IF INT(x + x2) <> lastx% THEN
  93.                 LINE (INT(x + x2), INT(x * slope1 + y))-(INT(x + x2), INT(x * slope3 + y2))
  94.             END IF
  95.         NEXT
  96.     END IF
  97.  
  98. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  99. SUB filltri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  100.     a = _NEWIMAGE(1, 1, 32)
  101.     _DEST a
  102.     PSET (0, 0), K
  103.     _DEST 0
  104.     _MAPTRIANGLE (0, 0)-(0, 0)-(0, 0), a TO(x1, y1)-(x2, y2)-(x3, y3)
  105.     _FREEIMAGE a '<<< this is important!
  106.  
  107. FUNCTION Shade~& (WhichColor~&, ByHowMuch%)
  108.     Shade~& = _RGB32(_RED32(WhichColor~&) * (ByHowMuch% / 100), _GREEN32(WhichColor~&) * (ByHowMuch% / 100), _BLUE32(WhichColor~&) * (ByHowMuch% / 100))
  109.  
  110. 'Functions below come from p5js.bas
  111. FUNCTION hsb~& (__H AS _FLOAT, __S AS _FLOAT, __B AS _FLOAT, A AS _FLOAT)
  112.     DIM H AS _FLOAT, S AS _FLOAT, B AS _FLOAT
  113.  
  114.     H = map(__H, 0, 255, 0, 360)
  115.     S = map(__S, 0, 255, 0, 1)
  116.     B = map(__B, 0, 255, 0, 1)
  117.  
  118.     IF S = 0 THEN
  119.         hsb~& = _RGBA32(B * 255, B * 255, B * 255, A)
  120.         EXIT FUNCTION
  121.     END IF
  122.  
  123.     DIM fmx AS _FLOAT, fmn AS _FLOAT
  124.     DIM fmd AS _FLOAT, iSextant AS INTEGER
  125.     DIM imx AS INTEGER, imd AS INTEGER, imn AS INTEGER
  126.  
  127.     IF B > .5 THEN
  128.         fmx = B - (B * S) + S
  129.         fmn = B + (B * S) - S
  130.     ELSE
  131.         fmx = B + (B * S)
  132.         fmn = B - (B * S)
  133.     END IF
  134.  
  135.     iSextant = INT(H / 60)
  136.  
  137.     IF H >= 300 THEN
  138.         H = H - 360
  139.     END IF
  140.  
  141.     H = H / 60
  142.     H = H - (2 * INT(((iSextant + 1) MOD 6) / 2))
  143.  
  144.     IF iSextant MOD 2 = 0 THEN
  145.         fmd = (H * (fmx - fmn)) + fmn
  146.     ELSE
  147.         fmd = fmn - (H * (fmx - fmn))
  148.     END IF
  149.  
  150.     imx = _ROUND(fmx * 255)
  151.     imd = _ROUND(fmd * 255)
  152.     imn = _ROUND(fmn * 255)
  153.  
  154.     SELECT CASE INT(iSextant)
  155.         CASE 1
  156.             hsb~& = _RGBA32(imd, imx, imn, A)
  157.         CASE 2
  158.             hsb~& = _RGBA32(imn, imx, imd, A)
  159.         CASE 3
  160.             hsb~& = _RGBA32(imn, imd, imx, A)
  161.         CASE 4
  162.             hsb~& = _RGBA32(imd, imn, imx, A)
  163.         CASE 5
  164.             hsb~& = _RGBA32(imx, imn, imd, A)
  165.         CASE ELSE
  166.             hsb~& = _RGBA32(imx, imd, imn, A)
  167.     END SELECT
  168.  
  169.  
  170. FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  171.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  172.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: Cube Wave
« Reply #7 on: March 14, 2018, 06:55:36 pm »
All this code are nice.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Cube Wave
« Reply #8 on: March 14, 2018, 10:30:59 pm »
Did someone say "Trippy":

Code: QB64: [Select]
  1. _TITLE "Trippy Wave bplus 2018-03-14"
  2. ' mod Gold Wave
  3. 'translated from SmallBASIC: Goldwave by johnno copied and mod by bplus 2018-01-28
  4.  
  5. 'QB64 version 2017 1106/82 (the day before they switched to version 1.2)
  6. CONST xmax = 600
  7. CONST ymax = 480
  8. SCREEN _NEWIMAGE(xmax, ymax, 32)
  9. _SCREENMOVE 360, 60
  10. DIM SHARED cN, pR, pG, pB
  11.  
  12.     resetPlasma
  13.     FOR t = 1 TO 60 STEP .1 '< changed
  14.         toggle = (toggle + 1) MOD 16
  15.         IF toggle MOD 16 = 0 THEN CLS
  16.         CLS 'changed
  17.         FOR y1 = 0 TO 24
  18.             FOR x1 = 0 TO 24
  19.                 x = (12 * (24 - x1)) + (12 * y1)
  20.                 y = (-6 * (24 - x1)) + (6 * y1) + 300
  21.                 d = ((10 - x1) ^ 2 + (10 - y1) ^ 2) ^ .5
  22.                 h = 60 * SIN(x1 / 4 + t) + 65
  23.                 IF t > 10 AND t < 20 THEN h = 60 * SIN(y1 / 4 + t) + 65
  24.                 IF t > 20 AND t < 30 THEN h = 60 * SIN((x1 - y1) / 4 + t) + 65
  25.                 IF t > 30 AND t < 40 THEN h = 30 * SIN(x1 / 2 + t) + 30 * SIN(y1 / 2 + t) + 65
  26.                 IF t > 40 AND t < 50 THEN h = 60 * SIN((x1 + y1) / 4 + t) + 65
  27.                 IF t > 50 AND t < 60 THEN h = 60 * SIN(d * .3 + t) + 65
  28.                 'TOP
  29.                 ccc&& = changePlasma
  30.                 filltri x, y - h, x + 10, y + 5 - h, x + 20, y - h, ccc&&
  31.                 filltri x, y - h, x + 10, y - 5 - h, x + 20, y - h, ccc&&
  32.                 'FRONT-LEFT
  33.                 ccc = _RGBA32(200, 200, 200, 80)
  34.                 filltri x, y - h, x + 10, y + 5 - h, x + 10, y, ccc
  35.                 filltri x, y - h, x, y - 5, x + 10, y, ccc
  36.                 'FRONT-RIGHT
  37.                 ccc = _RGBA32(155, 155, 155, 80)
  38.                 filltri x + 10, y + 5 - h, x + 10, y, x + 20, y - 5, ccc
  39.                 filltri x + 10, y + 5 - h, x + 20, y - h, x + 20, y - 5, ccc
  40.                 IF INKEY$ = CHR$(27) THEN END
  41.             NEXT
  42.         NEXT
  43.         _DISPLAY
  44.         _LIMIT 20
  45.     NEXT
  46.  
  47. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  48. SUB filltri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  49.     a& = _NEWIMAGE(1, 1, 32)
  50.     _DEST a&
  51.     PSET (0, 0), K
  52.     _DEST 0
  53.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  54.     _FREEIMAGE a& '<<< this is important!
  55.  
  56. FUNCTION changePlasma&& ()
  57.     cN = cN + 1
  58.     changePlasma&& = _RGB32(127 + 127 * SIN(pR * cN), 127 + 127 * SIN(pG * cN), 127 + 127 * SIN(pB * cN))
  59.  
  60. SUB resetPlasma ()
  61.     pR = .1 * RND ^ 2: pG = .1 * RND ^ 2: pB = .1 * RND ^ 2
  62.  
Trippy Wave.PNG
* Trippy Wave.PNG (Filesize: 48.23 KB, Dimensions: 601x495, Views: 490)
« Last Edit: March 14, 2018, 10:34:10 pm by bplus »

FellippeHeitor

  • Guest
Re: Cube Wave
« Reply #9 on: March 15, 2018, 08:40:50 am »
Where's your seizure warning, man?

FellippeHeitor

  • Guest
Re: Cube Wave
« Reply #10 on: March 19, 2018, 01:24:26 pm »
Smoother color morphing.

Code: QB64: [Select]
  1. _TITLE "Trippy Bedsheet Swing With Morphing Colors"
  2. 'translated from SmallBASIC: Goldwave by johnno copied and mod by bplus 2018-01-28
  3. 'trippy bedsheet mod by fellippeheitor 2018-03-14
  4.  
  5. CONST xmax = 600
  6. CONST ymax = 480
  7. SCREEN _NEWIMAGE(xmax, ymax, 32)
  8. _SCREENMOVE 360, 60
  9. '_FULLSCREEN _SQUAREPIXELS , _SMOOTH
  10.  
  11. '                  compare fill triangle subs:  one uses very simple  _MAPTRIANGLE opt = 1
  12. '                                               2nd uses primative line graphic0s  opt <> 1
  13.  
  14.  
  15. opt = 1 ' << opt 1 uses _MAPTRIANGLE to fill triangles, any other uses line filled triangles
  16.  
  17. DIM angle
  18.     FOR t = 50.5 TO 56.7 STEP .01 '< changed
  19.         CLS 'changed
  20.         ccc = hsb(angle, 127, 127, 255)
  21.         angle = angle + .1
  22.         IF angle > 359 THEN angle = 0
  23.         FOR y1 = 0 TO 24
  24.             FOR x1 = 0 TO 24
  25.                 x = (12 * (24 - x1)) + (12 * y1)
  26.                 y = (-6 * (24 - x1)) + (6 * y1) + 300
  27.                 d = ((10 - x1) ^ 2 + (10 - y1) ^ 2) ^ .5
  28.                 h = 60 * SIN(x1 / 4 + t) + 65
  29.                 IF t > 10 AND t < 20 THEN h = 60 * SIN(y1 / 4 + t) + 65
  30.                 IF t > 20 AND t < 30 THEN h = 60 * SIN((x1 - y1) / 4 + t) + 65
  31.                 IF t > 30 AND t < 40 THEN h = 30 * SIN(x1 / 2 + t) + 30 * SIN(y1 / 2 + t) + 65
  32.                 IF t > 40 AND t < 50 THEN h = 60 * SIN((x1 + y1) / 4 + t) + 65
  33.                 IF t > 50 AND t < 60 THEN h = 60 * SIN(d * .3 + t) + 65
  34.                 IF opt = 1 THEN
  35.                     'TOP
  36.                     filltri x, y - h, x + 10, y + 5 - h, x + 20, y - h, Shade(ccc, h)
  37.                     filltri x, y - h, x + 10, y - 5 - h, x + 20, y - h, Shade(ccc, h)
  38.                     ''FRONT-LEFT
  39.                     'filltri x, y - h, x + 10, y + 5 - h, x + 10, y, Shade(ccc, h * .4)
  40.                     'filltri x, y - h, x, y - 5, x + 10, y, Shade(ccc, h * .4)
  41.                     ''FRONT-RIGHT
  42.                     'filltri x + 10, y + 5 - h, x + 10, y, x + 20, y - 5, Shade(ccc, h * 1.2)
  43.                     'filltri x + 10, y + 5 - h, x + 20, y - h, x + 20, y - 5, Shade(ccc, h * 1.2)
  44.                 ELSE
  45.                     COLOR _RGB32(242 + .1 * h, 242 + .1 * h, h)
  46.                     filltri2 x, y - h, x + 10, y + 5 - h, x + 20, y - h
  47.                     filltri2 x, y - h, x + 10, y - 5 - h, x + 20, y - h
  48.                     'FRONT-LEFT
  49.                     COLOR _RGB32(255, 80, 0)
  50.                     filltri2 x, y - h, x + 10, y + 5 - h, x + 10, y
  51.                     filltri2 x, y - h, x, y - 5, x + 10, y
  52.                     COLOR _RGB32(255, 150, 0)
  53.                     filltri2 x + 10, y + 5 - h, x + 10, y, x + 20, y - 5
  54.                     filltri2 x + 10, y + 5 - h, x + 20, y - h, x + 20, y - 5
  55.                 END IF
  56.  
  57.                 IF INKEY$ = CHR$(27) THEN SYSTEM
  58.             NEXT
  59.         NEXT
  60.         _DISPLAY
  61.         IF iconSetup = 0 THEN iconSetup = -1: _ICON _DEST
  62.         _LIMIT 60 'to compare speeds
  63.     NEXT
  64.  
  65. 'Andy Amaya's modified FillTriangle
  66. SUB filltri2 (xx1, yy1, xx2, yy2, xx3, yy3)
  67.     'make copies before swapping
  68.     x1 = xx1: y1 = yy1: x2 = xx2: y2 = yy2: x3 = xx3: y3 = yy3
  69.     'thanks Andy Amaya!
  70.     'triangle coordinates must be ordered: where x1 < x2 < x3
  71.     IF x2 < x1 THEN SWAP x1, x2: SWAP y1, y2
  72.     IF x3 < x1 THEN SWAP x1, x3: SWAP y1, y3
  73.     IF x3 < x2 THEN SWAP x2, x3: SWAP y2, y3
  74.     IF x1 <> x3 THEN slope1 = (y3 - y1) / (x3 - x1)
  75.  
  76.     'draw the first half of the triangle
  77.     length = x2 - x1
  78.     IF length <> 0 THEN
  79.         slope2 = (y2 - y1) / (x2 - x1)
  80.         FOR x = 0 TO length
  81.             LINE (INT(x + x1), INT(x * slope1 + y1))-(INT(x + x1), INT(x * slope2 + y1))
  82.             'lastx2% = lastx%
  83.             lastx% = INT(x + x1)
  84.         NEXT
  85.     END IF
  86.  
  87.     'draw the second half of the triangle
  88.     y = length * slope1 + y1: length = x3 - x2
  89.     IF length <> 0 THEN
  90.         slope3 = (y3 - y2) / (x3 - x2)
  91.         FOR x = 0 TO length
  92.             'IF INT(x + x2) <> lastx% AND INT(x + x2) <> lastx2% THEN  'works! but need 2nd? check
  93.             IF INT(x + x2) <> lastx% THEN
  94.                 LINE (INT(x + x2), INT(x * slope1 + y))-(INT(x + x2), INT(x * slope3 + y2))
  95.             END IF
  96.         NEXT
  97.     END IF
  98.  
  99. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  100. SUB filltri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  101.     a = _NEWIMAGE(1, 1, 32)
  102.     _DEST a
  103.     PSET (0, 0), K
  104.     _DEST 0
  105.     _MAPTRIANGLE (0, 0)-(0, 0)-(0, 0), a TO(x1, y1)-(x2, y2)-(x3, y3)
  106.     _FREEIMAGE a '<<< this is important!
  107.  
  108. FUNCTION Shade~& (WhichColor~&, ByHowMuch%)
  109.     Shade~& = _RGB32(_RED32(WhichColor~&) * (ByHowMuch% / 100), _GREEN32(WhichColor~&) * (ByHowMuch% / 100), _BLUE32(WhichColor~&) * (ByHowMuch% / 100))
  110.  
  111. FUNCTION hsb~& (__H AS _FLOAT, __S AS _FLOAT, __B AS _FLOAT, A AS _FLOAT)
  112.     DIM H AS _FLOAT, S AS _FLOAT, B AS _FLOAT
  113.  
  114.     H = map(__H, 0, 255, 0, 360)
  115.     S = map(__S, 0, 255, 0, 1)
  116.     B = map(__B, 0, 255, 0, 1)
  117.  
  118.     IF S = 0 THEN
  119.         hsb~& = _RGBA32(B * 255, B * 255, B * 255, A)
  120.         EXIT FUNCTION
  121.     END IF
  122.  
  123.     DIM fmx AS _FLOAT, fmn AS _FLOAT
  124.     DIM fmd AS _FLOAT, iSextant AS INTEGER
  125.     DIM imx AS INTEGER, imd AS INTEGER, imn AS INTEGER
  126.  
  127.     IF B > .5 THEN
  128.         fmx = B - (B * S) + S
  129.         fmn = B + (B * S) - S
  130.     ELSE
  131.         fmx = B + (B * S)
  132.         fmn = B - (B * S)
  133.     END IF
  134.  
  135.     iSextant = INT(H / 60)
  136.  
  137.     IF H >= 300 THEN
  138.         H = H - 360
  139.     END IF
  140.  
  141.     H = H / 60
  142.     H = H - (2 * INT(((iSextant + 1) MOD 6) / 2))
  143.  
  144.     IF iSextant MOD 2 = 0 THEN
  145.         fmd = (H * (fmx - fmn)) + fmn
  146.     ELSE
  147.         fmd = fmn - (H * (fmx - fmn))
  148.     END IF
  149.  
  150.     imx = _ROUND(fmx * 255)
  151.     imd = _ROUND(fmd * 255)
  152.     imn = _ROUND(fmn * 255)
  153.  
  154.     SELECT CASE INT(iSextant)
  155.         CASE 1
  156.             hsb~& = _RGBA32(imd, imx, imn, A)
  157.         CASE 2
  158.             hsb~& = _RGBA32(imn, imx, imd, A)
  159.         CASE 3
  160.             hsb~& = _RGBA32(imn, imd, imx, A)
  161.         CASE 4
  162.             hsb~& = _RGBA32(imd, imn, imx, A)
  163.         CASE 5
  164.             hsb~& = _RGBA32(imx, imn, imd, A)
  165.         CASE ELSE
  166.             hsb~& = _RGBA32(imx, imd, imn, A)
  167.     END SELECT
  168.  
  169.  
  170. FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  171.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  172.  
« Last Edit: March 19, 2018, 01:29:09 pm by FellippeHeitor »

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
Re: Cube Wave
« Reply #11 on: March 20, 2018, 05:07:36 am »
Nice Fellippe!
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 + ...
Re: Cube Wave
« Reply #12 on: March 20, 2018, 09:08:08 am »
It's nice but I don't see anybody being awoken by it.

Now a ball might be something!

Where is Pete?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Cube Wave
« Reply #13 on: March 20, 2018, 10:55:28 am »
Trippy Wave Ball Mod:
Code: QB64: [Select]
  1. _TITLE "Trippy Wave Ball Mod bplus 2018-03-20"
  2. '2018-03-20 just screwing around more with Ball stuff
  3. ' mod Gold Wave
  4. 'translated from SmallBASIC: Goldwave by johnno copied and mod by bplus 2018-01-28
  5.  
  6. 'QB64 version 2017 1106/82 (the day before they switched to version 1.2)
  7. CONST xmax = 600
  8. CONST ymax = 480
  9. SCREEN _NEWIMAGE(xmax, ymax, 32)
  10. _SCREENMOVE 360, 60
  11. DIM SHARED cN, pR, pG, pB
  12.  
  13.     resetPlasma
  14.     FOR t = 1 TO 60 STEP .1 '< changed
  15.         toggle = (toggle + 1) MOD 16
  16.         IF toggle MOD 16 = 0 THEN CLS
  17.         CLS 'changed
  18.         FOR y1 = 0 TO 24
  19.             FOR x1 = 0 TO 24
  20.                 x = (12 * (24 - x1)) + (12 * y1)
  21.                 y = (-6 * (24 - x1)) + (6 * y1) + 300
  22.                 d = ((10 - x1) ^ 2 + (10 - y1) ^ 2) ^ .5
  23.                 h = 60 * SIN(x1 / 4 + t) + 65
  24.                 IF t > 10 AND t < 20 THEN h = 60 * SIN(y1 / 4 + t) + 65
  25.                 IF t > 20 AND t < 30 THEN h = 60 * SIN((x1 - y1) / 4 + t) + 65
  26.                 IF t > 30 AND t < 40 THEN h = 30 * SIN(x1 / 2 + t) + 30 * SIN(y1 / 2 + t) + 65
  27.                 IF t > 40 AND t < 50 THEN h = 60 * SIN((x1 + y1) / 4 + t) + 65
  28.                 IF t > 50 AND t < 60 THEN h = 60 * SIN(d * .3 + t) + 65
  29.                 'TOP
  30.                 FOR r = 20 TO 1 STEP -4
  31.                     ccc&& = changePlasma
  32.                     fcirc x + 10, y - h, r
  33.                 NEXT
  34.                 IF INKEY$ = CHR$(27) THEN END
  35.             NEXT
  36.         NEXT
  37.         _DISPLAY
  38.         _LIMIT 20
  39.     NEXT
  40.  
  41. FUNCTION changePlasma&& ()
  42.     cN = cN + .05
  43.     COLOR _RGB32(127 + 127 * SIN(pR * cN), 127 + 127 * SIN(pG * cN), 127 + 127 * SIN(pB * cN))
  44.  
  45. SUB resetPlasma ()
  46.     pR = .1 * RND ^ 2: pG = .1 * RND ^ 2: pB = .1 * RND ^ 2
  47.  
  48. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  49. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  50.     DIM subRadius AS LONG, RadiusError AS LONG
  51.     DIM X AS LONG, Y AS LONG
  52.  
  53.     subRadius = ABS(R)
  54.     RadiusError = -subRadius
  55.     X = subRadius
  56.     Y = 0
  57.  
  58.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  59.  
  60.     ' Draw the middle span here so we don't draw it twice in the main loop,
  61.     ' which would be a problem with blending turned on.
  62.     LINE (CX - X, CY)-(CX + X, CY), , BF
  63.  
  64.     WHILE X > Y
  65.         RadiusError = RadiusError + Y * 2 + 1
  66.         IF RadiusError >= 0 THEN
  67.             IF X <> Y + 1 THEN
  68.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  69.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  70.             END IF
  71.             X = X - 1
  72.             RadiusError = RadiusError - X * 2
  73.         END IF
  74.         Y = Y + 1
  75.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  76.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  77.     WEND
  78.  
Trippy Wave Ball Mod.PNG
* Trippy Wave Ball Mod.PNG (Filesize: 36.49 KB, Dimensions: 605x485, Views: 294)