Created
September 9, 2024 08:59
-
-
Save em-deltaxp/377edfbbca55c008abeafe819eb1c0df to your computer and use it in GitHub Desktop.
Revisions
-
em-deltaxp created this gist
Sep 9, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ #!/usr/bin/env python3 # tmp-75QDpmeAU5.py -- [Pythonista v3.4 (iOS)] import sys import ui SIDE_LENGTH=10 STEP_COUNT=4 COLOR_COMPONENT_LIMIT=256 def gen_colors(start: int, end: int, step: int) -> list[str]: def _r() -> range: #print(f'{start} {end} {step}') return range(start, end, step) rgb=[(r,g,b) for r in _r() for g in _r() for b in _r()] rgb24=map(lambda x: (x[0]<<16)+(x[1]<<8)+x[2], rgb) rgb24s=list(map(lambda x: str.format('#{0:06x}',x),rgb24)) return rgb24s def make_img_colors(length: int, count: int, colors: list[str]) -> ui.Image: t=length*count*count with ui.ImageContext(t,t) as ctx: s='' for i in range(0,len(colors),1): ui.set_color(colors[i]) ui.fill_rect((i*length)%t,((i*length)//t)*length*count,length,length*count) eol="\n" if (i+1)%(count*count)==0 else "" s=f'{s} {colors[i]}{eol}' img=ctx.get_image() print(f"\n\n{s[:-1]}") return img def make_img_colors_lower(length: int, count: int) -> ui.Image: colors=gen_colors(0,COLOR_COMPONENT_LIMIT,COLOR_COMPONENT_LIMIT//count) return make_img_colors(length,count,colors) def make_img_colors_upper(length: int, count: int) -> ui.Image: colors=gen_colors(COLOR_COMPONENT_LIMIT-1,-1,(COLOR_COMPONENT_LIMIT//count)*-1) return make_img_colors(length,count,colors) def main(args: list[str]) -> int: img_lower=make_img_colors_lower(SIDE_LENGTH,STEP_COUNT) img_lower.show() img_upper=make_img_colors_upper(SIDE_LENGTH,STEP_COUNT) img_upper.show() return 0 if __name__ == "__main__": r = main(sys.argv) sys.exit(r)