I have been trying to draw a simple circle using the arcade python library, but all I can see is a perfectly positioned triangle instead.
Here's the sample code I used:
import arcade
# Set constants for the screen size
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 400
SCREEN_TITLE = "Happy Face Example"
# Open the window. Set the window title and dimensions
arcade.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
# Set the background color
arcade.set_background_color(arcade.color.WHITE)
arcade.start_render()
# Draw the face
x = SCREEN_WIDTH // 2
y = SCREEN_HEIGHT // 2
radius = 100
arcade.draw_circle_filled(x, y, radius, arcade.color.YELLOW)
arcade.finish_render()
# Keep the window open until the user hits the 'close' button
arcade.run()
After several hours of searching the internet for a solution, I tried it on another PC, and I got a proper circle !!
My machine spec:
i) AMD Ryzen 5 2500U , Vega 8 graphics
ii) 8 GB RAM
iii) OS: Ubuntu 21.10
iv) Python version: 3.10
The machine on which it worked also runs Ubuntu 21.10, with an AMD CPU + GTX 1060 6 GB video card and has Python 3.10 installed.
What could be the problem?
It is due to the fact that a circle is in fact rendered as a polygon. The quality of a sphere is determined by the number of vertices of this polygon.
According to the docs, you can set this is num_segments
parameter:
num_segments (int) – Number of triangle segments that make up this circle. Higher is better quality, but slower render time. The default value of -1 means arcade will try to calculate a reasonable amount of segments based on the size of the circle.
However, on some verisions of the library and some hardware, the default calculation goes wrong, so you have to set in manually.
So, your code should be something like this:
arcade.draw_circle_filled(x, y, radius, arcade.color.YELLOW, 0, 100)
However, since you most likely want the resolution to depend on the size of the sphere, I suggest you use this formula:
arcade.draw_circle_filled(x, y, radius, arcade.color.YELLOW, 0, int(2.0 * math.pi * radius / 3.0))