Open anandology opened 3 years ago
I could do:
c = circle()
points = c.get_points(n=5)
Looks like it is extensible.
e = ellipse()
points = e.get_points(n=5)
r = rectangle(w=200, h=100)
points = e.get_points(n=8) # any multiple of 4 will work
This approach an be extended to a line or polygon as well.
But I have not introduced methods yet. Not sure, if it is a good idea to do it this way.
It will be very useful. You should look at these two function in SVG which do the basic stuff.
It should work on any path & shape - so I would suggest to name it as a general function that work on Path and Shapes. e.g. get_point_on_path
and get_point_on_shape
For inspiration & examples, also look at Coordinator Library - https://github.com/spotify/coordinator which extends it beyond paths to shape. Write up about the library @ https://engineering.atspotify.com/2018/03/02/introducing-coordinator-a-new-open-source-project-made-at-spotify-to-inject-some-whimsy-into-data-visualizations/
It will be very useful. You should look at these two function in SVG which do the basic stuff.
* [SVGGeometryElement.getPointAtLength()](https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement/getPointAtLength) * [SVGGeometryElement.getTotalLength()](https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement/getTotalLength)
It should work on any path & shape - so I would suggest to name it as a general function that work on Path and Shapes. e.g.
get_point_on_path
andget_point_on_shape
Rather than having to get individual points by specifying length, I think it would be better have a function that returns a list of n points at equal distance on the shape/path.
Also, instead of having a function specific to path or shape, I suggested a method get_points
that works on every primitive shape.
One option could be to have a global function get_points(shape, n)
, but I'm not convinced to add this to the global namespace.
For inspiration & examples, also look at Coordinator Library - https://github.com/spotify/coordinator which extends it beyond paths to shape. Write up about the library @ https://engineering.atspotify.com/2018/03/02/introducing-coordinator-a-new-open-source-project-made-at-spotify-to-inject-some-whimsy-into-data-visualizations/
Thats looks quite interested!
Path and Shapes are different - similar to Stroke and Fill (for Colors). So Points on a Path and Points in a Shape have different meaning.
Right now the library does differentiate between the two - so may be later.
Also, worth thinking about what happens when you draw multiple shapes? Or is this going to be limited to primitive shapes (line, rectangle, circle) only.
Path and Shapes are different - similar to Stroke and Fill (for Colors). So Points on a Path and Points in a Shape have different meaning.
Agreed. But I'm trying to see if it is possible to unify that.
Right now the library does differentiate between the two - so may be later.
Thanks for the caution. I'll read up a bit and see if I need to model it differently.
Also, worth thinking about what happens when you draw multiple shapes? Or is this going to be limited to primitive shapes (line, rectangle, circle) only.
It is only for primitive shapes right now. I can't think of a way to generalize this.
However, I would love to find a way to identify a bounding box for any shape. It could be just the center of the shape and width and height.
It would be interesting to have a function that returns points equidistant on a circle.
These points can be used to create very intersting shapes by connecting to each other point etc. This will allow the students to achive all these shapes without worrying about sine and cosine.
I'm not particularly happy with the name
points_on_circle
. Another option iscrange
, just likerange
, but returns points on a circle.It feels quite useful, but at the same time it also feels like this function doesn't really belong to the joy library and doesn't go well with all other functions.
@amitkaps what do you think?