Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Creating X BitMap (XBM) images with directional gradientsby kcott (Archbishop) |
on Apr 02, 2021 at 08:34 UTC ( [id://11130713]=CUFP: print w/replies, xml ) | Need Help?? |
G'day All, I'm continuing my project to create interactive maps for RPGs with Tk generally and, for the main part, Tk::Canvas. I wrote a bit about that in "Tk::Canvas createGroup() Undocumented"; this CUFP post has nothing to do with the issue in that SoPW post; there is some backgound information and (very early, now substantially matured) code which may be of interest. The test code there to create creeks is related to the current work creating paths. I had created the basic paths, put nicely curved bends in them, and so on. All of this looked good except for where the paths terminated upon entering a glade, meadow, or whatever: all I had at the ends was solid lines; what I wanted was for these to gradually peter out. The sections for this needed to be solid (opaque) where the main path ended and gradually fade to nothingness (transparent) as the terrain moved away from the path. In addition, this gradient needed to have direction to match the direction of the path where it terminated. I made one futile attempt to do this manually in Gimp: the result looked horrible. I decided to let Perl do it for me. Here's the result which I knocked up this afternoon.
This produced the result I wanted. It allows multiple random instances so all the path endings don't look the same. I wouldn't claim this to be production-grade code; however, it does the required task without any sort of problems. This was only intended to be a quickly developed tool for a specific task; it does the job and does it quickly — I probably won't be spending any time making improvements but acknowledge that improvements could be made. When I was doing some research into this, before I started coding, I did note that the hex elements (0xhh) seemed to be in groups of twelve. I was unable to find any reason for this, so I didn't implement it — I'm certainly not going to try to discern bit patterns from such a large collection of hex values; although, there is a preponderance of 0xff values on the opaque side, and 0x00 on the transparent side. Here's an example of output. It is a 32x32 square. The orientation is 'w' (west): opaque on the right; transparent on the left.
— Ken
Back to
Cool Uses for Perl
|
|