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

Username:   Password: 
 RegisterRegister   
 Turing for Dummies #1 --> How to do texts
Index -> Programming, Turing -> Turing Tutorials
Goto page 1, 2, 3  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
basketball4ever




PostPosted: Sat Jan 29, 2005 8:05 pm   Post subject: Turing for Dummies #1 --> How to do texts

Text:
two good ways of doing text are...
either with the put command, or using Font.Draw

PUT COMMAND

put is your basic text entering code command:

code:
put "Hello"


By entering this, the output screen will show up Hello on the top left corner.

put can also hold variables and numbers
Numbers:

code:
put "2+2"

This displays the string: 2+2
however if
code:
put 2+2

is entered... the display answer will be 4. This is because 2+2 isn't in quotations.

Variables:

variables can also be outputed using the put command. After declaring a variable, all that is need is:


code:
put variablename

and its done.

EXAMPLE:
code:
var mymessage:string:="Hello this is my string."
put mymessage,"How are you?"


A "," can be used to connect two things together.


code:
put "":10,"yo"

see the ":"???
this is spacing. By doing :(then a number) you've set a space between this and the next string.

code:
put "yo"..
put "my name is joe"

now the ".."
two dots, connect one string to the next string in the next line.

Setting colour
first, to make a background for the text (the actual text)
use: colourback(whatever colour you want)

code:
colourback(10)

this will let all text have a background of 10 instead of the default (which is probably white)

code:
colour(10)

this will let your actual font colour to be the colour of 10.

Now that you know how to display text, here's how to manipulate where they're at.

Theres two ways: it can be done according to pixels, or characters

To do it according to characters, use locate
locate needs 2 numbers in brackets, such as:
code:
locate (4,4)


4,4 is the 4th coordinate in rows and 4th coordinate in columns. The start point (1,1) of characters is on the top left corner of the screen.

To do it with pixels, you need:
code:
locatexy(100,100)

This lets you adjust where your text is going to be with pixels instead of characters. However, the start point(0,0) is at the bottom left corner of the screen as oppose to top left corner.



Draw.Font

first thing to do when doing draw.font, is to declare it as a variable.

code:
var font1:int

and yup thats all you have to do... jking Smile

next.. declare wat the font is
code:
font1 := Font.New ("comicsans:14")


Notice the first thing in the quotations is the actual font (make sure its a normal font, or else turing wont load other fonts), and followed by the font size. You can also set if its bold, italic, or underlined
for example:
code:
font1 := Font.New ("Comicsans:14:bold,italic")


After declaring what font1 is... use it!

code:
Font.Draw ("Hello World", 50, 30, font1, red)


see how the first thing in the brackets is the string, like we learnt using the put command. Like the put statement, this can be replaced with a variable string. the next two numbers are coordinates in pixels. Yes Font.Draw is calculated in pixels not by characters. It works exactly the same as locatexy Smile. Afterwards, you see font1... basically what you declared font1 as before, all goes in there Wink making the message in comicsans, size 14, bold, and italic. The last thing in Font.Draw is the colour, in this case red.


And there you have it, the very basic way of doing fonts in turing. Post questions and suggestions to add to this tutorial.
*thanks to all that helped make this tutorial better
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Sun Jan 30, 2005 11:45 am   Post subject: (No subject)

You can't use tags within [code] structures. Fix...
cycro1234




PostPosted: Tue Feb 01, 2005 7:29 pm   Post subject: (No subject)

YAY Laughing Thx a lot for that tutorial, it really helped me out!
Tony




PostPosted: Wed Feb 02, 2005 9:35 am   Post subject: (No subject)

basketball4ever wrote:
Font.Draw is calculated in pixels not by characters

That's why one needs to use Font.Width() to find out where each character is located Wink
Dudewhatzup1




PostPosted: Sun May 01, 2005 2:22 pm   Post subject: (No subject)

Hey what about Center or aline left or right and locate for the Draw.Font?
Dudewhatzup1




PostPosted: Sun May 01, 2005 3:05 pm   Post subject: (No subject)

O im sry i didnt c the 50,30 nevermind Embarassed
Cervantes




PostPosted: Sun May 01, 2005 3:50 pm   Post subject: (No subject)

The 50, 30 doesn't really mean anything significant. If you want to align something to the centre or right edge of the screen, you'll need that nifty tool that tony mentioned: Font.Width

Turing:

var font := Font.New ("Impact:26")

var text := "Watch as I align myself"
var width := Font.Width (text, font)

Font.Draw (text, 0, maxy div 2, font, red)
delay (1000)
cls
Font.Draw (text, round (maxx / 2 - width / 2), maxy div 2, font, red)
delay (1000)
cls
Font.Draw (text, round (maxx - width), maxy div 2, font, red)
SureShot




PostPosted: Mon Feb 26, 2007 10:13 pm   Post subject: RE:Turing for Dummies #1 --> How to do texts

Very helpful TYVM
Sponsor
Sponsor
Sponsor
sponsor
ericfourfour




PostPosted: Mon Feb 26, 2007 10:43 pm   Post subject: Re: Turing for Dummies #1 --> How to do texts

I made a procedure that aligns text on the screen given a percentage (0 = 0%, 1 = 100%).

Turing:
proc alignText (text : string, alignment : real, y, font, clr : int)
    Font.Draw (text,
        round (alignment * (maxx - Font.Width (text, font))), y,
        font, clr)
end alignText

var font := Font.New ("Times New Roman:12")
alignText ("HelloWorld!", 0.5, 100, font, black)
Font.Free (font)


Alignment is the parameter that controls where on the x-axis the text is displayed.

Ex.
0 aligns left.
0.5 aligns centre.
1 is aligns right.
0.28 aligns 28% across the x-axis.
0.99 aligns 99% across the x-axis.
Zren




PostPosted: Wed Dec 10, 2008 2:05 pm   Post subject: Re: Turing for Dummies #1 --> How to do texts

Lekegolo killer @ Wed Dec 10, 2008 1:47 pm wrote:
how do you align/center put statements????


locate (row :int, col :int)
Rows and Columns starts at 1.

Useful Variables:
maxrow: The last row on the screen.
maxcol: The last column on the screen.

The center would be half of the maximum. Be sure to use Integer Division: div.

EDIT: I swear he was just there. :/

Oh well, building on from it since I forgot something.

That would align the first character to the middle. Now we want to center the text. In order to do this we'd have to move the text left or decrease the column number (Col 3 is left of Col 4). Now we need to find the middle of the text. In other words, half the size of your output string. (Hint: It's another div thing).
Tony




PostPosted: Wed Dec 10, 2008 3:02 pm   Post subject: Re: Turing for Dummies #1 --> How to do texts

Zren @ Wed Dec 10, 2008 2:05 pm wrote:
EDIT: I swear he was just there. :/

I've removed that post, because the question is actually answered in the above tutorial.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Lekegolo killer




PostPosted: Tue Dec 16, 2008 2:09 pm   Post subject: Re: Turing for Dummies #1 --> How to do texts

hey thx for the answer, i figured it out on my own b4 you posted but thx anyway. Would anyone mind answering another question? is there anyway to get the text background to be transperent?

I tryed: colourback(colourgoeshere) but i couldn't find a transperent setting (and if you don't use it the colour is white).
gillen15




PostPosted: Fri May 29, 2009 8:39 pm   Post subject: Re: Turing for Dummies #1 --> How to do texts

I have a quick question. When you use the put command, it makes the entire line that the text is on white. I have a background image and the white space goes over the background. I haven't use turing in a couple years and I don't remember if I can fix this problem or not. If you can help that would be great.
saltpro15




PostPosted: Sat May 30, 2009 7:44 am   Post subject: Re: Turing for Dummies #1 --> How to do texts

Lekegolo killer @ Tue Dec 16, 2008 wrote:
hey thx for the answer, i figured it out on my own b4 you posted but thx anyway. Would anyone mind answering another question? is there anyway to get the text background to be transperent?

I tryed: colourback(colourgoeshere) but i couldn't find a transperent setting (and if you don't use it the colour is white).


how can you have a transparent background? That doesn't make sense
Dusk Eagle




PostPosted: Sat May 30, 2009 9:42 am   Post subject: Re: Turing for Dummies #1 --> How to do texts

gillen15, your post should have probably gone in the "Turing Help" forum to ensure more people see it, but I'll answer it here. You must use [url=http://compsci.ca/holtsoft/doc/font_draw.html]Font.Draw[/url to use text with images properly.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

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


Style:  
Search: