Fork me on GitHub
#clojure
<
2020-08-01
>
devn01:08:22

I’m in the midst of a hackathon type thing, and we’re building a “text-based” adventure game. As in, you text from your cell phone. The trouble is, message length is a bit of a problem, so I want to create images of the text to send vs MMS as opposed to SMS. I’ve messed with Graphics2D, but text layout is a bit of a bummer. I’m looking for something simple that will let me just dump a big string in, and not have to worry about x/y coordinates. I’m imagining something like raw HTML->Image.

phronmophobic01:08:07

not exactly sure what you're looking for, but https://github.com/phronmophobic/membrane might help. graphics2d should also be pretty straight forward if you're just trying to create images from text

phronmophobic01:08:16

for example:

(require '[membrane.skia :as skia])
(require '[membrane.ui :as ui])

(skia/draw-to-image!
 "myimage.png"
 (ui/label
  "X   X 
 XXXXX
XX
"
  (ui/font "Menlo.ttc" 12))
 )

phronmophobic01:08:07

this assumes mac osx, but I can provide an example for whichever platform you're targetting

devn02:08:54

Very helpful, thank you

devn02:08:36

What would be the main difference for Linux? I don’t see anything in your example that makes me think it’s specific to OSX?

phronmophobic02:08:21

Menlo.ttc is a mac os x monospaced font*

devn02:08:39

that’s kind of what I expected you’d say 🙂

devn02:08:55

this lib looks pretty cool

phronmophobic02:08:56

otherwise, it should work on linux

phronmophobic02:08:16

windows support is in progress

devn02:08:27

I’m a fan of lanterna and text-based UIs

🙂 6
phronmophobic02:08:51

i’m looking for feedback, so let me know if you have any suggestions or improvements

devn01:08:03

Does this exist (freely (I found a paid library/api to do it)), or do you have any other ideas?

Ody10:08:06

So a func defined within let can not refer to itself, one must use letfn?

herald11:08:15

It can! (fn name? [params*] exprs*) takes an optional name before the params.

👍 6
Chris O’Donnell14:08:27

letfn is necessary when you bind two functions which call each other. (With let, the first function couldn't call the second.)

Michael du Breuil23:08:15

I'm getting errors of "Inconsistent stackmap frames at branch target" which I'm guessing at this point is a compiler bug? I've created a minimal standalone example here (including the error I'm seeing and full edn report): https://gist.github.com/WickedShell/2acaaf5e40a15352123e2bad338e06ae changing line 49 of core.clj to just return a number instead of calling haversine-distance will fix the error

rutledgepaulv23:08:56

Not sure if it's the cause (not at a computer) but your return type tag is in the wrong spot, it should be before the symbol not before the arg vector: https://gist.github.com/WickedShell/2acaaf5e40a15352123e2bad338e06ae#file-core-clj-L29

Michael du Breuil23:08:47

Oh wow, absolutely correct, and resolves it. What's horrifying is I got that hint wrong 4 years ago, and everything else has been fine with it....

Michael du Breuil23:08:35

@U5RCSJ6BB Thanks! Feeling foolish at the moment 🙂

rutledgepaulv23:08:45

np! Probably is related to a clojure or java upgrade and some transitive behaviors in conjunction with a long standing bad tag

Michael du Breuil23:08:21

Wait, actually I'm not sure I'm wrong there. All my type hints are done that way, and that's actually how the docs say to do it... https://clojure.org/reference/java_interop#typehints

Michael du Breuil23:08:27

I do accept that it's a type hinting bug though

rutledgepaulv23:08:12

Wow, so they do. I certainly always have put them before the var symbol. I will need to look more closely

noisesmith01:08:11

based on that discussion, moving the ^double hint to the symbol means its no longer a proper primitive hint, which means the hint no longer does anything useful, but in this case it also prevents the code path that has the compiler bug

Alex Miller (Clojure team)03:08:19

agreed that the type hint was at the right spot originally

Alex Miller (Clojure team)03:08:43

can you post this to https://ask.clojure.org - that will get it into my queue to make it a bug

Michael du Breuil04:08:45

@U064X3EF3 I'll be out of town till Tuesday, but I'll post it there once I'm back, thanks!

Michael du Breuil16:08:00

@U064X3EF3 posted, thanks again for your time.