16
$\begingroup$

How can i convert a text/font into a list of Points? For example,I have this letter h,

Graphics[Text[Style["h", FontFamily -> "Courier", 300]]]

enter image description here

I want to obtain all the list of points such that when i put it in

Graphics[{Point[{{},{},...}]}]

I get the letter "h" made from points.

$\endgroup$

4 Answers 4

19
$\begingroup$
Graphics[MeshPrimitives[
  BoundaryDiscretizeGraphics[
   Text[Style["h", FontFamily -> "Courier", 300]], _Text], 0]]

enter image description here

Point /@ RandomPoint[
   DiscretizeGraphics[
    Text[Style["h", FontFamily -> "Courier", 300]], _Text], 
   600] // Graphics

Or

text = Text[Style["h", FontFamily -> "Courier", 300]]; 
reg = 
 BoundaryDiscretizeGraphics[
  ImportString[ExportString[text, "PDF"], {"PDF", "PageGraphics"}, 
    "TextOutlines" -> True][[1, 1]]]
Point /@ RandomPoint[reg, 600] // Graphics

enter image description here

Edit

region = DiscretizeGraphics[
   Text[Style["h", FontFamily -> "Courier", 300]], _Text];
e1 = AngleVector[π/6];
e2 = AngleVector[π/2];
c = 2;
pts = Table[c*{x, y} . {e1, e2}, {x, -100, 100, 1}, {y, -100, 100, 1}];
(*Show[Graphics[Point/@pts],region]*)
Graphics[{AbsoluteThickness[1], 
  Blue, Point /@ Pick[pts, RegionMember[region][pts]]}]

use Pick according to How to speed up process with DeleteCases?

enter image description here

$\endgroup$
19
$\begingroup$

I would define the letter as a discretised 2D region and plot it with axes in order to get a rough idea about its area:

letterRegion = BoundaryDiscretizeGraphics[Text[Style["h", FontFamily -> "Courier",300]], _Text, MaxCellMeasure -> 0.1, Axes -> True]

letterArea

Then, I would create a grid of equidistant points (if this is what you want!)

points = Flatten[CoordinateBoundsArray[{{-100, 100}, {-100, 100}}], 1];

and select those points within the letter region:

letterPoints = Select[points, RegionMember[letterRegion]];
ListPlot[letterPoints, PlotStyle -> PointSize[0.005], Frame -> False, Axes -> False]

letterPoints

For better resolution you can produce more points (by decreasing the grid step, now it is 1). Also for complicated letters you can define a better discretised region by decreasing even more the MaxCellMeasure parameter.

$\endgroup$
13
$\begingroup$
graphics = Graphics[Text[Style["h", FontFamily -> "Courier", 300]]];
pts = PixelValuePositions[ColorNegate[Binarize[Image[graphics, ImageSize -> 100]]], 1];

{{144, 378}, {145, 378}, {146, 378}, {147, 378}, {148, 378}, {149,
378}, {150, 378}, ..., {333, 134}, {334, 134}, {335, 134}, {336, 134}}

you can plot these points:

Graphics[Point[pts]]

enter image description here

$\endgroup$
3
$\begingroup$
BoundaryDiscretizeGraphics[Text[Style["h", FontFamily -> "Courier", 300]], 
 _Text, 
 MeshCellStyle -> 
  {1 -> None, 
  2 -> PatternFilling[{"HalftoneGrid", 
         Directive[AbsolutePointSize @ 25, Red]}, ImageScaled[1/15]]}]

enter image description here

Replace "HalftoneGrid" with "Halftone" to get

enter image description here

Use PatternFilling[{"HalftoneGrid", Directive[AbsolutePointSize[15], Red]}, ImageScaled[1/30]] to get

enter image description here

Use PatternFilling[{"Halftone", Directive[AbsolutePointSize[30], Red]}, ImageScaled[1/50]] to get

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.