DEST: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 18: Line 18:
''Example 1:'' Placing a center point and a circle using [[_CLEARCOLOR]] to eliminate the background color black.
''Example 1:'' Placing a center point and a circle using [[_CLEARCOLOR]] to eliminate the background color black.
{{CodeStart}}
{{CodeStart}}
{{Cl|SCREEN (statement)|SCREEN}} 13      'program screen can use 256 colors
{{Cl|SCREEN}} {{Text|13|#F580B1}} {{Text|<nowiki>'program screen can use 256 colors</nowiki>|#919191}}
a& = {{Cl|_NEWIMAGE}}(320,200,13)       'create 2 screen page handles a& and b&
a& = {{Cl|_NEWIMAGE}}({{Text|320|#F580B1}}, {{Text|200|#F580B1}}, {{Text|13|#F580B1}}) {{Text|<nowiki>'create 2 screen page handles a& and b&</nowiki>|#919191}}
b& = {{Cl|_NEWIMAGE}}(320,200,13)
b& = {{Cl|_NEWIMAGE}}({{Text|320|#F580B1}}, {{Text|200|#F580B1}}, {{Text|13|#F580B1}})
{{Cl|_DEST}} a&                         'set destination image to handle a&
{{Cl|_DEST}} a& {{Text|<nowiki>'set destination image to handle a&</nowiki>|#919191}}
{{Cl|PSET}} (100, 100), 15               'draw a dot on the current destination handle a&
{{Cl|PSET}} ({{Text|100|#F580B1}}, {{Text|100|#F580B1}}), {{Text|15|#F580B1}} {{Text|<nowiki>'draw a dot on the current destination handle a&</nowiki>|#919191}}
{{Cl|_DEST}} b&                         'set destination image to handle b&
{{Cl|_DEST}} b& {{Text|<nowiki>'set destination image to handle b&</nowiki>|#919191}}
{{Cl|CIRCLE}} (100, 100), 50, 15         'draw a circle on the current destination handle b&
{{Cl|CIRCLE}} ({{Text|100|#F580B1}}, {{Text|100|#F580B1}}), {{Text|50|#F580B1}}, {{Text|15|#F580B1}} {{Text|<nowiki>'draw a circle on the current destination handle b&</nowiki>|#919191}}
{{Cl|_CLEARCOLOR}} 0                     'make page b color 0 (black) transparent
{{Cl|_CLEARCOLOR}} {{Text|0|#F580B1}} {{Text|<nowiki>'make page b color 0 (black) transparent</nowiki>|#919191}}
{{Cl|_PUTIMAGE}} , b&, a&               'put circle on image b to image a& (a PSET dot)
{{Cl|_PUTIMAGE}} , b&, a& {{Text|<nowiki>'put circle on image b to image a& (a PSET dot)</nowiki>|#919191}}
{{Cl|_PUTIMAGE}} , a&, 0                 'put what is on image a& to the screen (handle 0)  
{{Cl|_PUTIMAGE}} , a&, {{Text|0|#F580B1}} {{Text|<nowiki>'put what is on image a& to the screen (handle 0)</nowiki>|#919191}}
{{CodeEnd}}
{{CodeEnd}}


----


''Example 2:'' Demonstrates how [[PRINT|printed]] text can be stretched using [[_PUTIMAGE]] with [[_DEST]] pages.
''Example 2:'' Demonstrates how [[PRINT|printed]] text can be stretched using [[_PUTIMAGE]] with [[_DEST]] pages.
{{CodeStart}}
{{CodeStart}}
{{Cl|DIM}} a(10) {{Cl|AS}} {{Cl|LONG}}
{{Cl|DIM}} a({{Text|10|#F580B1}}) {{Cl|AS}} {{Cl|LONG}}
{{Cl|DIM}} b {{Cl|AS}} {{Cl|LONG}}
{{Cl|DIM}} b {{Cl|AS}} {{Cl|LONG}}


{{Cl|REM}} Sets up a newimage for B then sets the screen to that.
{{Cl|REM}}{{Text|<nowiki> Sets up a newimage for B then sets the screen to that.</nowiki>|#919191}}
b = {{Cl|_NEWIMAGE}}(640, 480, 32)
b = {{Cl|_NEWIMAGE}}({{Text|640|#F580B1}}, {{Text|480|#F580B1}}, {{Text|32|#F580B1}})
{{Cl|SCREEN (statement)|SCREEN}} b
{{Cl|SCREEN}} b


{{Cl|REM}} Make pages 48 pixels tall. If the image is not at least that it wont work
{{Cl|REM}}{{Text|<nowiki> Make pages 48 pixels tall. If the image is not at least that it wont work</nowiki>|#919191}}
a(1) = {{Cl|_NEWIMAGE}}(240, 48, 32)
a({{Text|1|#F580B1}}) = {{Cl|_NEWIMAGE}}({{Text|240|#F580B1}}, {{Text|48|#F580B1}}, {{Text|32|#F580B1}})
a(2) = {{Cl|_NEWIMAGE}}(240, 48, 32)
a({{Text|2|#F580B1}}) = {{Cl|_NEWIMAGE}}({{Text|240|#F580B1}}, {{Text|48|#F580B1}}, {{Text|32|#F580B1}})
a(3) = {{Cl|_NEWIMAGE}}(98, 48, 32)
a({{Text|3|#F580B1}}) = {{Cl|_NEWIMAGE}}({{Text|98|#F580B1}}, {{Text|48|#F580B1}}, {{Text|32|#F580B1}})


xa = 100
xa = {{Text|100|#F580B1}}
ya = 120
ya = {{Text|120|#F580B1}}
xm = 4
xm = {{Text|4|#F580B1}}
ym = 4
ym = {{Text|4|#F580B1}}


{{Cl|REM}} Some fun things for the bouncing text.
{{Cl|REM}}{{Text|<nowiki> Some fun things for the bouncing text.</nowiki>|#919191}}
st$(0) = "doo"
st$({{Text|0|#F580B1}}) = {{Text|<nowiki>"doo"</nowiki>|#FFB100}}
st$(1) = "rey"
st$({{Text|1|#F580B1}}) = {{Text|<nowiki>"rey"</nowiki>|#FFB100}}
st$(2) = "mee"
st$({{Text|2|#F580B1}}) = {{Text|<nowiki>"mee"</nowiki>|#FFB100}}
st$(3) = "faa"
st$({{Text|3|#F580B1}}) = {{Text|<nowiki>"faa"</nowiki>|#FFB100}}
st$(4) = "soo"
st$({{Text|4|#F580B1}}) = {{Text|<nowiki>"soo"</nowiki>|#FFB100}}
st$(5) = "laa"
st$({{Text|5|#F580B1}}) = {{Text|<nowiki>"laa"</nowiki>|#FFB100}}
st$(6) = "tee"
st$({{Text|6|#F580B1}}) = {{Text|<nowiki>"tee"</nowiki>|#FFB100}}


sta$(0) = "This is a demo"
sta$({{Text|0|#F580B1}}) = {{Text|<nowiki>"This is a demo"</nowiki>|#FFB100}}
sta$(1) = "showing how to use"
sta$({{Text|1|#F580B1}}) = {{Text|<nowiki>"showing how to use"</nowiki>|#FFB100}}
sta$(2) = "the _DEST command"
sta$({{Text|2|#F580B1}}) = {{Text|<nowiki>"the _DEST command"</nowiki>|#FFB100}}
sta$(3) = "with PRINT"
sta$({{Text|3|#F580B1}}) = {{Text|<nowiki>"with PRINT"</nowiki>|#FFB100}}
sta$(4) = "and _PUTIMAGE"
sta$({{Text|4|#F580B1}}) = {{Text|<nowiki>"and _PUTIMAGE"</nowiki>|#FFB100}}


{{Cl|REM}} prints to a(3) image then switches back to the default 0
{{Cl|REM}}{{Text|<nowiki> prints to a(3) image then switches back to the default 0</nowiki>|#919191}}
{{Cl|_DEST}} a(3): f = {{Cl|INT}}({{Cl|RND}} * 6): {{Cl|PRINT}} st$(3): {{Cl|_DEST}} 0
{{Cl|_DEST}} a({{Text|3|#F580B1}}): f = {{Cl|INT}}({{Cl|RND}} * {{Text|6|#F580B1}}): {{Cl|PRINT}} st$({{Text|3|#F580B1}}): {{Cl|_DEST}} {{Text|0|#F580B1}}


DO
{{Cl|DO}}
     {{Cl|REM}} prints to a(1) and a(2) then switches bac to 0
     {{Cl|REM}}{{Text|<nowiki> prints to a(1) and a(2) then switches bac to 0</nowiki>|#919191}}
     {{Cl|_DEST}} a(1)
     {{Cl|_DEST}} a({{Text|1|#F580B1}})
     {{Cl|CLS}}
     {{Cl|CLS}}
     {{Cl|PRINT}} sta(r)
     {{Cl|PRINT}} sta(r)
     {{Cl|_DEST}} a(2)
     {{Cl|_DEST}} a({{Text|2|#F580B1}})
     {{Cl|CLS}}
     {{Cl|CLS}}
     {{Cl|PRINT}} sta(r + 1)
     {{Cl|PRINT}} sta(r + {{Text|1|#F580B1}})
     {{Cl|_DEST}} 0         'destination zero is the main program page
     {{Cl|_DEST}} {{Text|0|#F580B1}} {{Text|<nowiki>'destination zero is the main program page</nowiki>|#919191}}


     {{Cl|REM}} a loop to putimage the images in a(1) and a(2) in a way to make it look like its rolling
     {{Cl|REM}}{{Text|<nowiki> a loop to putimage the images in a(1) and a(2) in a way to make it look like its rolling</nowiki>|#919191}}
     {{Cl|FOR...NEXT|FOR}} yat = 150 {{Cl|TO}} 380 {{Cl|STEP}} 4
     {{Cl|FOR}} yat = {{Text|150|#F580B1}} {{Cl|TO}} {{Text|380|#F580B1}} {{Cl|STEP}} {{Text|4|#F580B1}}
         {{Cl|CLS}}
         {{Cl|CLS}}
         {{Cl|_PUTIMAGE}} (0, yat)-(640, 380), a(1)
         {{Cl|_PUTIMAGE}} ({{Text|0|#F580B1}}, yat)-({{Text|640|#F580B1}}, {{Text|380|#F580B1}}), a({{Text|1|#F580B1}})
         {{Cl|_PUTIMAGE}} (0, 150)-(640, yat), a(2)
         {{Cl|_PUTIMAGE}} ({{Text|0|#F580B1}}, {{Text|150|#F580B1}})-({{Text|640|#F580B1}}, yat), a({{Text|2|#F580B1}})
         {{Cl|GOSUB}} bounce
         {{Cl|GOSUB}} bounce
         {{Cl|_DISPLAY}}
         {{Cl|_DISPLAY}}
         {{Cl|_LIMIT}} 20
         {{Cl|_LIMIT}} {{Text|20|#F580B1}}
     {{Cl|NEXT}} yat
     {{Cl|NEXT}} yat


     r = r + 1
     r = r + {{Text|1|#F580B1}}
     {{Cl|IF...THEN|IF}} r = 4 {{Cl|THEN}} r = 0
     {{Cl|IF}} r = {{Text|4|#F580B1}} {{Cl|THEN}} r = {{Text|0|#F580B1}}
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} <> ""
{{Cl|DO...LOOP|LOOP UNTIL}} {{Cl|INKEY$}} <> {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Cl|END}}
{{Cl|END}}


bounce:
bounce:
{{Cl|IF...THEN|IF}} xa > 600 {{Cl|OR (boolean)|OR}} xa < 20 {{Cl|THEN}} xm = xm * -1: {{Cl|_DEST}} a(3): f = {{Cl|INT}}({{Cl|RND}} * 6): {{Cl|CLS}}: {{Cl|_CLEARCOLOR}} 0: {{Cl|PRINT}} st$(f): {{Cl|_DEST}} 0
{{Cl|IF}} xa > {{Text|600|#F580B1}} {{Cl|OR (boolean)|OR}} xa < {{Text|20|#F580B1}} {{Cl|THEN}} xm = xm * {{Text|-1|#F580B1}}: {{Cl|_DEST}} a({{Text|3|#F580B1}}): f = {{Cl|INT}}({{Cl|RND}} * {{Text|6|#F580B1}}): {{Cl|CLS}}: {{Cl|_CLEARCOLOR}} {{Text|0|#F580B1}}: {{Cl|PRINT}} st$(f): {{Cl|_DEST}} {{Text|0|#F580B1}}
{{Cl|IF...THEN|IF}} ya > 400 {{Cl|OR (boolean)|OR}} ya < 20 {{Cl|THEN}} ym = ym * -1: {{Cl|_DEST}} a(3): f = {{Cl|INT}}({{Cl|RND}} * 7): {{Cl|CLS}}: {{Cl|_CLEARCOLOR}} 0: {{Cl|PRINT}} st$(f): {{Cl|_DEST}} 0
{{Cl|IF}} ya > {{Text|400|#F580B1}} {{Cl|OR (boolean)|OR}} ya < {{Text|20|#F580B1}} {{Cl|THEN}} ym = ym * {{Text|-1|#F580B1}}: {{Cl|_DEST}} a({{Text|3|#F580B1}}): f = {{Cl|INT}}({{Cl|RND}} * {{Text|7|#F580B1}}): {{Cl|CLS}}: {{Cl|_CLEARCOLOR}} {{Text|0|#F580B1}}: {{Cl|PRINT}} st$(f): {{Cl|_DEST}} {{Text|0|#F580B1}}
{{Cl|_PUTIMAGE}} (xa, ya)-(xa + 150, ya + 80), a(3)
{{Cl|_PUTIMAGE}} (xa, ya)-(xa + {{Text|150|#F580B1}}, ya + {{Text|80|#F580B1}}), a({{Text|3|#F580B1}})
xa = xa + xm
xa = xa + xm
ya = ya + ym
ya = ya + ym
{{Cl|RETURN}}  
{{Cl|RETURN}}
{{CodeEnd}}
{{CodeEnd}}
{{small|Adapted from code by CodeViper}}  
{{Small|Adapted from code by CodeViper}}




Line 112: Line 113:


{{PageNavigation}}
{{PageNavigation}}
[[Category:Latest]]

Latest revision as of 19:41, 23 March 2023

The _DEST statement sets the current write image or page. All graphic and print changes will be done to this image.


Syntax

_DEST imageHandle&


Description

  • imageHandle& is the handle of the image that will act as the current write page.
  • _DEST 0 refers to the present program SCREEN. You can use 0 to refer to the present program SCREEN.
  • _DEST _CONSOLE can set the destination to send information to a console window using PRINT or INPUT.
  • If imageHandle& is an invalid handle, an invalid handle error occurs. Always check for valid handle values first (imageHandle& < -1).
  • Note: Use _SOURCE when you need to read a page or image with POINT, GET or the SCREEN function.


Examples

Example 1: Placing a center point and a circle using _CLEARCOLOR to eliminate the background color black.

SCREEN 13 'program screen can use 256 colors
a& = _NEWIMAGE(320, 200, 13) 'create 2 screen page handles a& and b&
b& = _NEWIMAGE(320, 200, 13)
_DEST a& 'set destination image to handle a&
PSET (100, 100), 15 'draw a dot on the current destination handle a&
_DEST b& 'set destination image to handle b&
CIRCLE (100, 100), 50, 15 'draw a circle on the current destination handle b&
_CLEARCOLOR 0 'make page b color 0 (black) transparent
_PUTIMAGE , b&, a& 'put circle on image b to image a& (a PSET dot)
_PUTIMAGE , a&, 0 'put what is on image a& to the screen (handle 0)

Example 2: Demonstrates how printed text can be stretched using _PUTIMAGE with _DEST pages.

DIM a(10) AS LONG
DIM b AS LONG

REM Sets up a newimage for B then sets the screen to that.
b = _NEWIMAGE(640, 480, 32)
SCREEN b

REM Make pages 48 pixels tall. If the image is not at least that it wont work
a(1) = _NEWIMAGE(240, 48, 32)
a(2) = _NEWIMAGE(240, 48, 32)
a(3) = _NEWIMAGE(98, 48, 32)

xa = 100
ya = 120
xm = 4
ym = 4

REM Some fun things for the bouncing text.
st$(0) = "doo"
st$(1) = "rey"
st$(2) = "mee"
st$(3) = "faa"
st$(4) = "soo"
st$(5) = "laa"
st$(6) = "tee"

sta$(0) = "This is a demo"
sta$(1) = "showing how to use"
sta$(2) = "the _DEST command"
sta$(3) = "with PRINT"
sta$(4) = "and _PUTIMAGE"

REM prints to a(3) image then switches back to the default 0
_DEST a(3): f = INT(RND * 6): PRINT st$(3): _DEST 0

DO
    REM prints to a(1) and a(2) then switches bac to 0
    _DEST a(1)
    CLS
    PRINT sta(r)
    _DEST a(2)
    CLS
    PRINT sta(r + 1)
    _DEST 0 'destination zero is the main program page

    REM a loop to putimage the images in a(1) and a(2) in a way to make it look like its rolling
    FOR yat = 150 TO 380 STEP 4
        CLS
        _PUTIMAGE (0, yat)-(640, 380), a(1)
        _PUTIMAGE (0, 150)-(640, yat), a(2)
        GOSUB bounce
        _DISPLAY
        _LIMIT 20
    NEXT yat

    r = r + 1
    IF r = 4 THEN r = 0
LOOP UNTIL INKEY$ <> ""
END

bounce:
IF xa > 600 OR xa < 20 THEN xm = xm * -1: _DEST a(3): f = INT(RND * 6): CLS: _CLEARCOLOR 0: PRINT st$(f): _DEST 0
IF ya > 400 OR ya < 20 THEN ym = ym * -1: _DEST a(3): f = INT(RND * 7): CLS: _CLEARCOLOR 0: PRINT st$(f): _DEST 0
_PUTIMAGE (xa, ya)-(xa + 150, ya + 80), a(3)
xa = xa + xm
ya = ya + ym
RETURN
Adapted from code by CodeViper


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link