Processing.py animated presentation help

hi, I’m trying to make an animated presentation using processing.py, I got the presentation part down, but im having some trouble trying to add some animations into this, every YouTube video I’ve seen is for java and not python, so im kinda stuck and im not sure where to go or what to do, any help would be appreciated! here is my code, its really simple because im still a beginner

# Importing necessary libraries
from time import sleep

# Global variables
slide = 0
animation = 0

def setup():
    size(600, 600);

def slide0():
    background(255)
    textSize(35)
    textAlign(CENTER)
    fill(0, 128, 0)  
    text("The Harmful Effects of E-Waste", width/2, height/2 - 40) 

def slide1():
    background(255)
    textSize(24)
    fill(0)
    text("What is E-Waste?", 50, 100)
    textSize(16)
    textAlign(LEFT)
    text("The UN defines e-waste as any discarded products with a battery\nor plug that contains toxic substances such as mercury, that can\npose as a severe risk to human as well as environmental health.", 50, 150)


# Slide 2: Negative impacts of e-waste
def slide2():
    background(255)
    textSize(24)
    fill(0)
    text("Negative Impacts", 50, 100)
    textSize(16)
    text("E-waste is not biodegradable. For example, open-air burning\nleads to air pollution and releases toxic substances into\nthe environment such as lead, mercury, and cadmium.\nThis puts human and animal health at risk.", 50, 150)

# Slide 3: Case studies/examples
def slide3():
    background(255)
    textSize(24)
    fill(0)
    text("Case Studies", 50, 100)
    textSize(16)
    text("Examples here.", 50, 150)

# Slide 4: Solutions
def slide4():
    background(255)
    textSize(24)
    fill(0)
    text("Solutions and Actions", 50, 100)
    textSize(16)
    text("List ways to reduce e-waste and encourage responsible\ndisposal and recycling of electronics.", 50, 150)

#Draw function
def draw():
    global slide, animation
    if slide == 0:
        slide0()
    elif slide == 1:
        slide1()
    elif slide == 2:
        slide2()
    elif slide == 3:
        slide3()
    elif slide == 4:
        slide4()

#Mouse click function
def mouseClicked():
    global slide, animation
    if slide < 4:
        slide += 1
    else:
        slide = 0
    sleep(0.2) 
1 Like

Cheers @urjija !

You seem to be going well, please, tell us more about what kind of animation you would like to add? What would you like to animate?

I was trying to imagine slide transitions, or objects inside each slide doing things… I used your animation variable going from 0 to 255… see if it makes sense.



# Global variables
slide = 0
animation = 0

def setup():
    size(600, 600);

def slide0():
    background(255)
    textSize(35)
    textAlign(CENTER)
    fill(0, 128, 0)  
    text("The Harmful Effects of E-Waste", width/2, height/2 - 40) 

def slide1():
    background(animation, 255, 255)
    textSize(24)
    fill(0)
    text("What is E-Waste?", 50, 100)
    textSize(16)
    textAlign(LEFT)
    text("The UN defines e-waste as any discarded products with a battery\nor plug that contains toxic substances such as mercury, that can\npose as a severe risk to human as well as environmental health.", 50, 150)


# Slide 2: Negative impacts of e-waste
def slide2():
    background(255, 0, animation)
    textSize(24)
    fill(0)
    text("Negative Impacts", 50, 100)
    textSize(16)
    text("E-waste is not biodegradable. For example, open-air burning\nleads to air pollution and releases toxic substances into\nthe environment such as lead, mercury, and cadmium.\nThis puts human and animal health at risk.", 50, 150)

# Slide 3: Case studies/examples
def slide3():
    background(255)
    textSize(24)
    fill(0)
    text("Case Studies", 50, 100)
    textSize(16)
    
    if animation > 25:
        text("Example 1.", 50, 150)
    if animation > 75:
        text("Example 2.", 50, 200)
    if animation > 125:
        text("Example 3.", 50, 250)
    if animation > 175:
        text("Example 4.", 50, 300)
    
        

# Slide 4: Solutions
def slide4():
    background(255)
    noStroke()
    fill(255, 200, 0)
    circle(10 * animation - 50, 300, 300)
    
    textSize(24)
    fill(0)
    text("Solutions and Actions", 50, 100)
    textSize(16)
    text("List ways to reduce e-waste and encourage responsible\ndisposal and recycling of electronics.", 50, 150)


#Draw function
def draw():
    global slide, animation
    if slide == 0:
        slide0()
    elif slide == 1:
        slide1()
    elif slide == 2:
        slide2()
    elif slide == 3:
        slide3()
    elif slide == 4:
        slide4()
    
    animation += 1
    if animation > 255:
        animation = 255


#Mouse click function
def mouseClicked():
    global slide, animation
    if slide < 4:
        slide += 1
    else:
        slide = 0
    animation = 0
2 Likes

so sorry for the late reply! I ended up creating some animations involving a computer, the earth and moving particles haha. thank you for your input!

2 Likes