Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I wan't to know how I can make objects in pygame. For example a Rectangle. How do I draw it? And I know/heard that you need different names for different shapes for example rect for rectangle. Can you tell me wich names I should use for other shapes? For example a triangle or a circle, etc.
I really hope this question is fitting to StackOverflow and not a waste of time for you! :)
You can draw rectangle in pygame using this code line -
DISPLAY=pygame.display.set_mode((500,400),0,32)
pygame.draw.rect(DISPLAY,BLUE,(200,150,100,50))
The above code, creates a rectangle Blue in color.
Now, Let's say in future you want to make a rectangle smaller or larger, in that case, you can just remove this rectangle and redraw it using the above command.
Similarly, to draw circle , you can use something like this:-
pygame.draw.circle(DISPLAY, BLUE, (150, 50), 15, 1)
Hope this helps!
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
I have an input file with the frame number and x,y coordinates for every frame in a video. Ex:
<frame#> <x>,<y>
3984 346,983
How would I use this information to draw these points on the respective frames and save the video with this information?
Just commenting here as Reine's comment below needs a correction. The second value should be the (x,y) of the endpoint, not the height and the width.
Alternatively, use just the rec-argument call, which does take the (x, y, w, h) form.
Documentation for cv.rectangle()
What do you want to draw? I'm assuming you want to mark out that specific spot? Then I would suggest you drawing a small rectangle/square around that specific pixel. Here's the python code:
cv2.rectangle(img,(xCoor,yCoor),(width,height),(255,0,255),3)
img is that frame you input. xCoor and yCoor are x and y coordinates. In your case its xCoor=346, yCoor=983. Width and Height is how wide and tall you want your rectangle to be. (255,0,255) are just rbg values for your drawn lines. Last parameter (3) is line thickness.
If you want to mark a dot or a spot, try drawing a tiny circle around your x and y coordinates with cv2.circle().
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Using Python, I want to check whether a circle has an equal radius along all 360 degrees. Actually, I have segmented a circular shape from an image and then want to check whether it has a same-sized and equal radius along all the 360 degrees or not.
Can someone kindly help and tell how to do that?
In Python, OpenCV is a strong choice for an imaging library. You'd want to fit a contour to the circle and use moments to check the properties. You can fit an ellipse and see how close the major and minor axis of the ellipse match.
See this tutorial/docs for details.
Also, this question should help.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have an image that I'm masking, but even the text gets thresholded. Here's a thresdholded image below:
As you can see, the time, letters and such are also a part of the mask. I want to get rid of them. How do I go about it?
If the images follow that kind of pattern, you could try to apply a morphological closing.
Whith a mask the right size for the closing and opening, it will get rid of the text in the image, leaving it black.
Note that applying a closing may also slightly modify the rest of the image (for instance, a circular mask may smooth the edges of the circle in the center of the mask).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am making this game where you are moving a circle using the arrows keys and there is another circle spawning randomly on the screen. I want to make a piece of code to detect when the first circle collides with the second circle. I know that collidepoint() might come in useful but there is nothing else I really can do. Any help would really be appreciated.
while True:
#if image1 collides with image2
Score -= 1
Pygame supports collision detection between sprites using circles.
The API call you need is:
pygame.sprite.collide_circle()
You can see an example of its use in this question on game dev SE (and don't worry - the bug that question is about has been fixed).
If for some reason you are not using sprites, then circle-circle collision detection is pretty straightforward: just test if the distance between them is less than the sum of their radii.
Or rather, test if the square of the distance between them is less than the square of the sum of their radii (to avoid slow square root calculation):
def circlesCollide(x1, y1, r1, x2, y2, r2):
return (((x2-x1)**2) + ((y2-y1)**2) < ((r1+r2)**2))
Note, that this assumes your circle is not moving fast enough to pass enitrely through the other circle in one update step, in which case you need to do a swept circle collision test.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need a way to get a list of all sprites in a certain area of the screen, and I cannot find one anywhere on the internet.
Can someone please give me an example code of how to do this?
If it helps, all the sprites are in an "active" list.
Depends on whether you have obstacles or not, i.e. what the definition of "In the Area" means and also home many sprites you are dealing with.
If there's not many sprites and the distance calc is fast then brute force is probably ok.
for sprite in sprites:
if something.distance(sprite) < THRESHOLD:
do_something_with_near_sprite(sprite)
If you have a lot of sprites have a look at quadtrees and things like that. If calculating the distance is complicated then you're probably going to want to look at A* algorithm. There are libraries for these things so you shouldn't have to implement them yourself unless you want to.
This is a pretty general question (prepare to have it voted down by others :)