Author Topic: Moire with triangle sheets  (Read 3725 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Moire with triangle sheets
« on: March 04, 2019, 09:39:48 pm »
Just ran into this today:
Code: QB64: [Select]
  1. _TITLE "Moire with triangle sheets" ' B+ 2019-03-04
  2.  
  3. CONST sq3 = 1.732050808
  4. CONST xmax = 700
  5. CONST ymax = 700
  6. CONST cx = xmax / 2
  7. CONST cy = ymax / 2
  8. CONST white = &HFFFFFFFF
  9. CONST black = &HFF000000
  10.  
  11. SCREEN _NEWIMAGE(xmax, ymax, 32)
  12. _SCREENMOVE 100, 20
  13.  
  14. tsheet& = _NEWIMAGE(xmax, ymax, 32)
  15. _DEST tsheet&
  16. s = 10
  17. sd2 = 5
  18. sh = sd2 * sq3
  19. FOR y = 0 TO ymax STEP sh
  20.     yoff = (yoff + 1) MOD 2
  21.     FOR x = yoff * sd2 TO xmax STEP s
  22.         ftri tsheet&, x, y + sh, x + s, y + sh, x + sd2, y, white
  23.     NEXT
  24.  
  25. scale = 1
  26. WHILE _KEYDOWN(27) = 0
  27.     CLS
  28.     _PUTIMAGE , tsheet&, 0
  29.     RotoZoom2 cx, cy, tsheet&, scale, scale, a
  30.     a = a + _PI(1 / 180)
  31.     _DISPLAY
  32.     _LIMIT 10
  33.  
  34. SUB RotoZoom2 (X AS LONG, Y AS LONG, Image AS LONG, xScale AS SINGLE, yScale, 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.     sinr! = SIN(-Rotation): cosr! = COS(-Rotation)
  41.     FOR i& = 0 TO 3
  42.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * xScale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * yScale + Y
  43.         px(i&) = x2&: py(i&) = y2&
  44.     NEXT
  45.     _MAPTRIANGLE (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  46.     _MAPTRIANGLE (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  47.  
  48.  
  49. ' 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
  50. SUB ftri (dh&, x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  51.     a& = _NEWIMAGE(1, 1, 32)
  52.     _DEST a&
  53.     PSET (0, 0), K
  54.     _DEST dh&
  55.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  56.     _FREEIMAGE a& '<<< this is important!
  57.  
  58.  
Moire with triangle sheets.PNG

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Moire with triangle sheets
« Reply #1 on: March 06, 2019, 01:42:07 am »
Amazing bplus! It is a nice illusion...Looking at this for a minute causes a pain in my head.
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: Moire with triangle sheets
« Reply #2 on: March 06, 2019, 05:08:12 pm »
More control over where the over-sheet lays as noted in comments:
Code: QB64: [Select]
  1. _TITLE "Moire with triangle sheets mod 2" ' B+ 2019-03-06
  2.  
  3. ' Now the middle of the over sheet is where the mouse is
  4. ' and the angle the sheet is turned is the same angle
  5. ' the mouse is to the center of screen. Theoretically
  6. ' if you put the mouse dead center of the screen the 2 sheets
  7. ' will coincide and look like one sheet. But as mouse closes in
  8. ' at center the angle swing becomes more sensitive to slightest
  9. ' changes.
  10.  
  11. CONST sq3 = 1.732050808
  12. CONST xmax = 700
  13. CONST ymax = 700
  14. CONST cx = xmax / 2
  15. CONST cy = ymax / 2
  16. CONST white = &HFFFFFFFF
  17. CONST black = &HFF000000
  18.  
  19. SCREEN _NEWIMAGE(xmax, ymax, 32)
  20. _SCREENMOVE 100, 20
  21.  
  22. tsheet& = _NEWIMAGE(xmax, ymax, 32)
  23. _DEST tsheet&
  24. s = 10
  25. sd2 = 5
  26. sh = sd2 * sq3
  27. FOR y = 0 TO ymax STEP sh
  28.     yoff = (yoff + 1) MOD 2
  29.     FOR x = yoff * sd2 TO xmax STEP s
  30.         ftri tsheet&, x, y + sh, x + s, y + sh, x + sd2, y, white
  31.     NEXT
  32.  
  33. scale = 1
  34. WHILE _KEYDOWN(27) = 0
  35.     CLS
  36.     _PUTIMAGE , tsheet&, 0
  37.     mx = _MOUSEX: my = _MOUSEY
  38.     angle = _ATAN2(my - cx, mx - cy)
  39.     RotoZoom2 mx, my, tsheet&, scale, scale, angle
  40.     _DISPLAY
  41.     _LIMIT 10
  42.  
  43. SUB RotoZoom2 (X AS LONG, Y AS LONG, Image AS LONG, xScale AS SINGLE, yScale, Rotation AS SINGLE)
  44.     DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
  45.     W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
  46.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  47.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  48.     'sinr! = SIN(-Rotation / 57.2957795131): cosr! = COS(-Rotation / 57.2957795131)
  49.     sinr! = SIN(-Rotation): cosr! = COS(-Rotation)
  50.     FOR i& = 0 TO 3
  51.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * xScale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * yScale + Y
  52.         px(i&) = x2&: py(i&) = y2&
  53.     NEXT
  54.     _MAPTRIANGLE (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  55.     _MAPTRIANGLE (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  56.  
  57.  
  58. ' 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
  59. SUB ftri (dh&, x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  60.     a& = _NEWIMAGE(1, 1, 32)
  61.     _DEST a&
  62.     PSET (0, 0), K
  63.     _DEST dh&
  64.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  65.     _FREEIMAGE a& '<<< this is important!
  66.  
  67.  
« Last Edit: March 06, 2019, 05:15:23 pm by bplus »

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: Moire with triangle sheets
« Reply #3 on: March 06, 2019, 06:05:01 pm »
nice bplus, can you add colors ?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Moire with triangle sheets
« Reply #4 on: March 06, 2019, 06:24:46 pm »
nice bplus, can you add colors ?

Yes I can add color:
Code: QB64: [Select]
  1. _TITLE "Moire with triangle sheets mod 3" ' B+ 2019-03-06
  2.  
  3. ' Now the middle of the over sheet is where the mouse is
  4. ' and the angle the sheet is turned is the same angle
  5. ' the mouse is to the center of screen. Theoretically
  6. ' if you put the mouse dead center of the screen the 2 sheets
  7. ' will coincide and look like one sheet. But as mouse closes in
  8. ' at center the angle swing becomes more sensitive to slightest
  9. ' changes.
  10.  
  11. ' mod #3 try it with color
  12.  
  13. CONST sq3 = 1.732050808
  14. CONST xmax = 700
  15. CONST ymax = 700
  16. CONST cx = xmax / 2
  17. CONST cy = ymax / 2
  18. CONST white = &HFFFFFFFF
  19. CONST black = &HFF000000
  20. CONST red = &HFFFF0000
  21. CONST grn = &HFF00FF00
  22. CONST blu = &HFF0000FF
  23.  
  24. SCREEN _NEWIMAGE(xmax, ymax, 32)
  25. _SCREENMOVE 100, 20
  26. pal(0) = red: pal(1) = grn: pal(2) = blu
  27. tsheet& = _NEWIMAGE(xmax, ymax, 32)
  28. _DEST tsheet&
  29. s = 10
  30. sd2 = 5
  31. sh = sd2 * sq3
  32. FOR y = 0 TO ymax STEP sh
  33.     yoff = (yoff + 1) MOD 2
  34.     ccy = (ccy + 1) MOD 3
  35.     ccx = ccy
  36.     FOR x = yoff * sd2 TO xmax STEP s
  37.         ftri tsheet&, x, y + sh, x + s, y + sh, x + sd2, y, pal(ccx)
  38.         ccx = (ccx + 1) MOD 3
  39.     NEXT
  40.  
  41. scale = 1
  42. WHILE _KEYDOWN(27) = 0
  43.     CLS
  44.     _PUTIMAGE , tsheet&, 0
  45.     mx = _MOUSEX: my = _MOUSEY
  46.     angle = _ATAN2(my - cx, mx - cy)
  47.     RotoZoom2 mx, my, tsheet&, scale, scale, angle
  48.     _DISPLAY
  49.     _LIMIT 10
  50.  
  51. SUB RotoZoom2 (X AS LONG, Y AS LONG, Image AS LONG, xScale AS SINGLE, yScale, Rotation AS SINGLE)
  52.     DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
  53.     W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
  54.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  55.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  56.     'sinr! = SIN(-Rotation / 57.2957795131): cosr! = COS(-Rotation / 57.2957795131)
  57.     sinr! = SIN(-Rotation): cosr! = COS(-Rotation)
  58.     FOR i& = 0 TO 3
  59.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * xScale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * yScale + Y
  60.         px(i&) = x2&: py(i&) = y2&
  61.     NEXT
  62.     _MAPTRIANGLE (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  63.     _MAPTRIANGLE (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  64.  
  65.  
  66. ' 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
  67. SUB ftri (dh&, x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  68.     a& = _NEWIMAGE(1, 1, 32)
  69.     _DEST a&
  70.     PSET (0, 0), K
  71.     _DEST dh&
  72.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  73.     _FREEIMAGE a& '<<< this is important!
  74.  
  75.  

Reminds me of a Magic Eye of Rubik's Cubes.
« Last Edit: March 06, 2019, 06:27:10 pm by bplus »