Fill a circle with text

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Fill a circle with text

Post by pgimeno »

Bigfoot71 wrote: Mon Jan 09, 2023 11:19 pm Wow, super cool! I wanted to understand your approach to the problem, so I restructured it a bit by commenting on the passages, I also took the liberty of putting the declaration of `words` in the `while` loop because even if a redefinition in a loop is slower than predefining it upstream it seems to me that it is preferable to do so since another loop takes care of "emptying" it afterwards, or maybe I did not understand a subtlety.
Thanks for adding comments.

The while loop is usually faster than allocating the table and clearing the garbage afterwards; also garbage collection is often responsible for CPU spikes that sometimes produce micro-stutters. There's a lot of garbage being generated in other sections, but that was one thing I could do something about. Ideally the table should be out of the function but that would have looked too extreme.

There's a minor issue in one of the comments; 'If the alignment is not "justify", use the default alignment' should not say default alignment, but specified alignment. Also, the math.min() line lacks a comment that says that it calculates the minimum between the width at the top and the width at the bottom of the line, which is the width to use. If the width of the circle at the bottom of the line is smaller, it means we're close to the bottom of the circle.

On a side note, after thinking about it, I could not have done much to use the built-in justify even if it worked well in this version. My initial plan was to include two lines and use scissor to cut out the second line, but that would have required a canvas rather than a text object. Probably slower, and almost surely more resource-intensive. I've requested a feature that would have helped.

And note that this version does not handle newline characters (\n) in the string, and doesn't let you choose a different line spacing, which would be cool.
RNavega
Party member
Posts: 355
Joined: Sun Aug 16, 2020 1:28 pm

Re: Fill a circle with text

Post by RNavega »

9912 wrote: Tue Jan 10, 2023 5:24 pm to display the text like a visual novel on round display.
If you're gonna use it with large texts that overflow the circle, you'll have to modify pgimeno's pretty cool function to also return the index of the string where it you can continue from, for pagination (splitting the huge text over several pages).

So in your last image, you know the text ended in "malesuad", you'll return the index of the next word after that, so for the next circle text you can supply myText:sub(nextWordStart) to show the rest of the text, doing that until the return index is nil or whatever (so after a few circles, all of the huge text was shown).
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Re: Fill a circle with text

Post by Bigfoot71 »

pgimeno wrote: Tue Jan 10, 2023 6:47 pm Thanks for adding comments.

The while loop is usually faster than allocating the table and clearing the garbage afterwards; also garbage collection is often responsible for CPU spikes that sometimes produce micro-stutters. There's a lot of garbage being generated in other sections, but that was one thing I could do something about. Ideally the table should be out of the function but that would have looked too extreme.

There's a minor issue in one of the comments; 'If the alignment is not "justify", use the default alignment' should not say default alignment, but specified alignment. Also, the math.min() line lacks a comment that says that it calculates the minimum between the width at the top and the width at the bottom of the line, which is the width to use. If the width of the circle at the bottom of the line is smaller, it means we're close to the bottom of the circle.

On a side note, after thinking about it, I could not have done much to use the built-in justify even if it worked well in this version. My initial plan was to include two lines and use scissor to cut out the second line, but that would have required a canvas rather than a text object. Probably slower, and almost surely more resource-intensive. I've requested a feature that would have helped.

And note that this version does not handle newline characters (\n) in the string, and doesn't let you choose a different line spacing, which would be cool.
Thank you for these details, it's very useful to know, so I corrected the comments and put back the totally original code. I also made some attempts about what you advised on word wrap wanting to add an option for line spacing as well, I got there but there are still some issues at the moment , I will share it here of course when I have succeeded.
My avatar code for the curious :D V1, V2, V3.
9912
Prole
Posts: 11
Joined: Sun Aug 23, 2020 7:12 am

[Solved] Fill a circle with text

Post by 9912 »

Thank you all for the help, now for future use is better to have this code as a library for future use
Attachments
roundtext.lua
roundtext function packaged into a lua file, credits at the beginning
(2.93 KiB) Downloaded 45 times
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests