Recently a bunch of collaborations announced on the forum have petered out without a result, as people have lost interest. So, to encourage collaborators, I want to talk about a spontaneous and successful collaboration, even though nobody called it that.
This collaboration took place in the thread Set Font, Bold and Italic for Pen Writing Block.
It started when @348663451y posted a block of Javascript code to change the font and style used in the WRITE block and asked for this to be added as a primitive in the coming version 7.0. (Before you ask, yes, it's behind schedule, and no, I don't know when it'll officially be released.)
I replied that nothing that isn't already planned will be added to 7.0, but that meanwhile, you can make boldface without Javascript by displaying the text twice, with one of them one pixel up and one pixel to the right of the other. (I learned this technique from The TeXBook, Don Knuth's manual for his TeX typesetting language.)
348663451y then proposed to simulate italics similarly, by turning the sprite clockwise a little before printing each character, like this:
That's pretty good, for an easy, quick solution, but it's not really satisfying because the baseline is wiggly instead of straight as it would be in true italics:
Meanwhile, in an unrelated thread, @warped_wart_wars had asked about matrix multiplication. This led me to suggest that a font character could be italicized by applying a linear transformation to its bitmap, multiplying by a transformation matrix such as
so that each point's new x coordinate would become
warped_wart_wars went to work on that.
Meanwhile, @joecooldoo had a different idea: The author of a project could enable JavaScript, run a block that would load a selected font into a list, and then save the project with that list in it. A version of the WRITE block, not using JavaScript, would then be able to use that font. The user of such a project would not have to enable JavaScript to benefit from the saved font.
warped_wart_wars asked for help extracting the pixels from a font-character costume, in black and white (one bit per pixel), so I wrote an expression to do that:
warped_wart_wars, with that start, got the matrix multiplication to work as desired, given a list of the x,y coordinates that have ink on them.
Then @dardoro embedded that matrix code into a project that converts a costume to and from the list of coordinates. But he also pointed out that it's a lot faster just to shift each row of pixels a little further to the right than the one below it, without bothering with matrices.
Meanwhile joecooldoo posted a project carrying out his plan, but it used a fixed spacing between characters. That's fine for a monospace font such as Courier, but not for variable-width fonts such as Arial or (my favorite) Baskerville. So I tried to determine the width of each character. I used the costume's bounding box ( etc.), but had a very persistent bug that made the spacing seem almost random.
Eventually I discovered that the costumes representing the font had their rotation centers at the right edge:
so by stamping the costume and then moving to the right I was effectively using this character's spacing to determine the next character's width.
Once I moved the CHANGE X BY block above the STAMP block, it worked almost perfectly:
The remaining problem, especially in Italic fonts, is that some characters have very flamboyant descenders that are meant to overlap with the next or previous character:
I think the solution to this is to make a subset of the costume with only the pixels above the baseline, and use that to determine the width. But I haven't actually implemented that (so far...).
So, two different solutions, one that makes an Italic font by a linear transformation of the characters of the Roman font, and one that allows any font to be stored in a project and used in the (rewritten, but without JavaScript) WRITE block.
Five people contributed to these solutions, without having to say "let's have a collaboration to do X."
(This isn't to say that intentional collaborations are bad! They can be very successful, too. I'm just suggesting that more collaborating happens than is captured by those "official" collaborations.)
Discuss this in the forum