summaryrefslogtreecommitdiff
path: root/src/modules/shapes
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-05-24 22:28:23 -0700
committerVito Caputo <vcaputo@pengaru.com>2022-05-24 22:34:50 -0700
commit60353ac9dde8ec3178ef926afc9889551e77cc62 (patch)
tree809647faec1ed53214b10f618d0be5f9934e76bf /src/modules/shapes
parenta2331d64f27ef3a5467128c03bd15dd486ed12b0 (diff)
modules/shapes: add spin setting for star+pinwheel
Introduces spin={-1,0,1} with a few intermediate fractions on both sides of 0. Controls rate and direction. As-is these multiple choice style options don't let you explicitly set a value in rototiller on the commandline that isn't in the set. There should probably be a flag in the desc we can set when bypassing the available options is tolerable, probably when regex's start getting enforced. That way rototiller's commandline setting parsing can just lean on the regex, and if the desc says anything can come in that passes the regex even if it's not in the values set, this can all still work and have something resembling input validation. At the end of the day, the multiple choice value sets are supposed to be a convenience/guide to a sane variety of values and of particular utility to randomizers like used by rtv/montage/compose, but also GUI setting selectors like in glimmer. They're not intended to get in the way preventing development from accessing explicit values of arbitrary precision which can be really necessary especially when trying to determine what's best for going in the values set.
Diffstat (limited to 'src/modules/shapes')
-rw-r--r--src/modules/shapes/shapes.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/src/modules/shapes/shapes.c b/src/modules/shapes/shapes.c
index f084a01..68d194e 100644
--- a/src/modules/shapes/shapes.c
+++ b/src/modules/shapes/shapes.c
@@ -66,6 +66,7 @@
#define SHAPES_DEFAULT_TYPE SHAPES_TYPE_PINWHEEL
#define SHAPES_DEFAULT_POINTS 5
+#define SHAPES_DEFAULT_SPIN .1
typedef enum shapes_type_t {
SHAPES_TYPE_CIRCLE,
@@ -78,6 +79,7 @@ typedef struct shapes_setup_t {
til_setup_t til_setup;
shapes_type_t type;
unsigned n_points;
+ float spin;
} shapes_setup_t;
typedef struct shapes_context_t {
@@ -173,7 +175,7 @@ static void shapes_render_fragment(void *context, unsigned ticks, unsigned cpu,
for (unsigned y = yoff; y < yoff + size; y++, Y += s) {
X = -1.f;
for (unsigned x = xoff; x < xoff + size; x++, X += s) {
- float rad = atan2f(Y, X) + (float)ticks * .001f;
+ float rad = atan2f(Y, X) + (float)ticks * ctxt->setup.spin * .01f;
float r = cosf((float)ctxt->setup.n_points * rad) * .5f + .5f;
if (X * X + Y * Y < r * r)
@@ -212,7 +214,7 @@ static void shapes_render_fragment(void *context, unsigned ticks, unsigned cpu,
for (unsigned y = yoff; y < yoff + size; y++, Y += s) {
X = -1.f;
for (unsigned x = xoff; x < xoff + size; x++, X += s) {
- float rad = atan2f(Y, X) + (float)ticks * .001f;
+ float rad = atan2f(Y, X) + (float)ticks * ctxt->setup.spin * .01f;
float r = (M_2_PI * asinf(sinf((float)ctxt->setup.n_points * rad) * .5f + .5f)) * .5f + .5f;
/* ^^^^^^^^^^^^^^^^^^^ approximates a triangle wave */
@@ -232,6 +234,7 @@ static int shapes_setup(const til_settings_t *settings, til_setting_t **res_sett
{
const char *type;
const char *points;
+ const char *spin;
const char *type_values[] = {
"circle",
"pinwheel",
@@ -260,6 +263,24 @@ static int shapes_setup(const til_settings_t *settings, til_setting_t **res_sett
"20",
NULL
};
+ const char *spin_values[] = {
+ "-1",
+ "-.9",
+ "-.75",
+ "-.5",
+ "-.25",
+ "-.1",
+ "-.01",
+ "0",
+ ".01",
+ ".1",
+ ".25",
+ ".5",
+ ".75",
+ ".9",
+ "1",
+ NULL
+ };
int r;
r = til_settings_get_and_describe_value(settings,
@@ -293,6 +314,20 @@ static int shapes_setup(const til_settings_t *settings, til_setting_t **res_sett
if (r)
return r;
+ r = til_settings_get_and_describe_value(settings,
+ &(til_setting_desc_t){
+ .name = "Spin factor",
+ .key = "spin",
+ .regex = "-?(0|1|0\\.[0-9]{1,2})", /* Derived from pixbounce, I'm sure when regexes start getting actually applied we're going to have to revisit all of these and fix them with plenty of lols. */
+ .preferred = TIL_SETTINGS_STR(SHAPES_DEFAULT_SPIN),
+ .values = spin_values,
+ .annotations = NULL
+ },
+ &spin,
+ res_setting,
+ res_desc);
+ if (r)
+ return r;
}
if (res_setup) {
@@ -316,8 +351,10 @@ static int shapes_setup(const til_settings_t *settings, til_setting_t **res_sett
return -EINVAL;
}
- if (setup->type == SHAPES_TYPE_STAR || setup->type == SHAPES_TYPE_PINWHEEL)
+ if (setup->type == SHAPES_TYPE_STAR || setup->type == SHAPES_TYPE_PINWHEEL) {
sscanf(points, "%u", &setup->n_points); /* TODO: -EINVAL parse errors */
+ sscanf(spin, "%f", &setup->spin); /* TODO: -EINVAL parse errors */
+ }
*res_setup = &setup->til_setup;
}
© All Rights Reserved