Hi all,
I want to create a child-like, multi-coloured font that's used on inputted text. It's only shown once, so normally I'd use something like "{color=#f00}Red{/color}, {color=#00ff00}Green{/color}, {color=#0000ffff}Blue{/color}" on each letter, but because this is inputted text (up to 46 characters) I don't know how to do it. Perhaps it's not possible in this situation?
[SOLVED] Rainbow font for text input
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
- Kinmoku
- Miko-Class Veteran
- Posts: 591
- Joined: Mon Aug 11, 2014 9:39 am
- Completed: One Night Stand
- Projects: VIDEOVERSE
- Tumblr: gamesbykinmoku
- itch: kinmoku
- Location: Germany
- Contact:
[SOLVED] Rainbow font for text input
Last edited by Kinmoku on Fri Jul 20, 2018 6:47 am, edited 1 time in total.
Re: Rainbow font for text input
You could write a python function that would process the input string, inserting the various color definitions into it.
Or you could do something similar with a custom text tag: https://www.renpy.org/doc/html/custom_text_tags.html
Or you could do something similar with a custom text tag: https://www.renpy.org/doc/html/custom_text_tags.html
- Kinmoku
- Miko-Class Veteran
- Posts: 591
- Joined: Mon Aug 11, 2014 9:39 am
- Completed: One Night Stand
- Projects: VIDEOVERSE
- Tumblr: gamesbykinmoku
- itch: kinmoku
- Location: Germany
- Contact:
Re: Rainbow font for text input
I think this is too advanced for me ^^; I don't know where to start.
Re: Rainbow font for text input
Apologies - I was AFK when I wrote my reply. Here's some sample code.
The idea is that there's a Python function named "colorize" that will take an input string
and return an output string where each of the letters in the input string is surrounded
by a {color} tag. The colors to be used are taken from the COLORIZE_COLORS array -
they're used in sequence, wrapping around to the beginning of the list if the input
string is longer than the array. You can obviously alter the list of colors as you
see fit.
Hope this is useful.
The idea is that there's a Python function named "colorize" that will take an input string
and return an output string where each of the letters in the input string is surrounded
by a {color} tag. The colors to be used are taken from the COLORIZE_COLORS array -
they're used in sequence, wrapping around to the beginning of the list if the input
string is longer than the array. You can obviously alter the list of colors as you
see fit.
Code: Select all
init python:
# A list of colors that the "colorize" function will use in sequence
COLORIZE_COLORS = [
'{color=#f00}',
'{color=#0f0}',
'{color=#00f}',
'{color=#ff0}',
'{color=#f0f}',
'{color=#0ff}',
]
# A Python function that will turn 'abc' into
# '{color}a{/color}{color}b{/color}{color}c{/color}'
# using the sequence of colors in COLORIZE_COLORS
def colorize(input):
# index into the COLORIZE_COLORS
i = 0
# array of strings that we'll build up
result = []
# iterate through each letter in the input string
for letter in input:
# Insert a {color} tag surrounding the letter
result.append(COLORIZE_COLORS[i])
result.append(letter)
result.append('{/color}')
# move to the next color, wrapping around when we get off the end of the list
i = (i + 1) % len(COLORIZE_COLORS)
# Now join together all the items in the array and return the resulting string
return ''.join(result)
image background = "#888"
label start:
scene background
label loop:
$ name = renpy.input('What is your name')
$ colorized_name = colorize(name)
"Your colorized name is [colorized_name]"
jump loop
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: [SOLVED] Rainbow font for text input
The code rames44 provided works...but it isn't a custom text tag as described in the documentation: https://www.renpy.org/doc/html/custom_text_tags.html
Because it isn't a custom text tag...you can't actually use it like a text tag.
So this code makes a custom text tag that you can actually use like a text tag:
Because it isn't a custom text tag...you can't actually use it like a text tag.
So this code makes a custom text tag that you can actually use like a text tag:
Code: Select all
define COLORIZE_COLORS = [
'#ff0000',
'#ff8000',
'#ffff00',
'#00ff00',
'#0000ff',
'#8000ff',
'#ff00ff'
]
init python:
#Custom Text Tag
def rainbow_tag(tag, argument, contents):
rv = []
for kind, text in contents:
if kind == renpy.TEXT_TEXT:
for i in range(0, len(text)):
rv.append((renpy.TEXT_TAG, "color={}".format(COLORIZE_COLORS[i%(len(COLORIZE_COLORS))])))
rv.append((kind, text[i]))
rv.append((renpy.TEXT_TAG, "/color={}"))
else:
rv.append((kind, text))
return rv
config.custom_text_tags["rainbow"] = rainbow_tag
label start():
#http://www.renpy.org/doc/html/custom_text_tags.html#custom-text-tags
"Creating a custom text tag is a something doable!"
"I've made a rainbow text tag, let's check it out."
"{rainbow}Here I am turning all the text rainbow.{/rainbow}"
"Maybe I only want to turn one word {rainbow}rainbow{/rainbow}."
"And of course, you can nest text tags."
"{rainbow}For example, all this text is rainbow. And this word is {size=40}big{/size}{/rainbow}."
"Okay, that's it."
return
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
Who is online
Users browsing this forum: No registered users