
-----------------------------------
Tony
Sun Sep 01, 2002 7:07 pm

[source code] Text Effects
-----------------------------------
I've seen a lot of people trying to make RPG games in turing and some turned out quite nice actually. As Dan about QFTB, he has it posted somewhere.

Most of typical RPGs have plots (atleast they should) and chats with other NPCs. Basically you'll end up displaying a lot of text. In this post I will be posting source codes for different text effects that you can use throughout your games and other applications.

-----------------------------------
Tony
Sun Sep 01, 2002 7:21 pm

Displaying text
-----------------------------------
This is the simpliest way to display text information on the screen:

put "your text here"
if you didn't know that already... well you've got a long way to go.

Here's a better way to display your text -- Font.Draw

var fontID:int := Font.New ("Arial:14:bold")
Font.Draw("Your text here", x,y, fontID, colour)

A bit of explanation -- fontID is a variable that stores information about the font you're using. It has to be an 'int' but can be assigned a value only through Font.New as in example. Arial is the name of the font you're using, if the name doesn't match with anything on computer, the default one is used. 14 stands for the size, you can change it to any integer number. 'bold' makes text bold and is optional. You can also add :italic and/or :underline if you want.
"Your text here" is the text that will be displayed, it can be a string variable. x and y are the coordinates of the lower-left corner where text starts. fontID is the name of the variable decleared earlier. colour is the color of the text to be displayed - place an integer value or a predefined keyword for color.

-----------------------------------
Tony
Sun Sep 01, 2002 7:36 pm

Text Delay
-----------------------------------
Text Delay is the simpliest text effect. What it does is it delays the time between each character being displayed, making it look like the text is being typed while you're reading it. Very useful, especially for games where a lot of text is displayed like RPG.

procedure TextDelay(text:string)
for i : 1..length(text)
put text(i)..
delay(50)
end for
end TextDelay

var text:string
get text:*
TextDelay(text)

I bit of explanation here -- TextDelay is a procedure. This way you can use it again and again in your code just like you use "put" command.

"text" is the name of the string variable passed into the procedure. Then a forloop is run from 1 to the total number of charactes in the string. It is displayed 1 character at a time followed by a delay(50). If you increase the number, text will be typed slower, decrease it to display it quicker.

Note: after putting each character don't forget '..' to keep them all on 1 line and when getting a text string, don't forget to put ':*' to get all the characters including spaces.

And ofcourse you can just put plain text instead of the variable if you already know what to display  :wink: 
TextDelay("hello world!")

-----------------------------------
Tony
Sun Sep 01, 2002 7:50 pm

TextDelay -- Coloured
-----------------------------------
If you didn't know before, text from 'put' command can be colored as well as text from Font.Draw using color(i:int) and colorback(i:int)

color(14)
colorback(1)
put "hello world!"


this will output "hello world!" in yellow color on a blue background.

Now we can take this one step further and include that in previosly shown TextDelay!

procedure TextDelay(text:string)
for i : 1..length(text)
color(red)
locate(5,i)
put text(i)
delay(100)
color(blue)
locate(5,i)
put text(i)
end for
end TextDelay

var text:string
get text:*
TextDelay(text)

This works the same way as before, but at first the character is printed in red, then it turns blue as the next character is printed. If you understand simple TextDelay, you should understand how this one works too.

Note: This procedure uses locate to output this text. In 'locate(5,i)' 5 stands for the row where text will be outputed and should be changed to achive desired results. You should not change 'i' since its the counter for the characters being displayed.

-----------------------------------
Tony
Sun Sep 01, 2002 8:46 pm

3D text
-----------------------------------
Here's something new for you guys -- text in 3D!

Here's the code, take a look

var size:int
var text:string
put "enter text"
get text:*
put "enter size"
get size


var fontID : array 1 .. size of int

for i:size div 2 .. size
fontID(i):=Font.New("Arial:"+intstr(i))
end for

procedure Text3D(text:string)

for t:1..length(text)

for i:size div 2 .. size
Font.Draw(text(t), t*size, 100, fontID(i),20+ floor(i/size*10))
end for

end for

end Text3D

Text3D(text)

Now a bit about how this thing works... variable size is the final size of the text that will be outputed. text is the variable for the... TEXT to be outputed. fontID is just like before is used as a font ID. Though this time its an array since we need many different fonts. Each font is of a different size from small to large. Puting those fonts on top of each other will make text look 3D, here's how:

the main body runs 2 forloops. "for t" runs to count each character in the text to be outputed. "for i" puts fonts from half the size to full size on top of each other.

t*size gives us a value of character position times the final size of the font. that gives a good estimate of spacing between letters. You could adjust that number to finetune spacing for specific fonts.

The color is the tricky part. The idea behind the raycasting is to go from darker to lighter color depending on the distance. this piece of code "20+ floor(i/size*10)" will evenly destribute numbers from 20 to 30 over whatever size you chouse. Numbers 20 to 30 corespond with the gridient from black to white in turing and is the easiest one to use to make it look 3D.

Since the fontID array is decleared based on the size of text desired and is outside of procedure, this effect is generally one time use. If for some crazy reason you would need to use this as often as 'put' command, I'm sure you can rearange the source code to suit your desire.

-----------------------------------
Tony
Mon Sep 02, 2002 8:05 pm

Arched Text
-----------------------------------
This one took me a while... you better like it, or I'm not posting any more  :wink: 

here's the code to make your text in a form of an arch:

NOTE: This code will only work under winoot 4.0.1 or higher because it uses a new "Pic.Rotate" feature not available in previous versions.

var text:string
var fontID:int := Font.New("Arial:14")

put "enter a word"
get text:*

if length(text) rem 2 = 1
then
text:= text +" "
end if

var letter : array 1.. length(text) of int
var angle : array 1.. length(text) of int
var x : array 1..length(text) of int
var y : array 1..length(text) of int


    for i:1..length(text) div 2
    angle(i):= round(90/length(text)*(length(text)-i))
    put angle(i)
    end for

for i:1..length(text) div 2
    y(i):=round ( (length(text)div 2)*30*cosd(angle(i)) )
    x(i):=round ( (length(text)div 2)*60 - (length(text)div 2)*60*sind(angle(i)) )    

    end for
cls
for i:1..length(text)
Font.Draw(text(i), 15, 15, fontID, black)
letter(i) := Pic.New (0,0,30,30)
cls
end for


for i:1..length(text) div 2

letter(i):= Pic.Rotate(letter(i),angle(i), 15,15)
Pic.Draw(letter(i),x(i),y(i),picMerge)

end for

for decreasing i:length(text) div 2 .. 1

letter(i+length(text) div 2):= Pic.Rotate(letter(i+length(text) div 2),360-angle((length(text)div 2)-i+1), 15,15)
Pic.Draw(letter(i+length(text) div 2),x(length(text)div 2)*2-x((length(text)div 2)-i+1),y(length(text) div 2)-y(i)+30,picMerge)

end for


I really don't feel like explaining it right now... I got really frustrated couple of times today while making this.

Basically what it does is that it takes each letter drawn using Font.Draw and saves it as a picture. Then its whole bunch of trigionometry to calculate angles and position of each character to arrangle them in an arch formation.

Calculations were done for the first half and then flipped to make values for second... I run into some problems and this seemed a better way out... might not be the best solution though.

Also, that little IF statment at the beggining of the program will add an extra character if you got an odd number of characters because otherwise last one will disappear.

Also you can change the relative height and width of the arch by messing with declaration of X and Y

    y(i):=round ( (length(text)div 2)*30*cosd(angle(i)) )
    x(i):=round ( (length(text)div 2)*60 - (length(text)div 2)*60*sind(angle(i)) )    

in Y, *30* is a relative height of the arch...you can change that... In X, *60 - is the center of the arch, you can move the text left and right by changing this number. The *60* part is the relative width of the arch, you can change this to make the arch wider or thiner.

This effect might be a good use for generating custom arched signs for things like park entrances or something... Who knows what kind of stuff you guys are making out there, I'm just giving you source code to use.

-----------------------------------
Mazer
Mon Oct 07, 2002 9:56 am


-----------------------------------
i liked the text delay with colour but it isn't that impressive since you're still stuck the the stupid turing run window font. think you could come up with a way to use that type of proc with Font.Draw? that would be impressive. don't worry about the text getting cut off i'd just like to see it done even with a few letters.

-----------------------------------
JayLo
Thu Mar 20, 2003 7:59 pm


-----------------------------------
yes tony. it would be impressive.

-----------------------------------
JayLo
Thu Mar 20, 2003 8:17 pm

Font.Draw in TextDelay
-----------------------------------
here it is. not as hard as I thought.
Text Delay involving Font.Draw!
var size : int
var colorText : int
var text : string
put "enter text"
get text : *
put "enter size"
get size
put "enter colour"
get colorText

var fontID : int
var text3DLetter : array 1 .. length (text) of string
fontID := Font.New ("Verdana:" + intstr (size))

procedure text3DDelay (text : string)
    for i : 1 .. length (text)
        text3DLetter (i) := text (i)
    end for
    for t : 1 .. length (text)
        Font.Draw (text3DLetter (t), t * size, maxy div 2, fontID, colorText)
        delay (50)
    end for
end text3DDelay
text3DDelay (text)



MOD EDIT: gave you some bits for this, good work. -Dan

-----------------------------------
Asok
Thu Mar 20, 2003 9:18 pm


-----------------------------------
Jay Lo, there are some spacing issues with your code you should address.

-----------------------------------
Tony
Thu Mar 20, 2003 9:55 pm


-----------------------------------
well spacing with font.draw would be my bad... I assumed that the size of a letter in pixels would equal to its size. Which is almost accurate. Atleast it would be with a fixed width font.

-----------------------------------
Catalyst
Thu Mar 20, 2003 10:19 pm


-----------------------------------
jus tuse Font.WIdth

-----------------------------------
Catalyst
Thu Mar 20, 2003 10:21 pm


-----------------------------------
here i fixed the spacing issue in ur code



var size : int
var colorText : int
var text : string
put "enter text"
get text : *
put "enter size"
get size
put "enter colour"
get colorText
var buff : string := ""
var fontID : int
var text3DLetter : array 1 .. length (text) of string
fontID := Font.New ("Verdana:" + intstr (size))

procedure text3DDelay (text : string)
    for i : 1 .. length (text)
        text3DLetter (i) := text (i)
    end for
    for t : 1 .. length (text)
        Font.Draw (text3DLetter (t), 50 + Font.Width (buff, fontID), maxy div 2, fontID, colorText)
        delay (50)
        buff += text3DLetter (t)
    end for
end text3DDelay
text3DDelay (text)


Mod Edit: gave some bits for the improved code :) - Tony

-----------------------------------
Asok
Fri Mar 21, 2003 12:43 am


-----------------------------------
Excellent job Catalyst!

-----------------------------------
JayLo
Fri Mar 21, 2003 6:23 pm

lol
-----------------------------------
catalyst puts me to shame...  :oops:

-----------------------------------
Delta
Fri Mar 21, 2003 10:55 pm

Text Effect Number 1
-----------------------------------
Types out the text

procedure TypeThis (word:string, speed:int)
    for i : 1 .. length(word)
        put word(i)..
        delay (speed)
    end for
    put ""
end TypeThis

TypeThis ("Text Effect", 100)
TypeThis ("Number 1", 100)


-----------------------------------
Tony
Fri Mar 21, 2003 11:00 pm


-----------------------------------
isnt it the same as textDelay :?

-----------------------------------
Delta
Fri Mar 21, 2003 11:04 pm


-----------------------------------
Here is the same thing just with some extras and using Font.Draw

procedure TypeThis (word:string, x, y :int, size, clr, speed:int)
    var font : int := Font.New ("Arial:"+intstr(size))
    for i : 1 .. length(word)
        Font.Draw (word(1..i), x, y, font, clr)
        delay (speed)
    end for
    put ""
end TypeThis

TypeThis ("Text Effect",100, 300, 20,14, 100)
TypeThis ("Number 2", 50,100, 50,12,100)


-----------------------------------
Delta
Fri Mar 21, 2003 11:06 pm

I'm sorry
-----------------------------------
Sorry if some of the text effects are the same I'm just posting what ever I can think of

-----------------------------------
Delta
Fri Mar 21, 2003 11:17 pm

Text Effect Number3
-----------------------------------
Fades in text using Font.Draw

procedure FadeThisIn (word:string, x, y :int, size, speed:int)
    var font : int := Font.New ("Arial:"+intstr(size))
    for decreasing i : 31 .. 16
        Font.Draw (word, x, y, font, i)        
        delay (speed)
    end for
    put ""
end FadeThisIn

FadeThisIn ("Text Effect", 300, 100, 75, 100)
FadeThisIn ("Number 3", 200, 50, 45, 500)


to fade out for i : 16 .. 31 fades from black to white

-----------------------------------
Delta
Fri Mar 21, 2003 11:25 pm

Text Effect Number 4
-----------------------------------
Flashes the letters in the word

procedure LetterFlash (word:string)
    var font : int := Font.New ("Arial:50")
    for i : 1..length(word)
        Font.Draw (word(1..i), 200, 200, font, 28)
        if i > 1 then
            Font.Draw (word(1..i-1), 200, 200, font, 0)
        end if
        delay (100)
    end for
end LetterFlash

LetterFlash ("Text Effect Number 4")


-----------------------------------
Catalyst
Sat Mar 22, 2003 12:54 pm


-----------------------------------
This makes the text explode and unexplode, (note for now only on a black background)

setscreen ("offscreenonly,graphics:320;150,nobuttonbar")

proc ExplodeText (x0, y0 : int, text00 : string, font : int, c0 : int)
    var clr, c : int := 0
    var r, g, b : real
    RGB.GetColor (c0, r, g, b)
    for i : 1 .. 255
        clr := RGB.AddColor ((i * r) / 255, (i * g) / 255, (i * b) / 255)
    end for
    type Particle :
        record
            x, y, xV, yV : real
            life, c : int
        end record

    drawfillbox (0, 0, maxx, maxy, 7)
    var text : string := text00
    Font.Draw (text, x0, y0, font, c0)
    var screen : array 1 .. maxx, 1 .. maxy of int
    const numP := 200
    const maxLife := 25
    var main : flexible array 1 .. 1 of Particle
    for x : 1 .. maxx
        for y : 1 .. maxy
            if whatdotcolor (x, y) = c0 then
                c += 1
                new main, c
                main (c).x := x
                main (c).y := y
                main (c).xV := Rand.Int (-5, 5) * Rand.Real
                main (c).yV := Rand.Int (-5, 5) * Rand.Real
                main (c).life := maxLife
                main (c).c := whatdotcolor (x, y)
            end if
        end for
    end for
    loop
        for i : 1 .. c
            main (i).x += main (i).xV
            main (i).y += main (i).yV
            main (i).life -= 1
            if main (i).life > 0 then
                drawdot (round (main (i).x), round (main (i).y), round ((main (i).life / maxLife) * 255) + 255)
            end if
        end for
        View.Update
        drawfillbox (0, 0, maxx, maxy, 7)
        exit when main (1).life = maxLife
    end loop
end UnExplodeText


var font : int := Font.New ("verdana:36:bold")
loop
    ExplodeText (50, 50, "Catalyst", font, 103)
    cls
    UnExplodeText (50, 50, "Catalyst", font, 103)
    View.Update
end loop

MOD Edit: I never realized we had such awesome turing programmers here already :? This effect by far is the best! +15Bits, I'm VERY impressed -Tony
MOD Edit: This is godly! Adding an additional +5 Bits! -Asok

-----------------------------------
Catalyst
Sat Mar 29, 2003 1:29 am


-----------------------------------
bored... racecar effect...


View.Set ("nobuttonbar,graphics:650;100,position:300;300,offscreenonly")

var font : int := Font.New ("verdana:45:bold")
var a, c : int := 0000

var x0, y0 : int := 20

var text : string := "               Catalyst"
var buff : string := ""
var x, y : array 1 .. length (text) of int

for i : 1 .. length (text)
    x (i) := x0 + Font.Width (buff, font)
    y (i) := y0
    buff += text (i)
end for

for decreasing i : length (text) .. 1
    for k : 1 .. x (i)
        Font.Draw (text (i), k, y (i), font, 7)
        View.Update
        delay (1)
        Font.Draw (text (i), k - 2, y (i), font, 0)
    end for
    Font.Draw (text (i), x (i), y (i), font, 7)
    View.Update
    delay (50)
end for

MOD Edit: Those effects just keep on comming  :D +10Bits -Tony

-----------------------------------
BlAcK TuRtLe
Mon Mar 31, 2003 7:51 pm


-----------------------------------
Thanks for the help. Here is a primitive piece of crap I just made
%Logo
Draw.Arc(200,200,50,100,0,180,yellow)
Draw.Arc(300,200,50,100,0,180,yellow)
Draw.FillBox(125,115,375,200,brightred)
Draw.Arc(200,200,25,100,0,180,yellow)
Draw.Arc(300,200,25,100,0,180,yellow)
Draw.FillMapleLeaf(370,200,400,230,red)
%Text
var y:int := Font.New ("Arial:26:bold") 
Font.Draw("McDonalds",160,150,y,yellow)
delay(2000)
Draw.FillBox(125,115,375,200,brightred)
var x:int := Font.New ("Arial:14:bold") 
Font.Draw("We love to see you smile",130,150,x,yellow)
delay(2000)
Draw.FillBox(125,115,375,200,brightred)
var z:int := Font.New ("Arial:14:bold") 
Font.Draw("Billions served everyday",130,150,z,yellow)


-----------------------------------
Tony
Mon Mar 31, 2003 8:18 pm


-----------------------------------
lol, not exactly a text effect, but its still cool  :wink:

-----------------------------------
Catalyst
Mon Mar 31, 2003 10:25 pm


-----------------------------------
looked at my last post here (racecar) an got and idea...


setscreen ("offscreenonly,graphics:800;150,nobuttonbar")

proc ExplodeText (x0, y0 : int, text00 : string, font : int, c0 : int)
    var clr, c : int := 0
    var r, g, b : real
    RGB.GetColor (c0, r, g, b)
    for i : 1 .. 255
        clr := RGB.AddColor ((i * r) / 255, (i * g) / 255, (i * b) / 255)
    end for
    RGB.GetColor (103, r, g, b)
    for i : 1 .. 255
        clr := RGB.AddColor ((i * r) / 255, (i * g) / 255, (i * b) / 255)
    end for
    type Particle :
        record
            x, y, xV, yV : real
            life, c, trig : int
        end record

    drawfillbox (0, 0, maxx, maxy, 7)
    var text : string := text00
    Font.Draw (text, x0, y0, font, c0)
    var screen : array 1 .. maxx, 1 .. maxy of int
    const numP := 200
    const maxLife := 75
    var main : flexible array 1 .. 1 of Particle
    for x : 1 .. maxx
        for y : 1 .. maxy
            if whatdotcolor (x, y) = c0 then
                c += 1
                new main, c
                main (c).x := x
                main (c).y := y
                main (c).xV := +5
                main (c).yV := 0
                main (c).life := maxLife
                main (c).c := whatdotcolor (x, y)
                main (c).trig := 0
            end if
        end for
    end for
    loop
        for i : 1 .. c
            main (i).x += main (i).xV
            main (i).y += main (i).yV
            if main (i).x >= 750 and main (i).trig = 0 then
                main (i).trig := 1
                main (i).xV := (main (i).xV * -1) * Rand.Real
                main (i).yV := Rand.Int (-5, 5) * Rand.Real
            end if
            if main (i).trig = 1 then
                main (i).life -= 1
                main (i).yV-=0.05
            end if
            if main (i).life > 0 then
                if main (i).trig = 0 then
                    drawdot (round (main (i).x), round (main (i).y), round ((main (i).life / maxLife) * 255) + 255)
                else
                    drawdot (round (main (i).x), round (main (i).y), round ((main (i).life / maxLife) * 255) + 510)
                end if
            end if
        end for
        View.Update
        drawfillbox (0, 0, maxx, maxy, 7)
    end loop
end ExplodeText

var font : int := Font.New ("verdana:36:bold")
ExplodeText (210, 50, "Catalyst", font, 103)


-----------------------------------
Catalyst
Mon Mar 31, 2003 10:28 pm


-----------------------------------
this happened to come about when i was making the last one...

(altho i dont need to for some reason i still use particles)

setscreen ("offscreenonly,graphics:800;150,nobuttonbar")

proc ExplodeText (x0, y0 : int, text00 : string, font : int, c0 : int)
    var clr, c : int := 0
    var r, g, b : real
    RGB.GetColor (c0, r, g, b)
    for i : 1 .. 255
        clr := RGB.AddColor ((i * r) / 255, (i * g) / 255, (i * b) / 255)
    end for
    type Particle :
        record
            x, y, xV, yV : real
            life, c : int
        end record

    drawfillbox (0, 0, maxx, maxy, 7)
    var text : string := text00
    Font.Draw (text, x0, y0, font, c0)
    var screen : array 1 .. maxx, 1 .. maxy of int
    const numP := 200
    const maxLife := 25
    var main : flexible array 1 .. 1 of Particle
    for x : 1 .. maxx
        for y : 1 .. maxy
            if whatdotcolor (x, y) = c0 then
                c += 1
                new main, c
                main (c).x := x
                main (c).y := y
                main (c).xV := +5
                main (c).yV := 0
                main (c).life := maxLife
                main (c).c := whatdotcolor (x, y)
            end if
        end for
    end for
    loop
        for i : 1 .. c
            main (i).x += main (i).xV
            main (i).y += main (i).yV
            if main (i).x < 200 and main (i).life < maxLife then
                main (i).life += 1
            end if
            if main (i).x > 600 then
                main (i).life -= 1
            end if
            if main (i).x >= 800 then
                main (i).x -= 900
            end if
            if main (i).life > 0 then
                drawdot (round (main (i).x), round (main (i).y), round ((main (i).life / maxLife) * 255) + 255)
            end if
        end for
        View.Update
        drawfillbox (0, 0, maxx, maxy, 7)
    end loop
end ExplodeText

var font : int := Font.New ("verdana:20:bold")
ExplodeText (210, 50, "Catalyst - It's a Marquee...", font, 103)


-----------------------------------
Tony
Mon Mar 31, 2003 10:59 pm


-----------------------------------
:D AWESOME... just AWESOME.

+20Bits ofcourse... each :wink:

-----------------------------------
Tony
Sat Apr 05, 2003 3:36 pm


-----------------------------------
Count-Down  :D 

Note: This text effect works only in v4+ compilers because of View.Update. The effect will work in v3 if View.Update is removed, but it will flicker. If you want to use it in v3 anyway, atleast get rid of cls to reduce flicker amount.


procedure CountDown(numFrom,numTo,speed:int)

View.Set("offscreenonly") %flicker free animation, v4 compiler only
var fontID:array 1..ceil(maxy*1.5) of int %declear variables for fonts

for i:1..ceil(maxy*1.5)
fontID(i):= Font.New("arial:"+intstr(i)) %declearing fonts of sizes we need
end for

for decreasing num:numFrom..numTo %starting count down loop

for i:1..ceil(maxy*1.5) by speed %starting loop for zooming numbers in
Font.Draw(intstr(num),round(maxx/2 - i/3 - Font.Width(intstr(num),fontID(i))/4),round(maxy/2-i/2),fontID(i),round(17+i/ceil(maxy*1.5)*13))
%just draws the number where its suppost to be, X,Y,Color
View.Update %updates image
cls %clears screen
end for

end for

View.Set("nooffscreenonly") %disable offscreenonly and returns to previous mod

for i:1..ceil(maxy*1.5)
Font.Free(fontID(i)) %clean up after ourselves
end for 

end CountDown %and we're done


%now to call the procedure and test it out.
%arguments are:
%Count down from: int
%Count down to: int
%Speed :int ~ larger num = faster countdown
CountDown(10,1,10)


Counts down from/to numbers your specify. Good for the start of the "movie" or whenever you need to count down to something.

Also this procedure is screen-size independant. Meaning it would work properly in any screensize of your program.

Note: if you count in single digits only, you can take out - Font.Width(intstr(num),fontID(i))/4 Its there just to fix positioning of 2 digit numbers.

-----------------------------------
void
Mon Apr 07, 2003 6:34 pm

patch
-----------------------------------
is there a patch i can get for v3 to run v4 programs because i really dont feel like paying money for v4 but all these neat effects require v4 because of the one line that all of them use "View.Update"  :evil: if anyone knows of any site where i can in theory "GET" this v4 of winOOT...a link would be much appreciated or a link to a patch..(my skools too cheap for v4)

-----------------------------------
Dan
Mon Apr 07, 2003 7:03 pm


-----------------------------------
i do not bilve there is a pach for 3.1.1 to 4.X . Also the only site i know of that has pachs for turing is holths site.

-----------------------------------
haujobb
Tue Apr 15, 2003 9:28 am


-----------------------------------
Didn't see this anywhere else so...


var intTextLength : int := 0
var realTextLength : int := 0
var where : int := 0
var text : string := " "

procedure textCenter (text : string, where : int)
    intTextLength := length (text)
    realTextLength := intTextLength / 2
    intTextLength := round (realTextLength)
    locate (where, 60 - intTextLength)
    put text
end textCenter

textCenter ("The text... is centered!", 1)


The first variable passed is the text that you want displayed and the second variable is which row you want it displayed on...

Also... the Y coordinate - in this case 60 - intTextlength - only works with the screen size I used to you might have to alter that value.

-----------------------------------
Tony
Tue Apr 15, 2003 10:09 am


-----------------------------------
if you replace 60 with maxcol it would work for any window size :wink:


Also, there is no patch from v3 to v4 since v4 was rewriten from scrach.

You can take out View.Update and View.Set("offscreenonly") as the rest of the code should be compatible with v3. The only downside is flashing.

-----------------------------------
haujobb
Tue Apr 15, 2003 10:16 am


-----------------------------------
60 is the center of the screen, so it would be maxcol \ 2.

Good idea tho, I'm gonna use that now...

-----------------------------------
Blade
Sat Apr 19, 2003 3:01 pm


-----------------------------------
if you replace 60 with maxcol it would work for any window size :wink:


Also, there is no patch from v3 to v4 since v4 was rewriten from scrach.

You can take out View.Update and View.Set("offscreenonly") as the rest of the code should be compatible with v3. The only downside is flashing.

so thats why sprites dont work in 4.... wierd stuffs..

-----------------------------------
Blade
Thu May 22, 2003 11:22 am


-----------------------------------
here's my 2 cents worth of text effect :) it might help some though because there was a question in turing help forum

var x : int := 100
const y := 100
var font : int := Font.New ("Arial:30")
procedure drawword (word : string (30), del : int)
    for i : 1 .. length (word)
        Font.Draw (word (i), x, y, font, black)
        delay (del)
        x += Font.Width (word (i), font)
    end for
    x := 100
    for i : 1 .. length (word)
        Font.Draw (word (i .. *), x, y, font, black)
        delay (del)
        x += Font.Width (word (i), font)
        cls
    end for
    cls
end drawword

drawword ("WAAAZZZAAAP???", 100)
 - hope it helps someone

MOD EDIT: Fixed some typos so it actually works. -Asok

-----------------------------------
AsianSensation
Sun Jul 20, 2003 12:28 pm


-----------------------------------
One more text effect....

3D(sort of) text rising


View.Set ("offscreenonly")
var fontID := Font.New ("Ariel:50:Bold")
var x, y := 50
for rep : 1 .. 15
    Font.Draw ("Hello", x, y + rep, fontID, 16)
    delay (50)
    View.Update
    if rep not= 15 then
        Font.Draw ("Hello", x, y + rep, fontID, 20)
    end if
end for


I got this idea when I was looking back at my midterm mario rpg game. It works the same way with a picture.

readjust the delays for different computer.

-----------------------------------
AsianSensation
Sun Jul 20, 2003 4:59 pm


-----------------------------------
here is a better version of the above one, more 3D-ish...

View.Set ("offscreenonly")
var clr : int
const depth : int := 15
var counter := 256 + depth
var fontID := Font.New ("Ariel:50:Bold")
var x := (maxx - Font.Width ("AsianSensation", fontID)) div 2 + depth
var y := 200

for rep : 1 .. depth + 1
    clr := RGB.AddColor (1, rep / (depth + 1), 1)
end for

for rep : 1 .. depth
    Font.Draw ("AsianSensation", x - rep, y + rep, fontID, purple)
    delay (50)
    View.Update
    if rep not= depth then
        Font.Draw ("AsianSensation", x - rep, y + rep, fontID, counter)
    end if
    counter -= 1
end for

Tweaking with the RGB value will give you different color displays.

Also, tweak depth for how much it rises.

Edit: Well, fixed some error, and made it look better, especially with the purple color :P 

-----------------------------------
SilverSprite
Tue Jul 22, 2003 2:34 pm


-----------------------------------
Sucky..

-----------------------------------
AsianSensation
Sun Aug 10, 2003 11:51 am


-----------------------------------
Well, time again for the AsianSensation text effect of the.....um.....month, yeah!  8) 

View.Set ("offscreenonly")
colorback (7)
cls

var word := "AsianSensation"
var font := Font.New ("Arial:30:Bold")
const xpos := 200
const ypos := 100

var dot : array xpos .. xpos + Font.Width (word, font), ypos .. ypos + 30 of int

var clr : int
const width := Font.Width (word, font)

for decreasing rep : width .. 0
    clr := RGB.AddColor (rep / (width), rep / (width), rep / (width))
end for
clr := RGB.AddColor (0, 0, 0)
var clrc := maxcolor

Font.Draw (word, xpos, ypos, font, white)

for x : xpos .. xpos + Font.Width (word, font)
    for y : ypos .. ypos + 30
        if whatdotcolor (x, y) = white then
            dot (x, y) := 1
        else
            dot (x, y) := 0
        end if
    end for
end for

for x : xpos .. xpos + Font.Width (word, font)
    for y : ypos .. ypos + 30
        if dot (x, y) = 1 then
            drawdot (x, y, clrc)
            %View.Update
        end if
    end for
    clrc -= 1
end for


Text shading, I haven't seen this up here, just thought it was useful...

now all I need is a sliding shade fade for text...

maybe I'll work it out for next month 8)

Edit: lol, I realized that I spelt AsianSensation wrong, lol. I also "fixed" that outline thing, and spelt Arial correctly, lol

-----------------------------------
SilverSprite
Sun Aug 10, 2003 12:41 pm


-----------------------------------
this is even crappier lol

-----------------------------------
PaddyLong
Sun Aug 10, 2003 2:22 pm


-----------------------------------
a good idea ... unfortunately it looks kind of grubby because of that outline or something lol

btw you spelt arial wrong

-----------------------------------
AsianSensation
Mon Aug 11, 2003 9:47 am


-----------------------------------
lol, I spelt Arial wrong, guess you found another error in the Turing help document, lol. I only copy and pasted what's on the help file.

btw, what outline are you talking about? If you mean that line that goes from left to right while shading, just comment off View.Update, and it shouldn't appear anymore.

-----------------------------------
PaddyLong
Mon Aug 11, 2003 11:28 am


-----------------------------------
no I mean around some of the first letters you can see a few miscoloured pixels...

-----------------------------------
Tony
Sat Oct 04, 2003 11:05 pm


-----------------------------------
This weekend I saw foolproof and desided to try and reprocude the text effect they have in the opening. Its basically a random line of hex numbers (well not really hex, but of 2 digit sets) that randomly rotate into the text wanted. This is what I came up with


%text effect from movie "foolproof"
%programmed by Tony Targonski
%Started October 03.2003
%Finished October 04.2003

%draw procedure
procedure draw(picL1:int, picN1:int ,x:int, y:int, step:int)

var picL:int := picL1
var picLtemp:int
var picN:int := picN1
var picNtemp:int


var i:int := step

if step0 then

picNtemp:=Pic.Scale(picN,21-i,20)
Pic.Draw(picNtemp,x+round(i/2),y,picMerge)
Pic.Free(picNtemp)

elsif step>20 and step40 then
Pic.Draw(picL,x,y,picMerge)
elsif step nRows then %time to turn binary back into letters
            for i : 1 .. length (text)
                list (i) := list (i) (2 .. *) %cut leading bit off
            end for
        end if

        for i : 1 .. length (text) %for each column
            for l : 1 .. length (list (i)) %for each digit


                %this number thingy makes sure that letters dont fall below sertain level
                if s > nRows then
                    number := nRows
                else
                    number := s
                end if

                Font.Draw (list (i) (l), i * 20, maxy - number * 14 + l * 14, fontID, black)

            end for

        end for
   %     drawline (0, maxy - 10 * 14, maxx, maxy - 10 * 14, black)
        
        for i:1..length(text)
        Font.Draw(text(i),i*20,maxy-nRows*14,fontID,black)
        end for
        Draw.FillBox(0,maxy-nRows*14+14,length(text)*20+20,maxy-nRows*14+round((s-nRows)/8*13),white)
        
        View.Update
        delay (250)
        cls
    end for

    for i:1..length(text)
    Font.Draw(text(i),i*20,maxy-nRows*14,fontID,black)
    end for
    View.Update %show off text to last
    
end binaryFall


kind of documented... not really... should be straight-farward.

The binary that's falling are real binary values of text passed to the method. Reading from bottom to up.

to run the effect:

View.Set("offscreenonly")
binaryFall ("tony is bored", 20)


where it's
binaryFall(text:string, number_of_rows_to_fall:int)

-----------------------------------
thoughtful
Tue Oct 28, 2003 6:05 pm

My lame effect
-----------------------------------
This is a lame strike out effect i made. Still has some length issues.

var font : int

var strike : string
procedure strikeout (word : string, x : int, y : int, fontsize : int ,delaytime:int)

    font := Font.New ("Ariel:" + intstr (fontsize))
    Font.Draw (word, x, y, font, black)
    strike := repeat ("_", length (word)- length (word) div 10 )
    if length(strike)=1 then
    Font.Draw (strike, x, y + (fontsize div 2), font, black)
    else
    for i: 1..length(strike)
    Font.Draw (strike(1..i), x, y + (fontsize div 2), font, white)
    Font.Draw (strike(1..i-1), x, y + (fontsize div 2), font, black)
    delay(delaytime)
    end for
    Font.Draw (strike, x, y + (fontsize div 2), font, black)
    end if
end strikeout


At the end try this to call the procedure

strikeout ("Thoughtful", 100, 100, 20,100)


-----------------------------------
Tony
Tue Oct 28, 2003 6:51 pm


-----------------------------------
I'm not sure if this would help, but

Font.Width(text:string, fontID:int)

might come in handy. It tells you the width of a textstring using sertain font in pixels.

-----------------------------------
thoughtful
Tue Oct 28, 2003 7:53 pm

Thnx
-----------------------------------
Hey thnx, now the length problem is fixed using the command u gave me.
I also added custom color. But still the effect is petty lame will do a better one if got more time. :oops: 


var strike : string
procedure strikeout (word : string, x : int, y : int, fontsize : int ,delaytime:int,clr:int)

    var font := Font.New ("Ariel:" + intstr (fontsize))
    Font.Draw (word, x, y, font, clr)
    strike :="_"
    loop
    exit when Font.Width(word, font)