# Need help with this script

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.

[scratchblocks]
(height) / (stripes)
[/scratchblocks]

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.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.5894367098808289, "perplexity": 463.1760956841071}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2023-06/segments/1674764499646.23/warc/CC-MAIN-20230128153513-20230128183513-00196.warc.gz"}