randomly capitalizing/spacing text

Inspired by this thread

I started messing with a definition to mess up text in a random way. It seems to be a little demanding, performance-wise. A slight delay after input. I don’t know that it is bad enough to truly bother someone, but it might. I’ll include the snippet here as a curiosity, but I thought it might be interesting for people to discuss how they might approach the problem.

Though I do have one question about the example: my approach truncates the text four words early. I’m assuming that’s a mistake I’ve made somewhere. (fixed it! was missing “punctuated” from my initial repeat phrase)

So how about it? What is the best way to randomly alter/format a text in Inform?

Code
lab is a room.

to say the randomly capitalized form of (t - a text):
	let the modified text be a text;
	let placeholder be a text;
	let next character be a text;
	let future be a text;
	let word count be the number of punctuated words in t;
	repeat with N running from 1 to word count:
		now placeholder is punctuated word number N in t;
		now future is punctuated word number (N + 1) in t;
		repeat with CN running from 1 to the number of characters in placeholder:
			now next character is character number CN in placeholder;
			if a random chance of 1 in three succeeds:
				now next character is the substituted form of next character in upper case;
			now the modified text is the substituted form of "[modified text][next character]";
		unless "[future]" is a punctuation mark or "[future]" is "":
			now the modified text is the substituted form of "[modified text][the random thing] ";
	say the modified text;
	
		 
portrait is a text that varies.
portrait is "The Vances lived in number seven. They had a different father and mother. They were Eileen’s father and mother. When they were grown up he was going to marry Eileen."

instead of jumping:
	say portrait;
	say paragraph break;
	say the randomly capitalized form of portrait;
	
to decide if (c - a text) is a punctuation mark:
	if "[c]" matches the regular expression "\p":
		decide yes;
		
to say the random thing:
	if a random chance of one in 5 succeeds:
		say "[one of][line break][or][paragraph break][purely at random]";
	if a random chance of one in 5 succeeds:
		say "[one of][line break][or][paragraph break][purely at random][fixed letter spacing]        [variable letter spacing]";
	if a random chance of one in 5 succeeds:
		say "[fixed letter spacing]     [variable letter spacing]";
	if a random chance of one in 5 succeeds:
		say "[fixed letter spacing]           [variable letter spacing]";
	otherwise:
		say " ";
		
test me with "jump"
Sample Output
>jump
The Vances lived in number seven. They had a different father and mother. They were Eileen's father and mother. When they were grown up he was going to marry Eileen.

The  Vances            Lived  in  number
  seven.
            ThEY                 Had

          a  diFfErent            fATher            and
               motHER.  TheY  were
          EIleEn'S  fatHer  And                 mOther.            WhEN

                    theY  Were  growN  up            he  waS
  goinG  

>
4 Likes

Iterating over characters in a text in I7 is always going to be very slow, because of all the machinery necessary to transmute and untransmute the arrays. But that can be worked around with a bit of I6, after which there shouldn’t be any noticeable delay.

4 Likes

That’s too bad about the Inform 6; I think it’s beyond my grasp :pensive_face:

I mocked up a simple bisquixe demo that changes color and font while jumping, and switches those characteristics back to a “default” when doing something else. The font is illegible, but gets the point across.

The gblorb, which runs in any interpreter, just randomizes the capitalization.

I share this as a curiosity that might interest anyone finding this in a search. I think it would be interesting to go further and add some animation, though out-of-the-box Bisquixe can’t format keyframe stuff. I’ve thought about tweaking this in the template, but since I publish my source code, I like to leave extensions and templates as-is.

weird text demo by Drew Cook

the password is “jump”

source
"The Trouble with Jumping"

lab is a room.

include simple multimedia effects for v10 by mathbrush.
include basic screen effects by emily short.

release along with a "bisquixe" interpreter


To decide if bisquixe is active:
	(-(glk_gestalt(5376, 0) )-)

to decide if bisquixe is inactive:
	unless bisquixe is active, decide yes.
	
	
to decide if (c - a text) is a punctuation mark:
	if "[c]" matches the regular expression "^\p$":
		decide yes;
		
keypress is a number that varies;
		
first when play begins:
	if bisquixe is active:
		follow the styling startup rule;
		follow the default rule;
		ask for device information;
		follow the initial page setup rule;
	otherwise:
		now keypress is 2;
	
to ask for device information:
	say paragraph break;
	say "This demo supports mobile and desktop screen configurations. Please choose:

1) I am using a mobile device.
[line break]2) I am using a full-sized screen.";
	while 5 is 5:
		let T be the chosen letter;
		now T is T minus 48;
		if T is greater than zero and T is less than 3:
			now keypress is T;
			say "You have chosen [if playmode is mobile]mobile[otherwise if playmode is full]full[end if].";
			make no decision;
			
to decide if playmode is mobile:
	if keypress is 1, decide yes;

to decide if playmode is full:
	if keypress is 2, decide yes;
	
to say the randomly capitalized form of (t - a text):
	let the modified text be a text;
	let placeholder be a text;
	let next character be a text;
	let future be a text;
	let word count be the number of punctuated words in t;
	repeat with N running from 1 to word count:
		now placeholder is punctuated word number N in t;
		now future is punctuated word number (N + 1) in t;
		repeat with CN running from 1 to the number of characters in placeholder:
			now next character is character number CN in placeholder;
			if a random chance of 1 in four succeeds:
				now next character is the substituted form of next character in upper case;
			now the modified text is the substituted form of "[modified text][next character]";
		unless "[future]" is a punctuation mark or "[future]" is "":
			now the modified text is the substituted form of "[modified text][the random thing]";
	say chaos;
	say the modified text;
	say line break;

	
portrait is a text that varies.
portrait is "The Vances lived in number seven. They had a different father and mother. They were Eileen’s father and mother. When they were grown up he was going to marry Eileen. He hid under the table. His mother said:[unicode 8233]—O, Stephen will apologise."


instead of jumping:
	say portrait;
	say paragraph break;
	css-set-fast ".Input; background; transparent";
	css-set-fast ".BufferWindow .Input; color; #0A0A0A";
	css-set-fast ".Input; color; #0A0A0A";
	css-set-fast ".Style_input; color; #0A0A0A";
	css-set-fast ".BufferWindow; background; #F2A005";
	css-set-fast ".BufferWindow; color; #0A0A0A";
	say the randomly capitalized form of portrait;

		
to say the random thing:
	if a random chance of one in 7 succeeds:
		say "[one of][line break][or][paragraph break][purely at random]";
	if a random chance of one in 7 succeeds:
		say "[one of][line break][or][paragraph break][purely at random][ms]        [variable letter spacing]";
	if a random chance of one in 5 succeeds:
		say "[ms]     [variable letter spacing]";
	if a random chance of one in 5 succeeds:
		say "[ms]           [variable letter spacing]";
	otherwise:
		say " ";
		


test me with "jump"

first when play begins:
	css-set-fast ".Style_console; font-family; Roboto Mono, monospace";
	css-set-fast ".Style_console; font-size; 16px";
	css-set-fast ".Style_large; font-size; 20px";
	css-set-fast ".Style_chaos; font-family; Rubik Glitch, monospace";
	css-set-fast ".Style_chaos; font-weight; lighter";
	css-set-fast ".Style_chaos; font-size; 18px";
	css-set-fast ".Style_chaos; color; #0A0A0A";


	
this is the initial page setup rule:
	css-set-fast ".BufferLine; white-space; pre-wrap";
	if playmode is full:
		css-set-fast "#gameport; left; 22%";
		css-set-fast "#gameport; right; 22%";
		css-set-fast "#gameport; top; 0%";
		css-set-fast "#gameport; bottom; 0%";
	otherwise if playmode is mobile:
		css-set-fast "#gameport; left; 0%";
		css-set-fast "#gameport; right; 0%";
		css-set-fast "#gameport; top; 0%";
		css-set-fast "#gameport; bottom; 0%";


	
this is the styling startup rule:
	import-google-fonts "Open+Sans&family=Rubik+Glitch&family=Bitcount+Ink";
	css-set-fast ".BufferWindow;padding;0px 15px 0px 15px";	
	css-set-fast ".GridWindow;padding5px 15px 5px 15px";
	css-set-fast ".play; background; #00030a";
	css-set-fast ".links; display; none";
	css-set-fast ".interpretercredit; display; none";
	css-set-fast ".coverimage; display; none";

this is the default rule:
	css-set-fast ".BufferWindow .Input; font-size; 16px";
	css-set-fast ".Input; background; transparent";
	css-set-fast ".BufferWindow .Input; color; #210303";
	css-set-fast ".Input; color; #210303";
	css-set-fast ".Style_input; color; #210303";
	css-set-fast ".BufferWindow; background; #F7F2F2";
	css-set-fast ".BufferWindow; color; #210303";	
	css-set-fast ".BufferWindow; font-size; 16px";
	css-set-fast ".BufferWindow; font-family; sans-serif";
	
before doing something other than jumping:
	follow the default rule;
	
to say ms:
	if bisquixe is active:
		set-any-class "console";
	otherwise:
		say fixed letter spacing;

to say chaos:
	set-any-class "chaos";

E: no phone version, sorry! I might add it later
E2: Updated to include a mobile mode!

Building this with 10.1, I see all the words:

The  VANCES
          lIVEd            IN       number  seveN.       They  hAd  a  DiFFErEnt  Father  and  moTHer.            TheY  weRe       EilEen'S  father
               ANd
                    moTHer.  WhEn

                    they       weRe  gRoWn       up  hE            WAs       gOINg  to  mArrY  EIlEEn.

Here’s a not hopelessly inefficient way to repeat through words (it requires textWipe from a previous comment):

and through characters…

…but they’d require considerable tweaking to deal with punctuation like yours does.

2 Likes

Thanks for this! It’s amazing how different inform 6 is. It’s like going from modern English to old English (I’m sure experienced programmers have no such difficulties)

e: as a final note, I added a mobile version to the demo (only available in web play)