Author Topic: Rectangles  (Read 5403 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Rectangles
« on: June 21, 2018, 03:54:57 pm »
In future i add here more hardware accelerated demos.

This code create in hardware screen layer N - rectangle textured using MAPTRIANGLE.
Code: QB64: [Select]
  1. '100.000 frames demo
  2.  
  3. SCREEN _NEWIMAGE(640, 480, 32)
  4. I& = _COPYIMAGE(J&, 33) '                                                             use hardware acceleration
  5. T = TIMER
  6. FOR x = 1 TO 100000
  7.     Rectangle 320, 240, 4 + a, 240, I& 'X axis, Y axis, Vertex numbers, Radius, Texture&
  8.  
  9.     _DISPLAY
  10.     a = a + .0001
  11.  
  12.  
  13.  
  14. SUB Rectangle (X AS INTEGER, Y AS INTEGER, N AS INTEGER, Radius AS INTEGER, Source AS LONG)
  15.     bod = 628 / N
  16.     FOR g! = 0 TO 4 * _PI STEP 0.01
  17.         IF h MOD bod = 0 THEN
  18.             IF oldx = 0 THEN oldx = X: oldy = Y
  19.             _MAPTRIANGLE (oldx, oldy)-(X + SIN(g!) * Radius, Y + COS(g!) * Radius)-(X, Y), Source& TO(oldx, oldy)-(X + SIN(g!) * Radius, Y + COS(g!) * Radius)-(X, Y)
  20.             oldx = X + SIN(g!) * Radius: oldy = Y + COS(g!) * Radius
  21.         END IF
  22.         h = h + 1
  23.     NEXT g!
  24.  
  25.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Rectangles
« Reply #1 on: June 22, 2018, 08:51:05 am »
Hi Petr,

You really threw me off by calling these rectangles.

I would call them regular polygons of an image (of a copy of the screen).

Nice work with _MAPTRIANGLE.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Rectangles
« Reply #2 on: June 22, 2018, 06:03:31 pm »
Umm... I ran the program and all I got was a black window. Ran it several times with the same result. The last time I ran it, I waited - just in case I was too impatient... and a number appeared on the screen. Ran it again to confirm. Screen stayed black for maybe 20 seconds then displayed '20.93359' (without the quotes) and the program terminated.

All I did was 'cut and paste' and F5 to run...

J
Logic is the beginning of wisdom.

FellippeHeitor

  • Guest
Re: Rectangles
« Reply #3 on: June 22, 2018, 06:11:29 pm »
I get (and have a feeling bplus got it too) a circle with an image of the desktop, as if made by a cookie cutter.

FellippeHeitor

  • Guest
Re: Rectangles
« Reply #4 on: June 22, 2018, 06:24:47 pm »
Btw, this code is for Windows only (because of _SCREENIMAGE), so in Linux you probably won't see anything after all.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Rectangles
« Reply #5 on: June 22, 2018, 08:33:59 pm »
OK Johnno, Petr did this:
Code: QB64: [Select]
  1. _TITLE "Polygon Image Demo"
  2. 'by bplus started 2018-06-22
  3.  
  4. CONST xmax = 800
  5. CONST ymax = 600
  6. SCREEN _NEWIMAGE(xmax, ymax, 32)
  7. _SCREENMOVE 100, 20
  8.  
  9. stars& = _LOADIMAGE("stars.png")
  10. _PUTIMAGE , stars&, 0
  11. FOR n = 3 TO 12
  12.     CLS
  13.     polygonImage stars&, xmax / 2, ymax / 2, 300, n
  14.     _DISPLAY
  15.     _DELAY 1
  16. SUB polygonImage (ImageHandle&, xOrigin, yOrigin, radius, nVertex)
  17.     polyAngle = _PI(2) / nVertex
  18.     x1 = xOrigin + radius * COS(polyAngle)
  19.     y1 = yOrigin + radius * SIN(polyAngle)
  20.     FOR i = 2 TO nVertex + 1
  21.         x2 = xOrigin + radius * COS(i * polyAngle)
  22.         y2 = yOrigin + radius * SIN(i * polyAngle)
  23.         _MAPTRIANGLE (xOrigin, yOrigin)-(x1, y1)-(x2, y2), ImageHandle& TO(xOrigin, yOrigin)-(x1, y1)-(x2, y2), 0
  24.         x1 = x2: y1 = y2
  25.     NEXT
  26.  

Only with an image of the desktop and in a much more complicated way.
« Last Edit: June 22, 2018, 08:36:36 pm by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Rectangles
« Reply #6 on: June 22, 2018, 08:52:28 pm »
Btw, this code is for Windows only (because of _SCREENIMAGE), so in Linux you probably won't see anything after all.

Understood.
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Rectangles
« Reply #7 on: June 22, 2018, 09:26:22 pm »
On the other hand if we are just cookie cutting a circle out of an image this is much shorter time:
Code: QB64: [Select]
  1. _TITLE "Polygon Image Demo"
  2. 'by bplus started 2018-06-22
  3.  
  4. CONST xmax = 800
  5. CONST ymax = 600
  6. SCREEN _NEWIMAGE(xmax, ymax, 32)
  7. _SCREENMOVE 100, 20
  8.  
  9. stars& = _LOADIMAGE("stars.png")
  10. _PUTIMAGE , stars&, 0
  11. start## = TIMER
  12. polygonImage stars&, xmax / 2, ymax / 2, 300, 50
  13. PRINT TIMER - start##
  14.  
  15. SUB polygonImage (ImageHandle&, xOrigin, yOrigin, radius, nVertex)
  16.     polyAngle = _PI(2) / nVertex
  17.     x1 = xOrigin + radius * COS(polyAngle)
  18.     y1 = yOrigin + radius * SIN(polyAngle)
  19.     FOR i = 2 TO nVertex + 1
  20.         x2 = xOrigin + radius * COS(i * polyAngle)
  21.         y2 = yOrigin + radius * SIN(i * polyAngle)
  22.         _MAPTRIANGLE (xOrigin, yOrigin)-(x1, y1)-(x2, y2), ImageHandle& TO(xOrigin, yOrigin)-(x1, y1)-(x2, y2), 0
  23.         x1 = x2: y1 = y2
  24.     NEXT
  25.  
BTW I wonder how a circle fill with this method stacks up against Steve's.
« Last Edit: June 22, 2018, 09:31:32 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Rectangles
« Reply #8 on: June 22, 2018, 10:14:18 pm »
Quote
BTW I wonder how a circle fill with this method stacks up against Steve's.

Terribly!

FellippeHeitor

  • Guest
Re: Rectangles
« Reply #9 on: June 22, 2018, 10:26:07 pm »
Quote
On the other hand if we are just cookie cutting a circle out of an image this is much shorter time.

Hold my beer:

Code: QB64: [Select]
  1. cookieCutter& = _NEWIMAGE(1600, 1200, 32)
  2. _DEST cookieCutter&
  3. CIRCLE (_WIDTH / 2, _HEIGHT / 2), 250, _RGB32(255, 0, 255)
  4. PAINT (_WIDTH / 2, _HEIGHT / 2), _RGB32(255, 0, 255)
  5. _CLEARCOLOR _RGB32(255, 0, 255)
  6.  
  7. stars& = _LOADIMAGE("stars.png", 32)
  8. SCREEN _NEWIMAGE(800, 600, 32)
  9.  
  10.     _PUTIMAGE (0, 0), stars&
  11.     _PUTIMAGE (_MOUSEX - 800, _MOUSEY - 600), cookieCutter&
  12.     _DISPLAY
  13.     _LIMIT 30
  14.  

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Rectangles
« Reply #10 on: June 22, 2018, 11:57:04 pm »
Quote
BTW I wonder how a circle fill with this method stacks up against Steve's.

Terribly!

Such is life

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Rectangles
« Reply #11 on: June 23, 2018, 12:13:11 am »
Still here is the cookie:
Code: QB64: [Select]
  1. _TITLE "Polygon Image Demo 2"
  2. 'by bplus started 2018-06-22
  3.  
  4. CONST xmax = 800
  5. CONST ymax = 600
  6. SCREEN _NEWIMAGE(xmax, ymax, 32)
  7. _SCREENMOVE 100, 20
  8.  
  9. stars& = _LOADIMAGE("stars.png")
  10. stuff& = _NEWIMAGE(xmax, ymax, 32)
  11. _DEST stuff&
  12. FOR i = 1 TO 100
  13.     CIRCLE (RND * xmax, RND * ymax), RND * 100, _RGB32(RND * 255, RND * 255, RND * 255)
  14.     CLS
  15.     _SOURCE stuff&
  16.     _PUTIMAGE
  17.     polygonImage stars&, _MOUSEX, _MOUSEY, 250, 50
  18.     _DISPLAY
  19.     _LIMIT 30
  20.  
  21.  
  22. SUB polygonImage (ImageHandle&, xOrigin, yOrigin, radius, nVertex)
  23.     polyAngle = _PI(2) / nVertex
  24.     x1 = xOrigin + radius * COS(polyAngle)
  25.     y1 = yOrigin + radius * SIN(polyAngle)
  26.     FOR i = 2 TO nVertex + 1
  27.         x2 = xOrigin + radius * COS(i * polyAngle)
  28.         y2 = yOrigin + radius * SIN(i * polyAngle)
  29.         _MAPTRIANGLE (xOrigin, yOrigin)-(x1, y1)-(x2, y2), ImageHandle& TO(xOrigin, yOrigin)-(x1, y1)-(x2, y2), 0
  30.         x1 = x2: y1 = y2
  31.     NEXT
  32.  
  33.  
« Last Edit: June 23, 2018, 12:16:15 am by bplus »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Rectangles
« Reply #12 on: June 23, 2018, 03:15:14 am »
Thank you all for posts, I'll add another code in the near future. Last night of my time I was no longer in the forum, but now I go to bury the guinea pigs of my children, that died in the evening. I'm pleased with your interest in this program, which shows how many ways one thing can do and their differences in speed. My N - polygon I wrote for the use I will show in the next program.