Find all integer coords a shape can with a size can land on, in a custom block

So, this is a bit complicated.
I need a custom block that can take a shape (circle, square, triangle or hexagon) and find all integer coordinates that this shape lies on.

Say if I have a square, of width 5 and height 3, then it returns a list of points the square lies on. (order doesn’t really matter)

[[2, 1], [1, 1], [0, 1], [-1, 1], [-2, 1],
[2, 0], [1, 0], [0, 0], [-1, 0], [-2, 0],
[2, -1], [1, -1], [0, -1], [-1, -1], [-2, -1]]

something like this (definition is empty):
untitled script pic

You mean “rectangle,” not “square,” if its width and height can be different. :~)

More generally, your problem is underspecified. In the case of rectangles, I’m guessing you mean ones whose sides are vertical and horizontal, not at an angle. What about triangles, though? Do you mean isosceles triangles with a horizontal base? Or could it be turned like this: :play_button:︎? And so on.

If you give a sprite a costume with the shape of interest, Snap! will tell you its bounding box (the smallest vertical-horizontal rectangle that encloses the shape). Then you can just ask each point inside the bounding box whether the sprite is TOUCHING it, or you can be cleverer and take advantage of the fact that your shapes are convex, so if you find the outermost points at an integer Y value that are touching the shape, all the ones in between will be touching it also. And your shapes are symmetrical around the Y axis, so you really only have to find the leftmost touching point and the rightmost one will be [-x, y].

this could work, but they are slightly pixelated so all the pixels land on the pixel grid, so stretching the shape will have worse accuracy for larger and wider and taller shapes.

What i mean to say is, if you have a certain shape, like an ellipse, rectangle, triangle or hexagon, but squished and stretched to fit the width and height, then plot that on a grid, and map it so it fits the grid, the points on the grid would all be 2 argument lists of X and Y. these points would be reported within another list.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.