We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi, i'm an italian student and i'm learning this fantastic programming language :)
i'm doing a project for my university, where i would like to have a text (internal or with an external file doesn't matter) that appears letter by letter like i'm typing it manually, is it possible? i'm searching everywhere but i was capable only to draw a WORD than substitute it with another word, but is not my case i want that all the letters i type stay and generate a full text ^^ i hope my english is good enough to let you understand what i need.
thanks any help would be 100% appreciated
Answers
@GGileWP:: if i understand it s a kind of type writer you want have a look to Rita lib and the Rita typeWriter example
@akenaton is in this forum? can i have a link please?
Google
So here you go .. http://openprocessing.org/sketch/113262
It is one of my old code and you can reuse it.
to be honest, I wouldn't use the library and not use blyks approach
Do you know how
setup()
anddraw()
work?so when you have
background(0);
at the beginning ofdraw()
you clear you canvas.now, what you want to do is each time draw runs, show the same word again, but with one letter more. The trick is the "one letter more" part. 1st round you want to show 0, then 1, then 2 letters etc. - so you need a variable howManyLettersToShow or so to store that number and increase it at the end of
draw()
.then e.g. look at
substring()
to use howManyLettersToShow(or your teacher wants you to use a for-loop, the use howManyLettersToShow as an upper bound)
and look at framerate() please, see reference for all of those.
then do come back with detail question and showing your code
thank you!
Best, Chrisir ;-)
Cool. I'm trying to work this out, too. (If I can't, I'll try the blyk answer, thanks) Just started, here's where I'm at:
So, this sort of works- but a StringIndexOutOfBoundsException happens once the String has completed.
Does this work?
the function howmanyletterstoshow is a little over done but never mind
Remember to hit ctrl-t in the processing to get auto format please
;-)
A related discussion:
http://forum.processing.org/two/discussion/comment/41776/
:)
//overdone as in the name is too long? it works the first time, but I'm not able to reuse it. The second time I call it, (with k1 as a string parameter) the text just appears as a string, instead of 'type writer-ing' letter by letter.
//accidental double post
You need to reset lts to 0
Also if I were you, I would have nothing outside the if-stage-clauses in draw()
Meaning the first line with test should also be in if(stage==0)
because now test would appear in all stages
Only background must be in the first line (outside if)
Afaik it makes sense to use the function mousePressed instead of the variable with the same name, since now (where you use the latter) it can happen that one mouse click is registered 3 times by the sketch.
The function doesn't do this.
As linked, an OOP approach:
Cool! Plenty to think about. Thanks all!
%
is the modulo operator. It keeps the incrementing value within desired max (array length). try this:I could have said:
But then I can't use
++
so first I incrementindex++
then I use modulo to avoid kep it in desired rangeindex%=s.length;
. Same thing asindex = index % s.length;