1

Greeting, wise ones!

I am trying to make a generator for pictures like this one. My idea is to make 2 patterns (vertical lines and horizontal lines). After that, I need to make vertical lines only appear "within" the letter but go a bit beyound if they don't intersect a horizontal line. Same for horizontal line, just for being "outside" the letter.

To perform this I need to know, which pixels are "within" letters of the text() object and which are not. This is the only thing, that I can't get my head around. Any ideas on how to implement this?

(If you have a simpler idea of how to make this generator, I'll happily read about them as well, I'm not too sure that mine is the best)

MeloMan
  • 31
  • 6
  • How would you approach the problem if you had a simple polygon, like a square? Boil the issue down to the simplest test case and proceed from there. You don't need to have your hand held. – MarsAtomic Jan 04 '22 at 16:43
  • Something like a rectangle/triangle/circle is pretty easy, but I couldn't think of any solution that works for any set of letters, especially tilted ones. I would be really glad if you held my hand a bit here. – MeloMan Jan 04 '22 at 17:03
  • A complex shape is a series of simple shapes. If you can solve for the simple shape, then you can solve for the complex shape. This is engineering: decompose the problem into a set of smaller, more readily solved problems, and you have your solution. Your issue isn't so much a technical issue as a matter of following the proper engineering mindset. If you don't maintain faith in your abilities, why would anyone else? – MarsAtomic Jan 05 '22 at 00:15
  • If you use a monospace font, you'll have a waaay easier time coding this than if you use a proportional font. [Monospace vs proportional](https://en.wikipedia.org/wiki/Monospaced_font). – laancelot Jan 06 '22 at 16:32
  • I think i have a solution, but I would need to know what font you are using first. – person the human Jan 06 '22 at 17:35
  • Ideally, I'd want to be able to choose the font. But for now, I use [Raleway](https://fonts.google.com/specimen/Raleway) – MeloMan Jan 06 '22 at 21:14

1 Answers1

1

TL;DR: solution

So, initially, I was doing it in Java Processing and was thinking in terms of points and "if" conditions. I couldn't get any meaningful help and abandoned the problem, doing the thing by hand.

However, later I encountered a problem with detecting if a point is within a polygon in Unity and found a solution that includes the concept of raycasting. It's easily implemented in Unity but will require some extra work in something like Java Processing. In any case, this is an excellent answer to my question. I hope it helps anyone who encounters a similar problem.

MeloMan
  • 31
  • 6
  • 1
    In order for this answer to be useful for others, please include all the relevant code in the answer body. Links tend to break, which would render the answer useless. – Eran Dec 15 '22 at 18:40
  • One route could be font paths (e.g. [PFont -> `getShape()` -> PShape](https://stackoverflow.com/questions/52818958/createfont-from-string/52820994#52820994) which hopefully is a `PATH` type so you can use `contains(x, y)` or using the [Geomerative library](http://www.ricardmarxer.com/geomerative/) which has utilities to get font points / paths (and check if a path contains a given point). – George Profenza Dec 16 '22 at 02:06
  • Another alternative is using a pixel collision test: 1. render your text in a `PGraphics` buffer/layer (e.g. white text, black background, no strokes), 2. test if the pixel at a given location is white (foreground / text) or not. – George Profenza Dec 16 '22 at 02:07