How do I stop making multiple ellipses keep spawning on the canvas?

edited March 2017 in Python Mode

okay so this is my code so far:

  `diameter = 30`

    def setup():
        size(800,800)
        background(0)


    def draw():
        global diameter

        if diameter <= 100:
            ellipse(random(50,750), random(50,750),diameter,diameter)
            diameter = diameter + 1
        else:
            text("game over",100,100,100)
            return

I'm trying to make one ellipse appear at a random location on canvas, and grow until it's diameter reaches 100, and then the game over text appears. I realize the ellipses keep spawning because draw() is called 30 times per minute, but I don't know how to change my code so the ellipse appears once only at the random location and grows.

Answers

  • nevermind y'all I figured it out. I feel sort of dumb for not realizing this earlier. This is what I did

    diameter = 30
    x = random(50,750)
    y = random(50,750)
    def setup():
        size(800,800)
        background(0)
    
    def draw():
        global diameter
    
        if diameter <= 100:
            ellipse(x,y,diameter,diameter)
            diameter = diameter + 1
        else:
            text("game over",100,100,100)
            return
    
  • edited March 2017 Answer ✓

    Oh, I've just finished here as well: =P~

    # forum.Processing.org/two/discussion/21235/
    # how-do-i-stop-making-multiple-ellipses-keep-spawning-on-the-canvas
    
    # 2017-Mar-07
    
    
    MIN_DIAM, MAX_DIAM = 30, 200
    
    def setup():
        size(600, 500)
        smooth(4)
    
        blendMode(REPLACE)
        ellipseMode(CENTER)
        noStroke()
    
        textSize(24)
        textAlign(LEFT, BASELINE)
    
        mousePressed()
    
    
    def draw():
        global d
    
        clear()
        ellipse(x, y, d, d)
    
        d += 1
        if d > MAX_DIAM:
            noLoop()
            fill(0xffFF0000)
            text('Game Over', 100, 100)
    
    
    def mousePressed():
        global x, y, d
        x = random(MAX_DIAM, width  - MAX_DIAM)
        y = random(MAX_DIAM, height - MAX_DIAM)
        d = MIN_DIAM
    
        fill(0xffFFFF00)
        loop()
    
Sign In or Register to comment.