Computer Science Canada

Turing for Dummies #1 --> How to do texts

Author:  basketball4ever [ 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

Author:  Delos [ Sun Jan 30, 2005 11:45 am ]
Post subject: 

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

Author:  cycro1234 [ Tue Feb 01, 2005 7:29 pm ]
Post subject: 

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

Author:  Tony [ Wed Feb 02, 2005 9:35 am ]
Post 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

Author:  Dudewhatzup1 [ Sun May 01, 2005 2:22 pm ]
Post subject: 

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

Author:  Dudewhatzup1 [ Sun May 01, 2005 3:05 pm ]
Post subject: 

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

Author:  Cervantes [ Sun May 01, 2005 3:50 pm ]
Post 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)

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

Very helpful TYVM

Author:  ericfourfour [ 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.

Author:  Zren [ 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).

Author:  Tony [ 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.

Author:  Lekegolo killer [ 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).

Author:  gillen15 [ 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.

Author:  saltpro15 [ 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

Author:  Dusk Eagle [ 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.

Author:  yetiboy [ Tue Jun 01, 2010 8:40 am ]
Post subject:  Re: Turing for Dummies #1 --> How to do texts

Is there a way to change the font/text the user types with? I'd like to match up the user input with what I'm using in Font.Draw.

brad

Author:  DemonWasp [ Tue Jun 01, 2010 9:27 am ]
Post subject:  RE:Turing for Dummies #1 --> How to do texts

Not trivially; if you want that effect you'll have to write a bit of code to do it yourself. There's a very similar request in the Turing Help section recently; try looking there for it.

Author:  Insectoid [ Tue Jun 01, 2010 3:11 pm ]
Post subject:  RE:Turing for Dummies #1 --> How to do texts

I did one in my blackjack program last year. It's not perfect, and I forgot some features but you can see how I went about doing it. There's some hackish code in my implementation but it works and not to shabbily.

Author:  chrisbrown [ Tue Jun 01, 2010 4:15 pm ]
Post subject:  RE:Turing for Dummies #1 --> How to do texts

Just so you have a starting point:
    Begin with an empty string
    Read one character at a time using hasch and getch or getchar (trivial difference)
    Modify the string, handling the special cases for enter and backspace
    Font.Draw the string


@Insectoid: I'm sure you had your reasons for doing so, but drawing one character at a time makes me cringe.

Author:  Insectoid [ Tue Jun 01, 2010 5:40 pm ]
Post subject:  RE:Turing for Dummies #1 --> How to do texts

I think it was 'cause I didn't want to clear/update the screen and this way I could just draw a box over the old letters to 'erase' it.

Author:  Krocker [ Thu Jan 20, 2011 11:55 am ]
Post subject:  RE:Turing for Dummies #1 --> How to do texts

is there a way of adding an entrance effect to Font.Draw?

Author:  Insectoid [ Thu Jan 20, 2011 12:00 pm ]
Post subject:  RE:Turing for Dummies #1 --> How to do texts

If you mean things like drawing letters one at a time, easy. Just use a for loop and Font.Draw one letter of a string at a time.

Author:  Krocker [ Thu Jan 20, 2011 12:49 pm ]
Post subject:  RE:Turing for Dummies #1 --> How to do texts

interesting, but no. i meant like fade ins and text swirling into the center, blah, blah. that sort of animation

Author:  Tony [ Thu Jan 20, 2011 12:51 pm ]
Post subject:  RE:Turing for Dummies #1 --> How to do texts

Yes, but you have to anime all the steps yourself. Similar advice applies -- use for-loops.

Author:  Krocker [ Thu Jan 20, 2011 1:05 pm ]
Post subject:  RE:Turing for Dummies #1 --> How to do texts

k , nvm

Author:  compnerd101 [ Tue Jan 03, 2012 12:16 am ]
Post subject:  Re: Turing for Dummies #1 --> How to do texts

hey peoples. srry for reopening this thread after a while, but i have a quick question: how do i color SIMPLE output text. i.e if i put into turing:

code:
put "Hi how are you"



how would i color the "Hi how are you" part to be displayed in the color green upon output?

Author:  Tony [ Tue Jan 03, 2012 12:51 am ]
Post subject:  RE:Turing for Dummies #1 --> How to do texts

color

Author:  Fortes [ Fri Dec 07, 2012 8:11 pm ]
Post subject:  RE:Turing for Dummies #1 --> How to do texts

Is there a way to make the font bold or italic?

Author:  Insectoid [ Fri Dec 07, 2012 8:28 pm ]
Post subject:  RE:Turing for Dummies #1 --> How to do texts

If I remember correctly, this is only possible via Font.Draw.

Author:  lanceahsi02 [ Thu Feb 04, 2021 2:21 pm ]
Post subject:  RE:Turing for Dummies #1 --> How to do texts

how to print the location of the highest number in the array?

Author:  scholarlytutor [ Sat Feb 06, 2021 2:20 pm ]
Post subject:  RE:Turing for Dummies #1 --> How to do texts

Hi lanceahsi02,

Do you want to post your question in the Turing Help section? I'll be happy to help you there.


: