Is there an easy way for the to specify points?

This is my first script in aseprite, and I am working on a function for multi-color gradients. Because the gradient tool can be used at an angle, and so I don’t have to do all the hard math, my script will be using the gradient tool multiple times.

This leads me to my question: How can I get the user to specify points on the canvas? Another script I saw (and used) used pre-drawn points on the canvas. This seems a little bit hard to use (though it works quite well) and so I am wondering if there is some way I can get the user’s mouse positions after two or more clicks during a dialog box. This seems to be the single thing I have seen missing from the really great API that has been put together- being able to interact with the rest of the app.

Much thanks!

2 Likes

As far as I know there’s no option to do that and I’d very much would like for this to be possible.

BUT

There are some ways to go around it, as you mentioned, others used pre-drawn points, I’d suggest a solution where a user can specify point from a dialog, you can draw a preview of them on a special layer.

I’d be happy to help with that, I have experience with writing overly complex dialogs. :smiley:

Hi all,

Yep, same here.

Re: specifying a point from a dialog. I’ve tried similar, except with percentages of the sprite’s width and height. I don’t find it as intuitive as the mouse-controlled built-in gradient.

An advantage of points in pixels over percentages is that you could expand a gradient’s origin and destination into coordinates beyond the sprite’s dimensions, e.g., from (-16, -16) to (48, 48) for a 32 x 32 sprite.

A disadvantage is entering inputs via keyboard. If you’ve ever typed a number, then left the dialog open, then pressed a tool shortcut without realizing what’s in focus, you see my point. (Although, I suppose sliders capture arrow keys as well.)

polarInputs

Another possibility is to use polar coordinates. Let the user define the center point (x, y), the angle of the gradient and the radius of origin and destination from the center. The dialog would convert polar to Cartesian. A disadvantage is that some users are used to clockwise rotation (positive y points down); others, counter-clockwise (positive y points up).

Or maybe consider the top-left and bottom-right of a selection’s bounds to define origin and destination. The selection contains method could mask off the gradient to a shape.

Lastly, a tangent: I encourage tackling the math. Not a math fan myself, but I’ve found that learning it gives you greater independence from any one API.

badDiagram7

The key concept is the scalar projection of one vector onto the other. It may help to learn the dot product first. Vector projection is the method we’d use to visualize geometry, i.e., the point projected on the line seg. However, for a gradient, we only need a percentage to supply to a color mixing function.

I made the percentage, n, lower case to show that it’s a single number, not an (x, y) pair. What confused me when I first learned is that tutorials sometimes distinguished between a point and a vector, and at other times didn’t. In the above, A and B are vectors. Subtracting one point from another yields a vector; adding a vector to a point yields a point.

Depending on whether you clamp or modulo the percentage, the gradient could truncate at the end points, as above, or repeat in a cycle.

By not using the built-in gradient, you’d lose access to dithering effects. For me, the effects are less useful for gradients with multiple colors and gradients that mix in perceptual space… But I realize it’s a matter of taste.

Cheers,
Jeremy

Thanks for the insightful reply! A great solution I’ll try to implement…

I think I could convert the polar coordinates to cartesian for the gradient tool. It seems the easiest to use. I was planning to use linear interpolation and some weird mess of math I haven’t written yet, but vectors is an interesting solution that seems much more versatile. Again, thanks for the wonderful ideas :slight_smile: