I am working on a project that allows you to easily make flag pixel art. This is done by inputting the axis: horizontal (Netherlands, Germany) and vertical (France, Italy), the amount of stripes your flag has and the top and bottom pixel values. It will calculate how wide each stripe should be. However, it uses a massive script which is extremely difficult to add support for new stripe amounts. As of now, the max you can do is 6. I need help with a more efficient script that can easily calculate with any stripe amount automatically. I have no idea how to do this though. Here's the current one:
If you take the height of the flag, divide that by the number of stripes, you get the height of each stripe.
(height) / (stripes)
to get stripes horizontally, you do the same, but with width
instead of height
.
It's for pixel art, which means if length/height divided by amount of stripes is a decimal, we have to round some of the stripe numbers down and the rest up then put the rounded up ones at the end, hence why I have this insanely long script. If I could find a way to do the same with a shorter script, I could do it with any amount of stripes, rather than have it limited.
I gather that the trouble is knowing which stripes to round up and which down? I would just use the ROUND block and let it worry about up versus down, then for the last stripe you can add up all the ups and downs to find out how much of a correction is needed.
What do you mean by this? Can you try updating my script with this?
If it's pixel art, then it will always have a set max amount of stripes each way anyway.
Well, you would just use the ROUND block, wouldn't you, except that the sum of the rounded numbers might not be the rounded sum of the exact numbers? So if you add up the differences between each value and its rounded value, you'll know how much you have to correct the last stripe to fill up the space exactly.
Then you just replace the last item with its value minus SUM OF DIFFERENCES. I think that's what you mean, isn't it?
I'm confused, could you try inserting this into my current script?
Hmm I don't want to do your homework for you...
i mean im extremely confused so can you at least explain in a way I can understand?
I'll try, but it'd be easier if you had a more specific question.
Reading your mind, I think you are worried that if you let ROUND decide whether to round up or down, sometimes it'll turn out that it always rounds down, or always rounds up, and so the total image is too small or too big respectively. Am I right about that?
So what I suggested is that you let ROUND do the rounding, but keep track of the accumulated error due to rounding and then fix it in the last stripe.
Although now that I think harder about it, you could do the correction incrementally: When the accumulated error becomes more than one pixel, adjust the next stripe by a pixel to compensate.
If you use a variable to accumulate the rounding errors, then you don't have to have specific rounded values for each situation built into your code.
If that doesn't make sense to you, please try to point me at whatever I said that you don't understand.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.