简体   繁体   中英

draw circle with ellipse pygame

I am trying to write a paint program using pygame and I am having a problem with the ellipse tool. I want the user to be able to draw ellipses as a solid or ring when the mouse is left held. I then want the user to be able to draw circles when holding shift. I know there is a way to do this. I just don't know how. I have a rectangle tool that can draw squares based on the same ideas and it works. This doesn't. Please help.

if tool=="ellipse":
                screen.blit(copy,(0,0))
                a=min(mx,start[0])
                b=min(my,start[1])
                x=abs(mx-start[0])
                y=abs(my-start[1])
                if keys[304] or keys[305]:
                    y=x

                if keys[32]:
                    if x<size*2 or y<size*2:
                        draw.ellipse(screen,(c),(a,b,x,y))    
                    else:
                        draw.ellipse(screen,(c),(a,b,x,y),size)
                else:
                    draw.ellipse(screen,(c),(a,b,x,y))

I don't know what you're trying to do there, but it looks unnecessarily complicated. All you need is something like this where downpos is where the mouse was put down and pos is where the mouse is now:

if tool=="ellipse":#and the mouse is being clicked
    if downpos[0]<pos[0]:
        l=downpos[0]
    else:
        l=pos[0]
    if downpos[1]<pos[1]:
        t=downpos[0]
    else:
        t=pos[0]
    if shiftDown:
        if l<t:
            pygame.draw.ellipse(screen, c, (l, l, abs(downpos[0]-pos[0]), abs(downpos[1]-pos[1])), size)
        else:
            pygame.draw.ellipse(screen, c, (t, t, abs(downpos[0]-pos[0]), abs(downpos[1]-pos[1])), size)
    else:
        pygame.draw.ellipse(screen, c, (l, t, abs(downpos[0]-pos[0]), abs(downpos[1]-pos[1])), size)

I haven't tested this, so if it doesn't work, just let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM