2021-03-10

Making Faces in nanDECK

The other day I was working on a game in Screentop, and decided that I wanted the dice I had in it to be spotty dice rather than the digit dice that are the default. All this requires is uploading an image which shows the required faces (this works for any custom faces). If my image has a transparent background, then you can set the fill colour for the die to be whatever you want and then use the same image for a range of different coloured dice.

I figured that nanDECK would be an effective way of constructing the image, and it didn't take long to make the script. I thought I would share my script here as a kinda worked example. I'll break the sections of the script down with discussion about what each section does.

So, here goes...

BORDER=RECTANGLE,#000000,0,MARKDOT
PAGE=21,29.7,PORTRAIT,HV

These lines are just boilerplate stuff that I put at the top of all my scripts, formatting a page for printing or creating a PDF at A4 size, with crop lines added. It's not necessary for what I am doing here, but I left them in anyway.

DPI=200
CARDSIZE=5,5

The next bit of the boilerplate, but a bit that I modify as necessary. My usual card size is 6.3 x 8.9 cm for poker-sized cards, but I want squares this time. As I am just making an image, the size doesn't really matter, so 5 cm square was just a convenient number.

[DotColour]=#000000
[CircleColour]=#999999
[TransparencyColour]=#ffbbff

It can be useful to define variables rather than using numbers in the guts of the code. Specifically the [DotColour] one meant that I could run the script once to generate an image with black dots, and then change the value (to #ffffff) in order to run again and output white dots.

The [TransparencyColour] is helpful because in nanDECK you can define a specific colour to be replaced by transparency in an output PNG file. As long as you select a colour you don't want to use in the actual image (I'm using a pink here), all is good.

RECTANGLE=,0,0,100%,100%,[TransparencyColour],[TransparencyColour]

So this is just filling the "card" with a solid background field of the colour I selected for the transparency.

ELLIPSE="1,3,5",2,2,1,1,[CircleColour],[DotColour],0.02
ELLIPSE="4,5,6",0.5,0.5,1,1,[CircleColour],[DotColour],0.02
ELLIPSE="4,5,6",3.5,3.5,1,1,[CircleColour],[DotColour],0.02
ELLIPSE="2,3,4,5,6",3.5,0.5,1,1,[CircleColour],[DotColour],0.02
ELLIPSE="2,3,4,5,6",0.5,3.5,1,1,[CircleColour],[DotColour],0.02
ELLIPSE="6",0.5,2,1,1,[CircleColour],[DotColour],0.02
ELLIPSE="6",3.5,2,1,1,[CircleColour],[DotColour],0.02

That's the guts of it. You can look at a standard spotted die face as having seven locations where spots can exist, and each spot is present on some faces, so this sort of arrangement does the job.

It's worth noting that this is just outputting images for faces, without any thought about where on the die those faces are placed. For instance, the standard die arrangement of opposite faces adding up to seven is not covered here, but at present, Screentop appears to simply treat a die as a randomiser, with no physical analogue, so this point is irrelevant for my current use case.

DISPLAY="dottydice.png",1,6,3,,[TransparencyColour]

And that last line outputs the six faces to a single PNG image, three "cards" wide, converting the colour we specified earlier to transparency.

And here's the output:

Black on transparency. Feel free to take and use if it is of any use to you. CC0 v1.0

And, as an alternative, re-running the script with the white version of [CircleColour] gives:

White on transparency. Feel free to take and use if it is of any use to you. CC0 v1.0

I don't know if this sort of thing is helpful or interesting, but here it is anyway. 


No comments:

Post a Comment