Post by pauloastro on Oct 17, 2022 21:04:25 GMT
This is a simple animation experience of qb64 graphic capabilities.
img1& = _NEWIMAGE(800, 400, 256) 'This will be a 256 color screen windows.
'_NEWIMAGE creates a memory graphic area, and not an actual SCREEN image.
'The character '&' defines a LONG variable.
'Using DIM img1 as LONG would have the same result.
_DEST img1& 'lets define the new graphic memory area as the DESTany to graphic output.
'This is not the final visual screen, but just a graphic memory representation to be displayed later,
'and where we are drawing the graphic shapes.
'lets draw some more shapes and text for the background reference:
LINE (12, 13)-(790, 360), 4, BF
LINE (40, 10)-(350, 350), 12, B
LINE (110, 100)-(799, 399), 3, BF
LINE (140, 80)-(760, 350), 1, B
PRINT img1& 'just print the value of the image memory of img1&
LOCATE 5, 5: COLOR 15, 2: PRINT ".. Test image ..."
LOCATE 10, 20: COLOR 10: PRINT "This is one more test line to test!!"
LOCATE 12, 27
FOR i = 1 TO 5
LOCATE 12 + i, 20 + i: COLOR i + 9, i - 1: PRINT "This is one more test line to test!!"
NEXT
'.. END of drawing shapes.
'Now lets create a copy of the background image to use it as the reference to make the animation
img2& = _COPYIMAGE(img1&)
PRINT img2&
SCREEN _DEST 'THis is the point to show the image made to the user saved in memory.
'Using 'SCREEN img1&'would have the same result as this line of code.
'Pay attention to this text during the animation: the img2& background image reference doesn't include these 3 lines.
'What is happening here? ;-)
LOCATE 20, 10: COLOR 4, 15: PRINT "INIT: Press any Key to Start Test..This line will be deleted/ cleaned by the moving BOX."
LOCATE 21, 10: COLOR 15, 4: PRINT "INIT: Press any Key to Start Test..This line will be deleted/ cleaned by the moving BOX."
LOCATE 11, 8: COLOR 1, 15: PRINT "INIT: Press any Key to Start Test..This line will be deleted/ cleaned by the moving BOX."
SLEEP 'Wait for Any key press
initX = 5 'Starting windows X position in pixels.
initY = 5 'Starting windows Y position.
initSize = 80 'Define square Box size.
_SOURCE img2&
_DEST img1&
'In this FOR..TO.. loop the Box is going down the screen:
FOR i = 0 TO 400 - initSize
LINE (initX + i, initY + i)-(initX + initSize + i, initY + initSize + i), 15, B 'This is the animated square Box.
_DELAY 0.011 'Give a small delay time to see the box movement.
_PUTIMAGE (initX + i, initY + i)-(initX + initSize + i, initY + initSize + i), , , (initX + i, initY + i)-(initX + initSize + i, initY + initSize + i)
'This _PUTIMAGE subroutine is what makes the magic happend.
NEXT
'In this FOR..TO.. loop the Box is going up the screen:
FOR j = 0 TO 340
LINE (initX + i + j, initY + i - j)-(initX + initSize + i + j, initY + initSize + i - j), 15, B
_DELAY 0.03
_PUTIMAGE (initX + i + j, initY + i - j)-(initX + initSize + i + j, initY + initSize + i - j), , , (initX + i + j, initY + i - j)-(initX + initSize + i + j, initY + initSize + i - j)
NEXT
_FREEIMAGE img2& 'this line is importante not to run out of memory if you create lots of memory images in your prgram.
'But not relevant for this simple exemple.