Author |
Message |
Shib
|
Posted: Sun Dec 16, 2007 7:21 pm Post subject: Procedure that centers text |
|
|
Can somebody please help me write the procedure that centers text? Thanks alot guys. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Ultrahex
|
Posted: Sun Dec 16, 2007 7:47 pm Post subject: Re: Procedure that centers text |
|
|
Think about how x-coordinates change base on length of the string you are writing in the font you are writing in. |
|
|
|
|
|
Shib
|
Posted: Sun Dec 16, 2007 7:52 pm Post subject: RE:Procedure that centers text |
|
|
Do you have the code? it would be easier if you gave it to me and then I could figure out whats going on. |
|
|
|
|
|
Tony
|
Posted: Sun Dec 16, 2007 8:11 pm Post subject: RE:Procedure that centers text |
|
|
sure thing.
If you are using plain text, you'll need
length() - length of string
locate() - moving the cursor before the put statement
If you are using graphics text, you'll need
Font.Draw() - obviously to draw the text itself
Font.Width() - to calculate the width of the text string |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
CodeMonkey2000
|
Posted: Sun Dec 16, 2007 8:56 pm Post subject: RE:Procedure that centers text |
|
|
We aren't suppose to write code for you. But we can give you advice. Why don't you attempt the problem first? |
|
|
|
|
|
Nick
|
Posted: Sun Dec 16, 2007 9:29 pm Post subject: Re: Procedure that centers text |
|
|
Shib @ Sun Dec 16, 2007 7:21 pm wrote: Can somebody please help me write the procedure that centers text? Thanks alot guys.
I do think he intends to write it himself just needs some help doing it
think about the length of the text between "Hello world" and "baz bar foo baz bar foo" |
|
|
|
|
|
Euphoracle
|
Posted: Sun Dec 16, 2007 10:56 pm Post subject: Re: RE:Procedure that centers text |
|
|
Tony @ Sun Dec 16, 2007 8:11 pm wrote: sure thing.
If you are using plain text, you'll need
length() - length of string
locate() - moving the cursor before the put statement
If you are using graphics text, you'll need
Font.Draw() - obviously to draw the text itself
Font.Width() - to calculate the width of the text string
Also,
If you are using plain text, you'll need
maxcol - columns in the "console"
maxrow - rows in the "console"
If you are using graphics text, you'll need
maxx - width of the window
maxy - height of the window |
|
|
|
|
|
Shib
|
Posted: Mon Dec 17, 2007 8:36 am Post subject: RE:Procedure that centers text |
|
|
This is what I got so far
code: |
procedure centerText
Font.Draw (centerText , maxx div 2, maxy div 4, font, black)
end centerText
cls
centerText ("Loading Please Wait...")
centerText ("Press Anykey to continue")
Input.Pause
|
it says assignment wrong type :S |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Carey
|
Posted: Mon Dec 17, 2007 10:58 am Post subject: RE:Procedure that centers text |
|
|
take a closer look at what you're doing. You're drawing a procedure and that wont work, hence error. What you want to do is find the width of the string using Font.Width(), divide it by 2 and subtract that amount from the x coord. You will probobly want to also structure your procedure like so:
code: |
procedure centerText (text :string, x, y :int)
%draw the text here
end centerText
|
you would then call the procedure like this:
code: |
centerText ("Centered text :)", 200, 200)
|
this will draw "Centered text " at 200 over and 200 up (x, y) |
|
|
|
|
|
|