Weekly Qbasic and Qb64 Lesson Topics
March 28, 2024, 02:08:49 pm
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
 
  Home Help Search Arcade Links Staff List Login Register  

NEW LESSON, KBD commands (keyboard)

Pages: [1]
  Print  
Author Topic: NEW LESSON, KBD commands (keyboard)  (Read 2152 times)
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« on: March 27, 2011, 07:41:48 pm »

Code:
kbd$ = INKEY$
IF kbd$ = "+" THEN size = size + .5
IF kbd$ = "-" THEN size = size - .5
IF kbd$ = CHR$(27) THEN END
'display the screen
_DISPLAY       
Ok CY, or anyone ,...as I started to aks about this, but it was in Demos,...
My question would be, for example, but this did not work...
I would just say PRINT "THIS LINE OR HELLO WORLD" I suppose also it should include LOCATE, to place the text in the middle of the screen,
Code:
PRINT "use the + key to make the text bigger, - key to make it smaller"
sleep 3 'to give the person time to read this
CLS ' to clear the screen
LOCATE 10,30
PRINT "HELLO WORLD" 

'then useing the kbd to be able to make the text bigger if one wants
  kbd$ = INKEY$
IF kbd$ = "+" THEN size = size + .5
IF kbd$ = "-" THEN size = size - .5
IF kbd$ = CHR$(27) THEN END
'display the screen
_DISPLAY                     
What happens is when I hit the + key it exits the program,
Like I said I tried it like this but this is not correct....no luck.  So if  yu can explain ? Thanks from Garry
« Last Edit: March 27, 2011, 07:49:52 pm by GarrisonRicketson » Report Spam   Logged

Share on Facebook Share on Twitter

Dustie Bear
Full Member
***
Posts: 115


« Reply #1 on: March 27, 2011, 11:14:41 pm »

If your asking how to keep the program from ending after hitting a
key, this will work.


Code:
PRINT "use the + key to make the text bigger, - key to make it smaller"
SLEEP 3 'to give the person time to read this
CLS ' to clear the screen
LOCATE 10, 30
PRINT "HELLO WORLD"

DO ' The do loop will keep from ending prog till your ready with Chr$(27)
   
'then useing the kbd to be able to make the text bigger if one wants

   kbd$ = INKEY$
   IF kbd$ = "+" THEN size = size + .5  : ' call  sub to change the sizes
   IF kbd$ = "-" THEN  size = size  - .5  : ' call   "    "     "        "     "

  '  -----   IF kbd$ = CHR$(27) THEN END  ---- You dont realy need this here

   'display the screen   
   _DISPLAY

LOOP WHILE DBD$ <> CHR$(27) ' ----- The loop will keep the program from ending

System

« Last Edit: March 27, 2011, 11:37:24 pm by Dustie Bear » Report Spam   Logged
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #2 on: March 28, 2011, 12:36:17 am »

Thanks Dusty,
 But, that was only part, of the problem,
 
Code:
kbd$ = INKEY$
   IF kbd$ = "+" THEN size = size + .5  : ' call  sub to change the sizes
   IF kbd$ = "-" THEN  size = size  - .5  : ' call   "    "     "        "     "
 
This is supposed to make the letters get bigger, or smaller when you enter the + or - , In the demo where CY used this, he loded the text useing _putimage, so I think that is where I am off track,
Your code dose keep it from exiting though, I notice you put in 'call sub to change sizes, as a remark,...but there is no sub,  dose this meand I need to make a sub, to change the sizes,...Ahh,...now I am thinking, but I still do not see how to do it,..almost, I may need to use DIM,  on the text, then a sub, with the _putimage, and kbd$ .
Don't know, and it is pretty late, maybe tommorow I can fool around with this some more,...
thanks though,...at least that part of it I understand now, keeping it from exiting...
from Garry
« Last Edit: March 28, 2011, 09:56:59 am by OlDosLover » Report Spam   Logged

OlDosLover
Guest
« Reply #3 on: March 28, 2011, 08:28:31 am »

Hi all,
    One way to do it is to create a screen that the user see's permanently like
SCREEN _newimage(800,600,32)  .<-- this creats it and makes it the active screen.
To make text that can be resized make another "hidden" screen where you print out that text. It "hidden" because you never actually see this screen, it exists in memory only. It doesnt matter how big or small the hidden window is.
Hidden& = _newimage(200,100,32)  '<-- very small screen
Now as the user already has a window he can view , thats where the output will appear (destination).
So we have to make the smaller hidden window the source. So we print on this window some text like "Hello World"
So once we have directed QB64 to print our message to our small screen , we need to point back to the big screen.
Why? At the moment every command that interacts with the screen(print,circle,line,etc) will do so on the small screen unless we point back to the screen we want this interaction to appear on.
Use the keypad PLUS and MINUS keys to change size.

    Note how i used _putimage in this example. There are NO source co-ordinates which means the entire window(small hidden one) is referenced. What we do is change the destination co-ordinates. This means that the place on the big screen grows and shrinks even thought we place the same size of the small screen into this growing or shrinking place. Putimage scales it for us!
Code:
REM
DEFLNG A-Z

SCREEN _NEWIMAGE(800, 600, 32) '<-- this creats it and makes it the active screen.
Hidden& = _NEWIMAGE(100, 50, 32) '<-- very small screen

_DEST Hidden& '<--point to the surface to print on
PRINT "Hello World"

Size = 0 '<-- set our variable
_DEST 0 '<--reset to point to the surface we see else everything referenced will go to hidden

DO
  _LIMIT 30
  kbd$ = INKEY$
  IF kbd$ = "+" THEN Size = Size + 1 ' call  sub to change the sizes
  IF kbd$ = "-" THEN Size = Size - 1 ' call   "    "     "        "     "
  CLS
  _PUTIMAGE (400 - Size, 300 - Size)-(500 + Size, 350 + Size), Hidden&, 0
  _DISPLAY
LOOP UNTIL _KEYDOWN(27)


More to be added
OlDosLover.
« Last Edit: March 28, 2011, 10:06:08 am by OlDosLover » Report Spam   Logged
Dustie Bear
Full Member
***
Posts: 115


« Reply #4 on: March 28, 2011, 09:19:18 am »

hi

Quote
dose this meand I need to make a sub, to change the sizes

Im modifying my message.

You can use a sub if ya want but due to amount of code its not neccessary, that code OldDos put up is very easy to follow and understand without breaking it up into
smaller sections (subs etc )

after your program gets larger you might want to use a sub.

Dustie



« Last Edit: March 28, 2011, 01:49:02 pm by Dustie Bear » Report Spam   Logged
OlDosLover
Guest
« Reply #5 on: March 28, 2011, 10:10:31 am »

Hi all,
    I think Dustie can rewrite my rather simple example to demonstrate subs. I believe that we all learn better from more teachers and examples than 1.
OlDosLover.
Report Spam   Logged
Dustie Bear
Full Member
***
Posts: 115


« Reply #6 on: March 28, 2011, 11:48:14 am »


Old Dos,  Your doing fine,

Yes I did mention using a sub but the program at this point he probably
doesnt realy need one.

Once he gets the text size thing figured out, no doubt he will want to
start rotating it. then it would be a good time to start segragating some
parts into subs for clarity. The program will be getting larger so breaking
it up into smaller sections would be easier to play with it.

Only reason I suggest using subs
is that it makes it easier to break down certain
parts of a program into smaller parts so its
easier modify and understand what each section does.

When I write a realy large programs like my weather chart program.
Once certain parts are trouble shooted and working fine
I actualy forget how those parts of the program even worked!
even though the rest of the program is still being written.
Dont know how to explain that.
I guess it is like using the print statement or some other command.
we use them but dont  realy know how they were coded or even work
in some cases.  Thats how some of my subs end up. I don't recall how I wrote
them or how they worked even. lol
 I just expect them to be there as I add code which may refer
to them.  I guess using commands from librarys could be an example,
as long as we know what that command does in some cases we probably
dont realy care how it does it.

Dustie






« Last Edit: March 28, 2011, 01:52:12 pm by Dustie Bear » Report Spam   Logged
OlDosLover
Guest
« Reply #7 on: March 28, 2011, 11:56:47 am »

Hi all,
    I agree and you are correct. I'd like colaboration on this topic that illustrates all sorts ways to do the program. The end user selects the method that they relate to and learn quicker in my opinion.
OlDosLover.
Report Spam   Logged
Dustie Bear
Full Member
***
Posts: 115


« Reply #8 on: March 28, 2011, 12:58:13 pm »

Sorry after looking at my hello world its not how you are doing this
I removed the animations and fancey colors from it so you could see how
I was enlarging it.Im posting it anyway just for interest sake.

Do to the amount of variables involved its not very handy for
what you are doing but its something to get ideas from for future .

Code:
a = _NEWIMAGE(800, 400, 32)
SCREEN a, 2, 2

xx = 7 '  set size of enlarged pixels
yy = 8 '

LOCATE 1, 1
PRINT "Hello World"

FOR x = 0 TO 86
   FOR y = 2 TO 11

      ' ----- point finds pixels of the  Hello world printed at top left corner
      IF POINT(x, y) = _RGB(255, 255, 255) THEN

         ' ------  Line simulates those points in larger size in the middle of the screen.
         LINE (x * xx + 25, y * yy + 154)-(x * xx + 31, y * yy + 161), _RGB(100, 200, 0), BF
      END IF
   NEXT y
NEXT x
SLEEP
SYSTEM


Dustie

« Last Edit: March 28, 2011, 01:38:40 pm by Dustie Bear » Report Spam   Logged
Cyperium
Newbie
*
Posts: 8


« Reply #9 on: March 28, 2011, 05:41:03 pm »

size is just a variable, not a sub, like in OlDosLover's example the size variable can be used in _PUTIMAGE to increase the size of the destination area (the source area will fit the destination area, so making the destination area bigger than the source area will increase the size of the image put).

I know the above seemed complicated, this is just because words can't describe it better, examples can though.

Let's break down _PUTIMAGE so we know what each part does:

This is the destination part of _PUTIMAGE it tells where to put the image:
_PUTIMAGE (xdestination, ydestination)-(xdestination2, ydestination2)

The xdestination variables forms a area in which the image will fit. If the image doesn't fit then the image size is increased or decreased in order to fit.

The source part of _PUTIMAGE tells us what part of the image to put in the destination (sourceimage is the image handle of the source and destinationimage is the image handle of the destination):
_PUTIMAGE (xdestination, ydestination)-(xdestination2, ydestination2),sourceimage,destinationimage, (xsource,ysource)-(xsource2,ysource2)

If the source area (xsource,ysource)-(xsource2,ysource2) is smaller than the destination area then the image will increase its size to fit the destination area. In the source area you should always define the area that you want to display in the destination image.


kbd$ is also just a variable, it is made to hold the contents of the INKEY$ function (which is a string representing the key entered on the keyboard).

I'll come up with some more examples covering this later. In the meantime feel free to ask about all this Smiley
« Last Edit: March 28, 2011, 08:28:58 pm by Cyperium » Report Spam   Logged
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #10 on: March 28, 2011, 09:41:47 pm »

Thank you, all, on this,...the code Oldoslover posted works pretty much like what I had in mind, and makes sense, I see the relatiions,  hidden$  ,_NEWIMAGE,
_DEST hidden$ and then that hidden$ is at the end of the _putimage statement,..
so I think I see how it all ties together, and how Screen _newimage establishes a screen, to put everything on. I added some lines of text, and had to make some
small changes, to do that, also added instructions,...
Quote
  Once he gets the text size thing figured out, no doubt he will want to
start rotating it
, actually, for text no, all though interesting idea, but I can't read to well upside down, or side ways, how ever, a image, yes,...but later,
My thoughts now, are to use a DATA map, for the image, but I am not sure, just
"playing around with this", I don't have any plan, it is because when I first saw CY make the letters bigger, in his "hello world" spiral, that cuaght my interest, the variable knd$
Quote
  kbd$ is also just a variable, it is made to hold the contents of the INKEY$ function (which is a string representing the key entered on the keyboard).
This seems to have a lot of uses, changeing size, moveing, jumping ?,...probabley more,I just have not yet thought of.
Here is the changes I made,
Code:
REM
DEFLNG A-Z
PRINT "Instructions, you have about 5 seconds to read this" 'this was just for someone who did not know,which keys to use.
PRINT " Use + to increse sisze , - to decrease size "
SLEEP 4
CLS
SCREEN _NEWIMAGE(800, 600, 32) '<-- this creats it and makes it the active screen.
Hidden& = _NEWIMAGE(100, 160, 32) '<-- very small screen //'note this is where I
'//changed 50 to 160 so the addedtext shows ,actaully each time I added more text
'//I had to increase this.

_DEST Hidden& '<--point to the surface to print on
PRINT "Hello World ­Hola Mundo! "
PRINT "­HOLA!"
PRINT "ALFONSO"
PRINT "How Many "
PRINT "Lines"
PRINT " can I make?"

Size = 0 '<-- set our variable
_DEST 0 '<--reset to point to the surface we see else everything referenced will go to hidden

DO
    _LIMIT 30
    kbd$ = INKEY$
    IF kbd$ = "+" THEN Size = Size + 1 ' call  sub to change the sizes
    IF kbd$ = "-" THEN Size = Size - 1 ' call   "    "     "        "     "
    CLS
    _PUTIMAGE (400 - Size, 300 - Size)-(500 + Size, 350 + Size), Hidden&, 0
    _DISPLAY
LOOP UNTIL _KEYDOWN(27)
 
Dusty, I did look at and save your example  too,...it is interesting to see
Code:
xx = 7 '  set size of enlarged pixels
yy = 8 '
 
the effects of changeing these values, to make it bigger or smaller...
Thanks again everyone.
from Garry
« Last Edit: March 30, 2011, 12:26:09 am by GarrisonRicketson » Report Spam   Logged

GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #11 on: April 04, 2011, 10:07:44 pm »

Code:
REM
DEFLNG A-Z
PRINT "Instructions, you have about 5 seconds to read this" 'this was just for someone who did not know,which keys to use.
PRINT " Use + to increse sisze , - to decrease size "
SLEEP 4
CLS
SCREEN _NEWIMAGE(800, 600, 32) '<-- this creats it and makes it the active screen.
Hidden& = _NEWIMAGE(100, 160, 32) '<-- very small screen //'note this is where I
'//changed 50 to 160 so the addedtext shows ,actaully each time I added more text
'//I had to increase this.

_DEST Hidden& '<--point to the surface to print on
'//------Instead of Print, to load the bunny data ?--------
PRINT "Hello World ­Hola Mundo! "
PRINT "­HOLA!"
PRINT "ALFONSO"
PRINT "How Many "
PRINT "Lines"
PRINT " can I make?"
'//------ The bunny data, would load INSTEAD of text------
Size = 0 '<-- set our variable
_DEST 0 '<--reset to point to the surface we see else everything referenced will go to hidden

DO
    _LIMIT 30
    kbd$ = INKEY$
    IF kbd$ = "+" THEN Size = Size + 1 ' call  sub to change the sizes
    IF kbd$ = "-" THEN Size = Size - 1 ' call   "    "     "        "     "
    CLS
    _PUTIMAGE (400 - Size, 300 - Size)-(500 + Size, 350 + Size), Hidden&, 0
    _DISPLAY
LOOP UNTIL _KEYDOWN(27)
   
Ok now, how would I insert this data map, instead of  the text,Note: the actual image takes up less space then the text,...but I would want the smallest size, to be about in the same location as the text is,...Bunny Data below---------
Code:
   DECLARE SUB PUT2 (Sprite() AS INTEGER, XSize AS INTEGER, YSize AS INTEGER, X AS INTEGER, Y AS INTEGER)
DEFINT A-Z
SCREEN 13
_FULLSCREEN
CLS
' Bitmap for the sprite
DATA 0,15,0,0,0,0,15,0,0,0
DATA 0,15,0,0,0,15,0,0,0,0
DATA 0,0,15,15,15,0,0,0,0,0
DATA 0,15,0,15,0,15,0,0,0,0
DATA 0,0,15,15,15,0,0,0,0,0
DATA 0,0,15,15,15,0,0,0,0,0
DATA 0,0,15,15,15,0,0,0,0,0
DATA 15,15,0,0,0,15,15,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
' An array to hold the sprite
DIM Bunny%(9, 9) 'DIM bunny% ?

' Read the sprite in from DATA to the array
FOR Y = 0 TO 9
    FOR X = 0 TO 9
        READ Bunny%(X, Y) 'DIM bunny% ?
    NEXT X
NEXT Y

' Draw the sprite from the array onto the screen
PUT2 Bunny%(), 9, 9, 0, 0 '

SUB PUT2 (Sprite() AS INTEGER, XSize AS INTEGER, YSize AS INTEGER, X AS INTEGER, Y AS INTEGER)
' Draw the sprite from the array onto the screen
FOR YP = 0 TO YSize - 1
    FOR XP = 0 TO XSize - 1
        PSET (X + XP, Y + YP), Sprite%(XP, YP)
    NEXT XP
NEXT YP
END SUB

 
I did try, a bunch of stuff, but as usual ,no luck, sometimes I really wonder if I ever will understand ?
thanks from Garry
Report Spam   Logged

OlDosLover
Guest
« Reply #12 on: April 05, 2011, 07:03:03 am »

Hi all,
    Garry you got most of it right!. We have to read the data and place it on the hidden screen. From the hidden screen it is scaled up or down as in the above example.
    Your experimental program tries to use the "PUT" command. GET can capture a part of ANY screen (point to that screen with _dest NameofScreen) and once housed inside an array then it can be PUT to another screen. The line
Quote
DECLARE SUB PUT2 (Sprite() AS INTEGER, XSize AS INTEGER, YSize AS INTEGER, X AS INTEGER, Y AS INTEGER)
i believe is from the GDK. QB64 doesnt need declarations and ignores them. Did you want this illustrated by using the GDK ?
Code:
REM
DEFLNG A-Z

SCREEN _NEWIMAGE(800, 600, 32) '<-- this creats it and makes it the active screen.
Hidden& = _NEWIMAGE(10, 10, 32) '<-- very small screen to place the colors from the data statements

_DEST 0
PRINT " Use + to increse sisze , - to decrease size ,any key to continue"
Dummy$ = INPUT$(1)
CLS

_DEST Hidden& '<--point to the surface to print on
FOR x = 1 TO 10 '<--load the bunny data
  FOR y = 1 TO 10
    READ z
    IF z = 0 THEN Tint = _RGB32(0, 0, 255) ELSE Tint = _RGB32(0, 255, 255)
    PSET (y, x), Tint
  NEXT y
NEXT x

_DEST 0 '<--reset to point to the surface we see else everything referenced will go to hidden
Size = 0 '<-- set our variable
DO
  _LIMIT 30
  kbd$ = INKEY$
  IF kbd$ = "+" THEN Size = Size + 1 ' call  sub to change the sizes
  IF kbd$ = "-" THEN Size = Size - 1 ' call   "    "     "        "     "
  CLS
  _PUTIMAGE (400 - Size, 300 - Size)-(410 + Size, 310 + Size), Hidden&, 0
  _DISPLAY
LOOP UNTIL _KEYDOWN(27)
SYSTEM

'--------------------------
' Bitmap for the sprite
DATA 0,15,0,0,0,0,15,0,0,0
DATA 0,15,0,0,0,15,0,0,0,0
DATA 0,0,15,15,15,0,0,0,0,0
DATA 0,15,0,15,0,15,0,0,0,0
DATA 0,0,15,15,15,0,0,0,0,0
DATA 0,0,15,15,15,0,0,0,0,0
DATA 0,0,15,15,15,0,0,0,0,0
DATA 15,15,0,0,0,15,15,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0

OlDosLover.
« Last Edit: April 05, 2011, 07:06:09 am by OlDosLover » Report Spam   Logged
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #13 on: April 05, 2011, 07:53:23 am »

Quote
  DECLARE SUB PUT2 (Sprite() AS INTEGER, XSize AS INTEGER, YSize AS INTEGER, X AS INTEGER, Y AS INTEGER)
Actually that was part of the code in tut for qb64,...I had not thought about it,
 If you have time, and feel like like it though, that would be interesting
to see, it useing GDK,
 I guess though it would be best if we start that in the GDK, categorys,..
I don't have much time right now, have to get ready for work, but thanks,
I think I see what you did here, though,...
thanks
from Garry
Report Spam   Logged


Pages: [1]
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum


Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy