« first day (3859 days earlier)      last day (1313 days later) » 
02:00 - 20:0020:00 - 00:00

20:06
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)
[((0, 1), (1, 1)), ((1, 1), (1, 0)), ((1, 0), (0, 0)), ((0, 0), (0, 1))]
That's fine, right?
Since it's only four items I'd be inclinded to just do zip(corners, corners[1:] + corners[:1])
What basics do I need to learn to understand these type of coordinates and shapes? How to make a tkinter canvas rectangle with rounded corners?
list(zip(...)) if you really want to end up with a list
@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
@AndrasDeak "inclinded"...
@CoolCloud there are several things going on there
Mostly you should read anzeljg.github.io/rin2/book2/2405/docs/tkinter/… or something similar
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.
20:13
I mean apart from the tkinter part, what about the points he made. Like coordinates, how did he figure it out
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
@CoolCloud I'll let Kevin do the drawing. But the idea is to deconstruct the curved rectangle into circles and lines
@Mikhail not sure how much of an issue it can be but I think you should compare dtypes
(Pdb) np.string_
<class 'numpy.bytes_'>
(Pdb) np.unicode_
<class 'numpy.str_'>
(Pdb) np.str_
<class 'numpy.str_'>
@AndrasDeak Ooooh
20:19
@AndrasDeak is it not more stable to do something like this or have I missed the mark?
Wait, no, I think I missed the mark
@Mikhail note:
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_
@Kevin So the enclosed region in the middle will be the rectangle? Where does the curving work?
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
20:21
@roganjosh no idea to be honest, I've never used that part of the ufunc API
@Kevin So you did not need all the points, that is nice
I'd either ignore the division by zero, or hand-pick "good" values with boolean indexing
But if you want a more precise estimation, then it can certainly be worthwhile to look at the x-y coordinate pairs. Mockup 2 coming up
But where/how does it curve?
Here are the actual coordinates specified. The circled points are the ones that were listed twice, "to 'stop' the smooth from occuring"
20:25
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...
@Kevin Ooooo thats how it happens
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 wondering if the exact behaviour of create_polygon is specified. I'll just look up the official documentation :'|
The second mockup explains alot, thanks 😃 @Kevin @AndrasDeak
I'll wager a quarter-quatloo on "they literally use bezier curves here"
20:29
Probably. With the middle point doubled for both control points. Which would agree with the angles.
So @CoolCloud that's another keyword (Bézier curves, that is). But proceed at your own risk.
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
@AndrasDeak Kay got it, splines and beziers
Hmm, perhaps they are B-splines.
we'd have to look at the ugliness of wiggly tkinter splines
A fine addition to my giant collection of unread math tabs
To be fair I mostly know of them.
20:33
I do wish these were a little simpler to fit into this tiny brain :^
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 don't think so. In a curvy case three points define a segment. In the straight case, four.
Assuming that's truly the case for the former. I've long closed the relevant answer.
Ok, I'll knock 10% off my statement's epistemic value, which demotes it from "perhaps" to "maybe(?)"
Just to confirm, does repeating coordinate make it straight or curve it?
It makes it straight.
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.
20:46
@Kevin look at the top figure in the B-spline article
For those uninterested in running the script
too late, I've already run it :'|
Well dang
What happens if you ever so slightly open the triangle?
Hmmm can ya take look at this? and tell what is wrong? paste.pythondiscord.com/puweyeduto.lua
20:48
Oh, never mind, it's closed by design. Explains a lot.
@CoolCloud you tell me
Oops forgot to add smooth=True there, but it still does not curve
@AndrasDeak Are the coordinates wrong 😬
you have too many doubled coordinates
@CoolCloud you tell me
Have you ever voted to close a question that just asks "what's wrong with my code?" without telling what's wrong with the code?
I have never done anything wrong in my life, ever
@AndrasDeak Well then, the code runs. But it does not create rounded rectangle
@AndrasDeak But I just doubled all the, supposed to be, straight lines.
@CoolCloud Maybe the radius is too small to see easily on your screen. Try a radius of 20.
20:53
@Kevin There is something wrong with the way I made the points. Radius doesn't help there
Does the starting coordinates matter
@CoolCloud you didn't double the corner points
or did I misunderstand your message
Here's what it looks like for me when I embiggen the radius.
Ah, radius of 5 with 100-long edges.
fourth corner point is missing, it all checks out
20:54
@Kevin Same
Oh wait it actually is rounded!!! I am blind!
The one corner is just missing
Re: "Does the starting coordinates matter", definitely not when using smooth=False. With smooth=True, I'm going to guess... Also no.
Finally it works
@AndrasDeak Thanks @AndrasDeak for noticing that
@Kevin Thats a relief
There may be fencepost strangeness if you try to double up a coordinate at the beginning and end of the list
Easy enough to test
But I don't get the concept as to why we double points to make them straight, why not leave them as such?
@CoolCloud we discussed this already:
20:58
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
20 mins ago, by Kevin
Perhaps just a natural consequence of the algorithm they're using, rather than something they went out of their way to special-case
20 mins ago, by Andras Deak
I don't think so. In a curvy case three points define a segment. In the straight case, four.
I know, I read it too. Just does not clip on. It is fine, ill try reading again or try something else out
So the reason is "either straightforward considering the implementation, or arbitrary API choice"
@AndrasDeak Oh okay, better
I do try
20:59
So usually(not tkinter) a single coordinate would make it okay right?
@CoolCloud come again?
there's no usually
"list of coordinates -> 2d spline" is not a math concept. It's a programming concept that relies on the specific implementation.
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"
So basically in some other framework if I were to use the same concept, I will have to double those points?
@Kevin Ah, okay cool
@AndrasDeak Oh I see
@CoolCloud you'd have to use whatever the specific implementation tells you to enforce straight lines, which might not even be possible.
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
(disclaimer: simplified and half remembered)
21:02
Oh, Okay got it guys
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
Might as well just use the circular arc mode of the same framework...
21:05
Yeah, I'd go with arcs over splines when I have the choice
There is create_arc() here too
In most cases you either want a circular or elliptical arc, otherwise you just want "something nice and smooth"
@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
Hmmmm true
One last question, why does it curve instead of going straight between those two vertices (x1,y2-rad) and (x1+rad,y2)
Oh because we didn't double the points, right?
If I understand your question correctly, right
21:09
Kay thats it, I understand it clear enough. Thanks :D
stackoverflow.com/a/61162928/13382000 this answer seems much crazier :P
 
3 hours later…
23:46
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?
02:00 - 20:0020:00 - 00:00

« first day (3859 days earlier)      last day (1313 days later) »