y'know there must be code for this somewhere already. but this makes a quick analog image. commit 7e23db09ca066d41c7e1227d5444c2d5f3482151 (HEAD -> main, origin/main, origin/HEAD) Author: xloem <[1]0xloem@gmail.com> Date: Sun Mar 27 23:13:15 2022 -0400 implement quickly diff --git a/gen_encoder_wheel/__main__.py b/gen_encoder_wheel/__main__.py index f1bd4f6..608eb43 100644 --- a/gen_encoder_wheel/__main__.py +++ b/gen_encoder_wheel/__main__.py @@ -3,6 +3,12 @@ from imageio import v3 as iio import numpy as np import click +# i used to have an idea for very precise position detection. +# i do not remember what that idea was. + +def angle2intensity(distance, angle): + return angle / np.pi / 2 + @click.command() @click.option('--size', default=4096, help='Height of wheel.') @click.option('--ratio', default=1.0, help='Aspect ratio of wheel. width = ratio * size') @@ -10,8 +16,13 @@ import click @click.option('--output', help='Output filename.') def generate(size, ratio, dpi, output): height = size * dpi - width = height * ratio - img = np.random.randint(0,0xffff,size=(int(width+.5),height,3),dtype=np.uint1 6) + fwidth = height * ratio + width = int(fwidth+.5) + x = np.tile(np.arange(width) / (fwidth - 1) * 2 - 1, (height, 1)) + y = np.tile((np.arange(height) / (height - 1) * 2 - 1)[:, None], width) + dists = np.sqrt(x * x + y * y) + angs = np.arctan2(x, y) + img = (angle2intensity(dists, angs) * 0xffff + np.random.random((width, height))).astype(np.uint16) return write(output, img) def write(fn, ndimg): References 1. mailto:0xloem@gmail.com