Author Topic: Swizzle  (Read 4039 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Swizzle
« on: May 29, 2021, 01:24:17 pm »
A quickie:
Code: QB64: [Select]
  1. _Title "Swizzle" ' b+ 2021-05-29
  2. Const Xmax = 600, Ymax = 600, cxy = 300, Pi = _Pi
  3. Screen _NewImage(Xmax, Ymax, 32)
  4. _Delay .25
  5. Dim vScreenR(Xmax, Ymax), vScreenG(Xmax, Ymax), vScreenB(Xmax, Ymax)
  6. restart:
  7. r = Rnd * Rnd: g = Rnd * Rnd: b = Rnd * Rnd
  8. For x = 0 To Xmax
  9.     Line (x, 0)-(x, Ymax), _RGB32(128 + 128 * Sin(r * x), 128 + 128 * Sin(g * x), 128 + 128 * Sin(b * x))
  10.     For y = 0 To Ymax
  11.         vScreenR(x, y) = 128 + 128 * Sin(r * x)
  12.         vScreenG(x, y) = 128 + 128 * Sin(g * x)
  13.         vScreenB(x, y) = 128 + 128 * Sin(b * x)
  14.     Next
  15. swizzle = Rnd * .5 + .8
  16. _Title "Swizzle @" + _Trim$(Str$(swizzle))
  17. For radius = 1 To 200
  18.     For a = 0 To 2 * Pi Step 1 / (2 * Pi * radius)
  19.         x = Int(cxy + radius * Cos(a))
  20.         y = Int(cxy + radius * Sin(a))
  21.         r = vScreenR(x, y)
  22.         g = vScreenG(x, y)
  23.         b = vScreenB(x, y)
  24.         PSet (cxy + radius * Cos(a + radius ^ swizzle * Pi / 180), cxy + radius * Sin(a + radius ^ swizzle * Pi / 180)), _RGB32(r, g, b)
  25.     Next
  26. GoTo restart
  27.  

 
Swizzle number.PNG


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Swizzle
« Reply #1 on: May 29, 2021, 01:36:14 pm »
Here's a variation:
Code: QB64: [Select]
  1. _Title "Swizzle YY" ' b+ 2021-05-29
  2. Const Xmax = 600, Ymax = 600, cxy = 300, Pi = _Pi
  3. Screen _NewImage(Xmax, Ymax, 32)
  4. _Delay .25
  5. Dim vScreenR(Xmax, Ymax), vScreenG(Xmax, Ymax), vScreenB(Xmax, Ymax)
  6.  
  7. For x = 0 To Xmax
  8.     If x < (.5 * Xmax) Then
  9.         r = 0: g = 0: b = 0
  10.     Else
  11.         r = 255: g = 255: b = 255
  12.     End If
  13.     Line (x, 0)-(x, Ymax), _RGB32(r, g, b)
  14.     For y = 0 To Ymax
  15.         vScreenR(x, y) = r
  16.         vScreenG(x, y) = g
  17.         vScreenB(x, y) = b
  18.     Next
  19. swizzle = 1.
  20. _Title "Swizzle @" + _Trim$(Str$(swizzle))
  21. For radius = 1 To 180
  22.     For a = 0 To 2 * Pi Step 1 / (2 * Pi * radius)
  23.         x = Int(cxy + radius * Cos(a))
  24.         y = Int(cxy + radius * Sin(a))
  25.         r = vScreenR(x, y)
  26.         g = vScreenG(x, y)
  27.         b = vScreenB(x, y)
  28.         PSet (cxy + radius * Cos(a + radius ^ swizzle * Pi / 180), cxy + radius * Sin(a + radius ^ swizzle * Pi / 180)), _RGB32(r, g, b)
  29.     Next
  30.  
  31.  
  32.  

Remind anybody of anything?

EDIT: adjust radius
« Last Edit: May 29, 2021, 01:47:04 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Swizzle
« Reply #2 on: May 29, 2021, 02:22:48 pm »
The picture remind me of my little screen eater demo I did a few years back, which basically simulated a black hole in the center of the screen which rotated and flushed the image on the screen down the drain.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Swizzle
« Reply #3 on: May 29, 2021, 02:48:32 pm »
Nice effect!  I just had to give it spin...

- Dav

Edit: Changed _LIMIT to 15, went too fast before.
 
Code: QB64: [Select]
  1. _TITLE "Swizzle" ' b+ 2021-05-29
  2. CONST Xmax = 600, Ymax = 600, cxy = 300, Pi = _PI
  3. SCREEN _NEWIMAGE(Xmax, Ymax, 32)
  4. _DELAY .25
  5. DIM vScreenR(Xmax, Ymax), vScreenG(Xmax, Ymax), vScreenB(Xmax, Ymax)
  6.  
  7. r = RND * RND: g = RND * RND: b = RND * RND
  8. FOR x = 0 TO Xmax
  9.     LINE (x, 0)-(x, Ymax), _RGB32(128 + 128 * SIN(r * x), 128 + 128 * SIN(g * x), 128 + 128 * SIN(b * x))
  10.     FOR y = 0 TO Ymax
  11.         vScreenR(x, y) = 128 + 128 * SIN(r * x)
  12.         vScreenG(x, y) = 128 + 128 * SIN(g * x)
  13.         vScreenB(x, y) = 128 + 128 * SIN(b * x)
  14.     NEXT
  15. swizzle = RND * .5 + .8
  16.  
  17. FOR radius = 1 TO 200
  18.     FOR a = 0 TO 2 * Pi STEP 1 / (2 * Pi * radius)
  19.         x = INT(cxy + radius * COS(a))
  20.         y = INT(cxy + radius * SIN(a))
  21.         r = vScreenR(x, y)
  22.         g = vScreenG(x, y)
  23.         b = vScreenB(x, y)
  24.         PSET (cxy + radius * COS(a + radius ^ swizzle * Pi / 180), cxy + radius * SIN(a + radius ^ swizzle * Pi / 180)), _RGB32(r, g, b)
  25.     NEXT
  26.  
  27.     s& = _COPYIMAGE(_DISPLAY)
  28.     RotoZoom _WIDTH / 2, _HEIGHT / 2, s&, 1, a
  29.     a = a + 1: IF a >= 360 THEN a = a - 360
  30.     _FREEIMAGE s&
  31.     _DISPLAY: _LIMIT 15
  32.  
  33.  
  34. SUB RotoZoom (X AS LONG, Y AS LONG, Image AS LONG, Scale AS SINGLE, Rotation AS SINGLE)
  35.     DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
  36.     W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
  37.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  38.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  39.     sinr! = SIN(-Rotation / 57.2957795131): cosr! = COS(-Rotation / 57.2957795131)
  40.     FOR i& = 0 TO 3
  41.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * Scale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * Scale + Y
  42.         px(i&) = x2&: py(i&) = y2&
  43.     NEXT
  44.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  45.     _MAPTRIANGLE _SEAMLESS(0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  46.  
  47.  
« Last Edit: May 29, 2021, 04:50:06 pm by Dav »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Swizzle
« Reply #4 on: May 29, 2021, 05:31:56 pm »
Man doing copies of copies really gets raggedy with Rotozoom, I modified Dav's maybe what he was intending?
Code: QB64: [Select]
  1. _Title "Swizzle Spin" ' b+ 2021-05-29 mod Dav mod b+
  2. Const Xmax = 600, Ymax = 600, cxy = 300, Pi = _Pi
  3. Screen _NewImage(Xmax, Ymax, 32)
  4. _Delay .25
  5. Dim vScreenR(Xmax, Ymax), vScreenG(Xmax, Ymax), vScreenB(Xmax, Ymax)
  6. restart:
  7. r = Rnd * Rnd: g = Rnd * Rnd: b = Rnd * Rnd
  8. For x = 0 To Xmax
  9.     Line (x, 0)-(x, Ymax), _RGB32(128 + 128 * Sin(r * x), 128 + 128 * Sin(g * x), 128 + 128 * Sin(b * x))
  10.     For y = 0 To Ymax
  11.         vScreenR(x, y) = 128 + 128 * Sin(r * x)
  12.         vScreenG(x, y) = 128 + 128 * Sin(g * x)
  13.         vScreenB(x, y) = 128 + 128 * Sin(b * x)
  14.     Next
  15. swizzle = Rnd * .5 + .8
  16.  
  17. For radius = 1 To 200
  18.     For a = 0 To 2 * Pi Step 1 / (2 * Pi * radius)
  19.         x = Int(cxy + radius * Cos(a))
  20.         y = Int(cxy + radius * Sin(a))
  21.         r = vScreenR(x, y)
  22.         g = vScreenG(x, y)
  23.         b = vScreenB(x, y)
  24.         PSet (cxy + radius * Cos(a + radius ^ swizzle * Pi / 180), cxy + radius * Sin(a + radius ^ swizzle * Pi / 180)), _RGB32(r, g, b)
  25.     Next
  26. s& = _NewImage(Xmax * 2.2, Ymax * 2.2, 32)
  27. _PutImage , 0, s&
  28.     RotoZoom cxy, cxy, s&, 1, a
  29.     a = a - 3: If a < -360 Then a = 0: _FreeImage s&: GoTo restart
  30.     _Display: _Limit 30
  31.  
  32.  
  33. Sub RotoZoom (X As Long, Y As Long, Image As Long, Scale As Single, Rotation As Single)
  34.     Dim px(3) As Single: Dim py(3) As Single
  35.     W& = _Width(Image&): H& = _Height(Image&)
  36.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  37.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  38.     sinr! = Sin(-Rotation / 57.2957795131): cosr! = Cos(-Rotation / 57.2957795131)
  39.     For i& = 0 To 3
  40.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * Scale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * Scale + Y
  41.         px(i&) = x2&: py(i&) = y2&
  42.     Next
  43.     _MapTriangle _Seamless(0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  44.     _MapTriangle _Seamless(0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& To(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  45.  
  46.  
  47.  
  48.  
« Last Edit: May 29, 2021, 05:39:34 pm by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Swizzle
« Reply #5 on: May 29, 2021, 05:34:33 pm »
Way cool.... Just the thing I need to see at 7:30am on a Sunday morning! Good thing I have my coffee at hand to refocus my optic nerves... LOL

Nay. Cool effect... Does it come in blue? lol
Logic is the beginning of wisdom.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Swizzle
« Reply #6 on: May 29, 2021, 07:38:09 pm »
That's it, bplus!  Very Cool.  Yeah I wanted to get it there, but didn't know exactly how to do it.  Thanks for showing.  I'm definitely saving that one...

- Dav

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Swizzle
« Reply #7 on: May 29, 2021, 08:13:35 pm »
Distorting spacetime creates marbles!
It works better if you plug it in.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Swizzle
« Reply #8 on: May 29, 2021, 09:19:52 pm »
This sort of thing amazes me. I am just about able to solve a right triangle with trig commands...

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Swizzle
« Reply #9 on: May 30, 2021, 04:14:42 am »
@bplus very nice effect! I find it more beautiful when swizzle get values slightly less than 1.
One Question.. Why you have used 2D array... since the color only depends on x,  you can just make it a 1D array.
« Last Edit: May 30, 2021, 04:26:20 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

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Swizzle
« Reply #10 on: May 30, 2021, 11:19:38 am »
Very good points @Ashish here are some changes towards those points:
Code: QB64: [Select]
  1. _Title "Swizzle 2" ' b+ 2021-05-30  Make use of 2D Arrays
  2. Const Xmax = 600, Ymax = 600, cxy = 300, Pi = _Pi
  3. Screen _NewImage(Xmax, Ymax, 32)
  4. _Delay .25
  5. Dim vScreenR(Xmax, Ymax), vScreenG(Xmax, Ymax), vScreenB(Xmax, Ymax)
  6. restart:
  7. r = Rnd * Rnd * .25: g = Rnd * Rnd * .25: b = Rnd * Rnd * .25
  8. For x = 0 To .5 * Xmax
  9.     Line (x, x)-(Xmax - x, Ymax - x), _RGB32(128 + 128 * Sin(r * x), 128 + 128 * Sin(g * x), 128 + 128 * Sin(b * x)), B
  10.     For y = x To Ymax - x
  11.         vScreenR(x, y) = 128 + 128 * Sin(r * x)
  12.         vScreenG(x, y) = 128 + 128 * Sin(g * x)
  13.         vScreenB(x, y) = 128 + 128 * Sin(b * x)
  14.         vScreenR(Xmax - x, y) = 128 + 128 * Sin(r * x)
  15.         vScreenG(Xmax - x, y) = 128 + 128 * Sin(g * x)
  16.         vScreenB(Xmax - x, y) = 128 + 128 * Sin(b * x)
  17.     Next
  18.     For y = x To Xmax - x
  19.         vScreenR(y, x) = 128 + 128 * Sin(r * x)
  20.         vScreenG(y, x) = 128 + 128 * Sin(g * x)
  21.         vScreenB(y, x) = 128 + 128 * Sin(b * x)
  22.         vScreenR(Xmax - y, Ymax - x) = 128 + 128 * Sin(r * x)
  23.         vScreenG(Xmax - y, Ymax - x) = 128 + 128 * Sin(g * x)
  24.         vScreenB(Xmax - y, Ymax - x) = 128 + 128 * Sin(b * x)
  25.     Next
  26. swizzle = Rnd * .2 + .9
  27. _Title "Swizzle @" + _Trim$(Str$(swizzle))
  28. For radius = 1 To 300
  29.     For a = 0 To 2 * Pi Step 1 / (2 * Pi * radius)
  30.         x = Int(cxy + radius * Cos(a))
  31.         y = Int(cxy + radius * Sin(a))
  32.         r = vScreenR(x, y)
  33.         g = vScreenG(x, y)
  34.         b = vScreenB(x, y)
  35.         PSet (cxy + radius * Cos(a + radius ^ swizzle * Pi / 180), cxy + radius * Sin(a + radius ^ swizzle * Pi / 180)), _RGB32(r, g, b)
  36.     Next
  37. GoTo restart
  38.  
  39.  
  40.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Swizzle
« Reply #11 on: May 30, 2021, 01:35:25 pm »
I tried an image of Picasso:
Code: QB64: [Select]
  1. _Title "Swizzle Image" ' b+ 2021-05-30  Make use of 2D Arrays
  2. Const Xmax = 600, Ymax = 600, cxy = 300, Pi = _Pi
  3. Screen _NewImage(Xmax, Ymax, 32)
  4. _Delay .25
  5. Dim As _Unsigned Long vScreen(Xmax, Ymax)
  6. p& = _LoadImage("Picasso.PNG")
  7. restart:
  8. r = .0041: g = .001: b = .0072 ' <<<<<<<<<<<<<<< adjust as needed
  9. For x = 0 To .5 * Xmax
  10.     Line (x, x)-(Xmax - x, Ymax - x), _RGB32(128 - 64 * Sin(r * x), 64 - 64 * Sin(g * x), 128 - 64 * Sin(b * x)), B
  11. _PutImage ((_Width - _Width(p&)) / 2, (_Height - _Height(p&)) / 2)-Step(_Width(p&), _Height(p&)), p&, 0
  12. For y = 0 To Ymax
  13.     For x = 0 To Xmax
  14.         vScreen(x, y) = Point(x, y)
  15.     Next
  16. swizzle = .85
  17. _Title "Swizzle @" + _Trim$(Str$(swizzle))
  18. For radius = 1 To 300
  19.     For a = 0 To 2 * Pi Step 1 / (2 * Pi * radius)
  20.         x = Int(cxy + radius * Cos(a))
  21.         y = Int(cxy + radius * Sin(a))
  22.         PSet (cxy + radius * Cos(a + radius ^ swizzle * Pi / 180), cxy + radius * Sin(a + radius ^ swizzle * Pi / 180)), vScreen(x, y)
  23.     Next
  24.  
  25.  
  26.  
Swizzle Picasso Image.PNG
* Swizzle Picasso Image.PNG (Filesize: 460.7 KB, Dimensions: 599x627, Views: 135)

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Swizzle
« Reply #12 on: May 31, 2021, 07:27:37 am »
@bplus woah! amazing work! :D
if (Me.success) {Me.improve()} else {Me.tryAgain()}


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