Author Topic: Screen Saver #3 Mystic Rectangles  (Read 5354 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Screen Saver #3 Mystic Rectangles
« on: March 01, 2018, 12:33:21 am »
Yep! Another bplus graphics thingy.
Code: QB64: [Select]
  1. _TITLE " *** Screen Saver #3 - Mystic Rectangles *** by bplus 2018-03-01"
  2. ' translated from
  3. ' Screen Saver #3 Mystic Rectangles.bas SmallBASIC 0.12.11 (B+=MGA) 2018-02-28
  4. ' instead of wire frame triangles try solid color rectangles
  5. ' arrays? we don't need no dang arrays!
  6. ' oh to share everything use GOSUBs instead of SUBs
  7.  
  8. CONST xmax = 1200
  9. CONST ymax = 700
  10. SCREEN _NEWIMAGE(xmax, ymax, 32)
  11. _SCREENMOVE 100, 20
  12.  
  13. nT = 150 'number of Things per screen
  14. GOSUB newRect
  15. savex1 = x1: savey1 = y1: savedx1 = dx1: savedy1 = dy1
  16. savex2 = x2: savey2 = y2: savedx2 = dx2: savedy2 = dy2
  17. cN = nT
  18. GOSUB resetPlasma
  19.     CLS
  20.  
  21.     'reset color Number back to beginning + 1
  22.     cN = cN - nT + 1
  23.  
  24.     'reset rect back to beginning and then update it once and save this for next round
  25.     x1 = savex1: y1 = savey1: dx1 = savedx1: dy1 = savedy1
  26.     x2 = savex2: y2 = savey2: dx2 = savedx2: dy2 = savedy2
  27.     GOSUB updateRect
  28.     savex1 = x1: savey1 = y1: savedx1 = dx1: savedy1 = dy1
  29.     savex2 = x2: savey2 = y2: savedx2 = dx2: savedy2 = dy2
  30.  
  31.     FOR j = 1 TO nT
  32.         GOSUB updateRect
  33.         GOSUB changePlasma
  34.         LINE (x1 - 12, y1 - 7)-(x2, y2), , BF
  35.         'inverse image and color
  36.         xx1 = xmax - x1: yy1 = ymax - y1
  37.         xx2 = xmax - x2: yy2 = ymax - y2
  38.         IF xx1 > xx2 THEN SWAP xx1, xx2
  39.         IF yy1 > yy2 THEN SWAP yy1, yy2
  40.         LINE (xx1 - 12, yy1 - 7)-(xx2, yy2), invColor&&, BF
  41.     NEXT
  42.     _DISPLAY
  43.     _LIMIT 10
  44.     k$ = INKEY$
  45.     IF k$ = " " THEN GOSUB resetPlasma
  46.  
  47. newRect:
  48. x1 = RND * xmax
  49. y1 = RND * ymax
  50. dx1 = (RND * 9 + 3) * rdir
  51. dy1 = (RND * 5 + 2) * rdir
  52. x2 = RND * xmax
  53. y2 = RND * ymax
  54. dx2 = (RND * 9 + 3) * rdir
  55. dy2 = (RND * 5 + 2) * rdir
  56. 'keep x1, y1 the lesser corner and x2, y2 the greater
  57. IF x1 > x2 THEN SWAP x1, x2: SWAP dx1, dx2
  58. IF y1 > y2 THEN SWAP y1, y2: SWAP dy1, dy2
  59.  
  60. updateRect:
  61. IF x1 + dx1 < 0 THEN dx1 = -dx1
  62. IF x1 + dx1 > xmax THEN dx1 = -dx1
  63. x1 = x1 + dx1
  64. IF y1 + dy1 < 0 THEN dy1 = -dy1
  65. IF y1 + dy1 > ymax THEN dy1 = -dy1
  66. y1 = y1 + dy1
  67. IF x2 + dx2 < 0 THEN dx2 = -dx2
  68. IF x2 + dx2 > xmax THEN dx2 = -dx2
  69. x2 = x2 + dx2
  70. IF y2 + dy2 < 0 THEN dy2 = -dy2
  71. IF y2 + dy2 > ymax THEN dy2 = -dy2
  72. y2 = y2 + dy2
  73. 'keep x1, y1 the lesser corner and x2, y2 the greater
  74. IF x1 > x2 THEN SWAP x1, x2: SWAP dx1, dx2
  75. IF y1 > y2 THEN SWAP y1, y2: SWAP dy1, dy2
  76.  
  77. changePlasma:
  78. cN = cN + 1
  79. COLOR _RGB32(127 + 127 * SIN(pR * .2 * cN), 127 + 127 * SIN(pG * .2 * cN), 127 + 127 * SIN(pB * .2 * cN))
  80. invColor&& = _RGB32(255 - (127 + 127 * SIN(pR * .2 * cN)), 255 - (127 + 127 * SIN(pG * .2 * cN)), 255 - (127 + 17 * SIN(pB * .2 * cN)))
  81.  
  82. resetPlasma:
  83. pR = RND ^ 2: pG = RND ^ 2: pB = RND ^ 2
  84.  
  85. FUNCTION rdir ()
  86.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  87.  
Screen Saver #3 Mystic Rectangles.PNG
* Screen Saver #3 Mystic Rectangles.PNG (Filesize: 84.52 KB, Dimensions: 1203x721, Views: 452)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Screen Saver #3 Mystic Rectangles
« Reply #1 on: March 01, 2018, 11:26:51 am »
Pete has reminded me that I should mention the ton of instructions that come with the screen saver:

Press spacebar for a new color pattern, one of the infinitely many available with my Plasma System*.

*Mark wouldn't trade it for any other. 

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Screen Saver #3 Mystic Rectangles
« Reply #2 on: March 02, 2018, 10:51:36 am »
Nice work, bplus! :)
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: Screen Saver #3 Mystic Rectangles
« Reply #3 on: March 02, 2018, 10:54:01 am »
Hi Ashish,

Thanks! incomaprable to your 3d stuff but you might like plasma (my version of name) and inverse color idea.