Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Centre Text?!
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mike200015




PostPosted: Sun Jan 30, 2005 7:30 pm   Post subject: Centre Text?!

Is there any way to centre text automatically instead of trial and error of trying to change the coordinates ??
Sponsor
Sponsor
Sponsor
sponsor
Mr. T




PostPosted: Sun Jan 30, 2005 7:33 pm   Post subject: (No subject)

no
person




PostPosted: Sun Jan 30, 2005 7:48 pm   Post subject: (No subject)

i think there is, since a standard text screen, is 25 rows by 80 columns, so the centre is (1,40)
ssr




PostPosted: Sun Jan 30, 2005 7:58 pm   Post subject: (No subject)

well, u can put the text in middle by doing something like index
first count how many chars are there
then div them by 2
locate (1,maxcol div 2 - the number of char div 2)
put the text
And there u go

Also, u can chaneg the size of thee output window by doing somethign liek
setscreen("graphics:x;y")
yep adn there u go
8)
ssr




PostPosted: Sun Jan 30, 2005 8:05 pm   Post subject: (No subject)

Here's a code for ya
use length to coutn how many chars are there and then use the way I mentioned above! Very Happy Smile

code:

var word : string
var length1:int
    get word:*
    length1:= length (word) div 2
locate ( maxrow div 2,maxcol div 2 - length1)
put word
basketball4ever




PostPosted: Sun Jan 30, 2005 8:09 pm   Post subject: (No subject)

code:
    var len : int := length ("Hello World")
    locate (1, (maxcol - len) div 2)
    put "Hello World" ..


hope it helps...
first u calculate how many letters are in ur string... and set it as a variable, so basically hello world has 11 characters.

Then in ur locate, you have 1 (being the row) then have the max col of the screen, minus the length, so in a default screen... (80-11) then div 2... = the center will be the center leter of ur text, in this case, a space.
ssr




PostPosted: Sun Jan 30, 2005 8:14 pm   Post subject: (No subject)

srry made a mistake ,
subtract first then div
srry
basketball4ever is right, its the same thing as I said
and hopefully it helps! Rolling Eyes
mike200015




PostPosted: Sun Jan 30, 2005 11:17 pm   Post subject: (No subject)

hey, yea thanx .. both of those helped me

but what i dont understand is why you use maxcol?.. isnt that maximum colour? what does that have to do with centring text?
Sponsor
Sponsor
Sponsor
sponsor
mike200015




PostPosted: Sun Jan 30, 2005 11:20 pm   Post subject: (No subject)

o wait.. never mind.. i figured it out.. its maximum column not colour lol

and also how would you incorporate that into Font.Draw , since i usually use that rather than jus the regular put
Bacchus




PostPosted: Sun Jan 30, 2005 11:23 pm   Post subject: (No subject)

no maxcol is for the maximum column, for the maximum color its maxcolor close but no cigar. they use maxcol because the text (even when you use locatxy) gets printed in the row and column specified (nearest row and column for locatexy) except if you dont use locatexy or locate then it starts at the maxrow (or is it row 1? which one is the top lol, i dunno i never use locate Razz) and either decreases or increases by one, depending on which is the top maxrow or 1 lol. rows go across and column go up and down. but you probably kno this so ive just wasted my time explaining.... meh
mike200015




PostPosted: Sun Jan 30, 2005 11:31 pm   Post subject: (No subject)

lol.. yea knew some of that.. but watever.. thanx anyway Very Happy
Bacchus




PostPosted: Sun Jan 30, 2005 11:55 pm   Post subject: (No subject)

lol im bored so i went a bit in depth Razz
Cervantes




PostPosted: Mon Jan 31, 2005 8:26 am   Post subject: (No subject)

mike200015 wrote:
and also how would you incorporate that into Font.Draw , since i usually use that rather than jus the regular put


Turing:

var word := "Hello World"
const fontHeight := 48
var font := Font.New ("Times New Roman:" + intstr (fontHeight))
Font.Draw (word, round ((maxx - Font.Width (word, font)) / 2), round ((maxy - fontHeight) / 2), font, black)

It's the same idea. THINK! Rolling Eyes
ssr




PostPosted: Mon Jan 31, 2005 8:07 pm   Post subject: (No subject)

Yep, but instead of using maxcol adn maxrow, u use maxx and maxy because font draw are measured in pixels instead of rows and columns! Idea
basketball4ever




PostPosted: Mon Jan 31, 2005 8:13 pm   Post subject: (No subject)

ssr wrote:
Yep, but instead of using maxcol adn maxrow, u use maxx and maxy because font draw are measured in pixels instead of rows and columns! Idea


unless you're using locatexy go see my tutorial on basic text stuff Very Happy
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 18 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: