If you had the four corners of a rectangle or square and wanted to get the vertices that describe each side how would you do it? This is what I am doing:
corners = [(0,1), (1,1), (1,0), (0,0)]
corners_cycle = itertools.cycle(corners)
sides = []
next(corners_cycle)
for c in corners:
sides.append((c, next(corners_cycle)))
print(sides)
@AndrasDeak Okay, that works. They are always in order going around the perimeter. I just couldn't think of a good way to get back to the first one in the end to make the last pair of points
tkinter does the heavy lifting with smooth=True, creating a spline. So one keyword is "spline". And then there's the hack that adding a point twice will make the segment straight even with smooth=True.
You guys think some_array.dtype.type is np.string_ can be an issue 1) if native python string type is. held, or 2) (trickier) if the string encoding is utf8 vs utf32 (so np.unicode_)
@CoolCloud I think that it helps to visualize the canvas as a grid with horizontal and vertical lines drawn at all the coordinates used in the poly list. Let me see if I can make a mockup in paint
The following aliases originate from Python 2, and it is recommended that they not be used in new code.
numpy.string_: alias of numpy.bytes_
numpy.unicode_: alias of numpy.str_
Here is every X and Y coordinate used in the solution. Without even looking at which x coordinates match up with which y coordinates, we can already tell the result will be rectangle-like, because the polygon's vertices can only pass through where the lines intersect
I still don't get those corner points to be honest. Seems to contradict the "define points" aspect. It's more like defining control points for a Bezier curve...
Since smoothing is disabled for double-specified points (apparently), we know with certainty that any lines drawn between double-specified points will be perfectly straight lines.
I agree with Andras that the single-specified points behave more like a "control point" than an actual vertex. Just as in Bezier curves, the control point will probably not actually lie on top of the curve.
I'm keeping my wager low because you can't really get a perfect semicircle with a bezier curve, but maybe it's close enough to pass casual inspection at this magnification
Tcl says smooth=True gives you bezier curves as "parabolic splines" by default, but other algorithms can be added at runtime
Oh, the behavior of doubled-up coordinates is guaranteed, that's nice: "Straight-line segments can be generated within a curve by duplicating the end-points of the desired line segment. "
Perhaps just a natural consequence of the algorithm they're using, rather than something they went out of their way to special-case
I am somewhat surprised by the output of this script, which draws a "smooth triangle". The resulting blue blob does not pass through any of my specified vertices. Even bezier curves pass through at least two of their points.
If you're asking "wouldn't the result look the same even if the rounded rectangle only had single-defined points?", my instinct is that it would get bendy in the middle
If you're asking "in other image-drawing libraries that can do smooth polygons, are they smart enough to know when to draw straight lines without the user specifying double coordinates?", I'm going to guess "no"
For example the HTML5 canvas framework can make polygons with straight and curved components, but you have to toggle a "isThisSegmentACurve" flag to your desired state
Yeah, I'd expect most frameworks to have a "straight line segments" vs "smooth curve" mode, with the latter interpolating across the input points in some way. There are many ways to define splines.
The more flexible the engine is, the more pain in the butt it is to use it.
It seems likely to me that you could use pure splines to draw a rounded rectangle in any framework that can draw splines, without using any framework-specific features. But it would be harder to figure out where the coordinates should go
@CoolCloud True. As tobias_k says, you can do it with arcs, but then it takes more than one draw call. This may or may not be acceptable depending on what you want to do with the shape later
Hi everyone. I am trying to see if the very basic things (like a simple producer/consumer pair on a json data or something) that one can do with kafka can be done with asyncio library. I was asked to solve an interview task with "streaming mentality" in Python, and I used Kafka (used the official python client, and a docker container for the broker), but could I handle it just in Python?