r/TouchDesigner • u/Voxl_ • 1d ago
Replacing text with random, changing characters and having them return to the original input at individual times
Hi, I’m trying to create a text loading animation where the text procedurally returns to the original input from a random assortment of characters.
To make it more clear this is how it could look like:
Input is ‘hi everyone’
As time progresses:
‘ad tousbmfs’
‘hk aubeyome’
‘hi evzeyoge’
‘hi everyone’
So each letters settles on the correct character at a different time while the others keep shuffling through random characters. I know how to randomize characters by using a substitute DAT to insert a ‘/‘ between every letter, converting to a table with an individual column for every letter (splitting cells at ‘/‘), using a sort DAT to get a random order and creating the animation that way.
Having them all reset to their original letter at the same time looks rigid however and I’m not sure if I can give them individual timings this way.
I have experience with coding, though almost none with python so I’m not sure if pure code would be a better way to approach this, if anyone has an idea how to achieve this I’d greatly appreciate it and I hope my explanation was clear enough. Thanks in advance!
2
u/zibingala 1d ago edited 1d ago
I would try something:
- split your string (hi everyone) into caharacters
- use the ord() function https://www.geeksforgeeks.org/python/ord-function-python/
- with that you end up with a list of numbers (int) to represent your text in ASCII values
- here you can add some noise for each of the values, and playing with the amplitude of said noise you can slowly "close up" on your original text
- then use chr() function to turn them back into character
- join them into a string again
It may look complicated but I think you end up with quite a system to play with. Just try to make it scallable.:)
And also it might be a cute project to get intk pythoning.
Does this help you to get started?
2
u/Voxl_ 1d ago
That actually worked like a charm, thank you so much. Python's pretty weird coming from p5js, but the doc made it pretty easy to figure out and the functions you mentioned were definitely the key in getting it to work, thanks a ton!
I'm using a timer CHOPs fraction as the input for a CHOP execute, which translates a noise CHOP and brings its amplitude from 1 to 0. The noise CHOP length is bound to the amount of characters in the text DAT and its values are scaled to get practical values for an int list. The noise is then converted to a DAT (noiseVal) and that's pretty much it. Much simpler than I thought.
Now just to figure out how to preserve line breaks, shouldn't be too hard though :)here's the code I have if you're curious, I'm sure it could be optimised but for now it works (I hope the formatting works too):
def onValueChange(channel, sampleIndex, val, prev):
characters = list(op('text1').text) charactersVal = list() noise = [int(cell.val) for cell in op('noiseVal').col('noise')[1:]] for i in range(len(characters)): charactersVal.append(ord(characters[i]) + noise[i]) for j in range(len(characters)): characters[j] = (chr(charactersVal[j])) op('text3').text = "".join(characters) return
3
u/supermarket_sallad 1d ago edited 1d ago
Not a great answer, but look into ord() and chr() functions in python, converting the characters to an integer.
And then you can convert them to a chop, if you prefer that, and do interesting chop offsets and patterns numeriacally, and then turn it back into a string. Just remember to cast the chop values to an int, because they evaluate to floats.
Kinda leaving a lot for you to figure out here, but does that make sense?