Intro (semi fictional)
I'm the solo developer of a game, I'm already struggling with character design as is. Hence I've thought of a smart solution, I'll just use images for regular monsters, outline them a bit and suddenly they are boss monsters! That will save me from thinking up new bosses yay.
However, I have approximately 100 monster designs already and I wouldn't like duplicating them all and manually drawing an outline to the images...
Given a file name (of a PNG file) as input, you should write a program/function which will draw an outline around every non-transparent pixel. The program/function should save the output file to a new file called
What does outlining mean
Outlining is the process of adding non-transparent pixels in the place of transparent pixels, around pixels which were non-transparent already. Any transparent pixel has an opacity of exactly 0%, anything else is defined as non-transparent. Any pixel which will be outlined will have an opacity of 100%, aka the alpha channel of that pixel will be 255.
Your program/function should take 3 variables as input. Feel free to provide these as function parameters, read them from stdin or any other method which suits you best.
The first variable is the file name, which is always a PNG file.
The second variable is the outline colour, which is a round integer, you can also take the colour from 3 separate
r,g,b byte values.
The third variable is the outline width, also an integer.
The width of the outline equals the maximum distance any transparent pixel should have to a non-transparent pixel in order to be outlined. The distance is calculated using the Manhattan distance between two points.
If the input image has only 1 non-transparent pixel, at
[0,0] and the outline width is 2, then the following pixels will be coloured:
[0,1] [0,-1] [1,0] [-1,0] [1,1] [-1,-1] [1,-1] [-1,1] [2,0] [-2,0] [0,2] [0,-2], for these have a manhattan distance of 2 or less from the coloured pixel
The following test cases are scaled up 7 times for visibility, so every block of 7 pixels should be treated as a single pixel
These are the input images used for the test cases:
These are the actual test cases:
input1.png, 0xFF0000, 0
input1.png, 0xFF0000, 1
input1.png, 0xFF0000, 2
input1.png, 0xFF0000, 3
input1.png, 0xFF0000, 10
input2.png, 0xFF0000, 2
input3.png, 0x000000, 2
Click here for the full Imgur album.