papermario/tools/splat/util/iter.py
Ethan Roseman 179998098c
Misc decomp 53 (#703)
* some btl_state work

* msg_draw_speech_bubble

* cleaners

* btl_state_stuff

* btl_state_update_next_enemy wip

* btl_state stuff

* disable_x fx + cleanup

* wip

* fxstuff

* path funcs & cleanup

* clean

* model_api funcs

* two action commands

* action_cmd progress

* UnkFunc001

* air raid func

* cleanup, data migration, goodies

* remove data file

* git subrepo pull --force tools/splat

subrepo:
  subdir:   "tools/splat"
  merged:   "a847090eac"
upstream:
  origin:   "https://github.com/ethteck/splat.git"
  branch:   "master"
  commit:   "a847090eac"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "2f68596"

* fix build

* more cleanup

* clean

* PR comments
2022-05-05 23:08:16 +09:00

30 lines
734 B
Python

from itertools import zip_longest
from math import ceil
def iter_in_groups(iterable, n, fillvalue=None):
args = [iter(iterable)] * n
return zip_longest(*args, fillvalue=fillvalue)
def iter_image_indexes(
width, height, bytes_per_x=1, bytes_per_y=1, flip_h=False, flip_v=False
):
w = int(width * bytes_per_x)
h = int(height * bytes_per_y)
xrange = (
range(w - ceil(bytes_per_x), -1, -ceil(bytes_per_x))
if flip_h
else range(0, w, ceil(bytes_per_x))
)
yrange = (
range(h - ceil(bytes_per_y), -1, -ceil(bytes_per_y))
if flip_v
else range(0, h, ceil(bytes_per_y))
)
for y in yrange:
for x in xrange:
yield x, y, (y * w) + x