Forum Archive

Ellipse origin (SOLVED)

Sebastian

Is there a way to change the origin of an ellipse to be in the center of the ellipse?
I'll put a little example under that demonstrates why this would be convenient in some cases.

from scene import *
class MyScene(Scene):
    def setup(self):
        self.pos = (self.bounds.center())
        self.w = self.h = 100
        self.p = Point(self.pos.x+self.h/2, self.pos.y+self.w/2)
        self.colour = Color(1.00, 1.00, 1.00)

    def draw(self):
        background(0,0,0)
        fill(*self.colour)
        ellipse(self.pos.x, self.pos.y, self.w, self.h)
        for t in self.touches.values():
            #p = t.location.distance(self.pos)
            p = t.location.distance(self.p)
            text(str(p), x=100, y=100, font_size=24)
            if p < self.w/2:
                self.colour = Color(1.00, 0.00, 0.00)
            else: 
                self.colour = Color(1.00, 1.00, 1.00)
run(MyScene())
C0deH4cker

Try this:

def centered_ellipse(x, y, width, height):
    return ellipse(x - width/2, y - height/2, width, height)
Sebastian

Nice! I didn't think of that. That's exactly what I need! Thanks@C0deH4cker :D

C0deH4cker

Glad to help :)