0% found this document useful (0 votes)
60 views

Import ,: - Init

This document defines functions for creating and interacting with buttons in a pygame application. It initializes pygame, loads background images, defines a button class for creating buttons with customizable properties like size, color, position and text. It then creates instance buttons for selecting between an animal or plant cell, and displays function descriptions for different organelle buttons within each cell type when clicked.

Uploaded by

api-512738790
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Import ,: - Init

This document defines functions for creating and interacting with buttons in a pygame application. It initializes pygame, loads background images, defines a button class for creating buttons with customizable properties like size, color, position and text. It then creates instance buttons for selecting between an animal or plant cell, and displays function descriptions for different organelle buttons within each cell type when clicked.

Uploaded by

api-512738790
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

import pygame

pygame.init()
display = pygame.display.set_mode((700, 436))
pygame.display.set_caption('cells!')
background = pygame.image.load('initpage.jpg').convert()
display.blit(background, (0, 0))
pygame.display.update()
pygame.font.init()
myfont = pygame.font.SysFont('Comic Sans MS', 30)
class button():
def __init__(self,size, color, x, y, width, height, text=''):
self.color = color
self.x = x
self.y = y
self.width = width
self.height = height
self.text = text
self.size = size
def draw(self, display, outline=None):
if outline:
pygame.draw.rect(display, outline, (self.x - 2, self.y - 2, self.width +
4, self.height + 4), 0)
pygame.draw.rect(display, self.color, (self.x, self.y, self.width,
self.height), 0)
if self.text != '':
font = pygame.font.SysFont('comicsans', self.size)
text = font.render(self.text, 1, (0, 0, 0))
display.blit(text, (
self.x + (self.width / 2 - text.get_width() / 2), self.y + (self.height /
2 - text.get_height() / 2)))
def isOver(self, pos):
if pos[0] > self.x and pos[0] < self.x + self.width:
if pos[1] > self.y and pos[1] < self.y + self.height:
return True
return False
def blit_text(surface, text, pos, font, color=pygame.Color('black')):
words = [word.split(' ') for word in text.splitlines()]
space = font.size(' ')[0]
max_width, max_height = surface.get_size()
x, y = pos
for line in words:
for word in line:
word_surface = font.render(word, 0, color)
word_width, word_height = word_surface.get_size()
if x + word_width >= max_width:
x = pos[0] # Reset the x.
y += word_height # Start on new row.
surface.blit(word_surface, (x, y))
x += word_width + space
x = pos[0] # Reset the x.
y += word_height # Start on new row.
pygame.mixer.music.load('backgroundscience.mp3')
pygame.mixer.music.play(-1,0.0)
animalButton=button(40,(255,0,0),100,350,150,50,'animal cell')
animalButton.draw(display, (0, 0, 0))
plantButton=button(40,(255,0,0),300,350,150,50,'plant cell')
plantButton.draw(display, (0, 0, 0))
pygame.display.update()
running = True
while (running):
pos = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.MOUSEBUTTONDOWN:
if animalButton.isOver(pos):
e="a"
running = False
elif plantButton.isOver(pos):
e="p"
running = False
if event.type == pygame.MOUSEMOTION:
if animalButton.isOver(pos):
animalButton.color=(0,0,255)
elif plantButton.isOver(pos):
plantButton.color=(0,0,255)
else:
animalButton.color = (255, 0, 0)
plantButton.color = (255, 0, 0)
while running==False:
if e=="a":
display = pygame.display.set_mode((750, 549))
background = pygame.image.load('animaldia.jpg').convert()
display.blit(background, (0, 0))
pygame.display.update()
nextButton = button(40,(255, 0, 0),550, 25, 175, 50, 'go to plant!')
nextButton.draw(display, (0, 0, 0))
pygame.display.update()
animalrunning=True
nucleusButton = button(25,(0, 255, 0), 20, 280, 90, 20, 'function')
nucleusButton.draw(display, (0, 0, 0))
nuclearEnvelopeButton = button(25,(0, 255, 0), 30,236, 90, 20, 'function')
nuclearEnvelopeButton.draw(display, (0, 0, 0))
cytoplasmButton = button(25, (0, 255, 0), 21, 353, 90, 20, 'function')
cytoplasmButton.draw(display, (0, 0, 0))
golgiApparatusButton = button(25, (0, 255, 0), 110, 490, 90, 20, 'function')
golgiApparatusButton.draw(display, (0, 0, 0))
mitochondrionButton = button(25, (0, 255, 0), 580, 517, 90, 20, 'function')
mitochondrionButton.draw(display, (0, 0, 0))
cellMembraneButton = button(25, (0, 255, 0), 610, 433, 90, 20, 'function')
cellMembraneButton.draw(display, (0, 0, 0))
ERButton = button(25, (0, 255, 0), 610, 355, 90, 20, 'function')
ERButton.draw(display, (0, 0, 0))
lysosomeButton = button(25, (0, 255, 0), 573, 220, 90, 20, 'function')
lysosomeButton.draw(display, (0, 0, 0))
ribosomeButton = button(25, (0, 255, 0), 583, 145, 90, 20, 'function')
ribosomeButton.draw(display, (0, 0, 0))
nucleolusButton = button(25, (0, 255, 0), 185, 120, 90, 20, 'function')
nucleolusButton.draw(display, (0, 0, 0))
pygame.display.update()
def ar(texting):
display = pygame.display.set_mode((600, 382))
background = pygame.image.load('backforlittle.jpg').convert()
display.blit(background, (0, 0))
pygame.display.update()
text = (str(texting))
font = pygame.font.SysFont('Arial', 55)
nextButton = button(30, (255, 0, 0), 20, 25, 150, 50, 'go back!')
nextButton.draw(display, (0, 0, 0))
pygame.display.update()
littlerunning = True
while (littlerunning):
blit_text(display, text, (20, 20), font)
pygame.display.update()
pos = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
littlerunning = False
global running,e,animalrunning
running = True
if event.type == pygame.MOUSEBUTTONDOWN:
if nextButton.isOver(pos):
e = "a"
littlerunning = False
animalrunning = True
while (animalrunning):
pos = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
animalrunning = False
running =True
if event.type == pygame.MOUSEBUTTONDOWN:
if nextButton.isOver(pos):
e = "p"
animalrunning = False
elif nucleusButton.isOver(pos):
e = "nucleusButton"
animalrunning = False
elif nuclearEnvelopeButton.isOver(pos):
e = "nuclearEnvelopeButton"
animalrunning = False
elif cytoplasmButton.isOver(pos):
e = "cytoplasmButton"
animalrunning = False
elif golgiApparatusButton.isOver(pos):
e = "golgiApparatusButton"
animalrunning = False
elif mitochondrionButton.isOver(pos):
e = "mitochondrionButton"
animalrunning = False
elif cellMembraneButton.isOver(pos):
e = "cellMembraneButton"
animalrunning = False
elif ERButton.isOver(pos):
e = "ERButton"
animalrunning = False
elif lysosomeButton.isOver(pos):
e = "lysosomeButton"
animalrunning = False
elif ribosomeButton.isOver(pos):
e = "ribosomeButton"
animalrunning = False
elif nucleolusButton.isOver(pos):
e = "nucleolusButton"
animalrunning = False
if e == "nucleusButton":
ar(" \nThe key function of the nucleus is to control cell growth and
multiplication.")
elif e == "nuclearEnvelopeButton":
ar(" \nSeparation of DNA from cytoplasm machinery.\nRegulation of contents
that move in and out.")
elif e == "cytoplasmButton":
ar(" \nprovide a medium for the cellular contentsto exist in")
elif e == "golgiApparatusButton":
ar(" \nSecretory.\nIt produces vacuoles or secretory vesicles which contain
cellular secretions")
elif e == "mitochondrionButton":
ar(" \nThe main function of mitochondria is the production of ATP through
cellular respiration")
elif e == "cellMembraneButton":
ar("\nA cell membrane separates an individual cell or a cellular compartment
from other surrounding structures")
elif e == "ERButton":
ar("\nIt is mainly responsible for the transportation of proteins and other
carbohydrates to another organelle")
elif e == "lysosomeButton":
ar(" \nrecycling old cells, digesting materials that are both inside and
outside of the cell, and releasing enzymes")
elif e == "ribosomeButton":
ar(" \nresponsible for assembling the proteins of the cell")
elif e == "nucleolusButton":
ar(" \nproduction of ribosomes and synthesis of ribosomal RNA (rRNA)")
if e=="p":
display = pygame.display.set_mode((900, 524))
background = pygame.image.load('plantd.jpg').convert()
display.blit(background, (0, 0))
pygame.display.update()
backButton = button(40,(255, 0, 0),675,450, 200, 50, 'go to animal!')
backButton.draw(display, (0, 0, 0))
pygame.display.update()
chloroplastButton = button(35, (0, 255, 0), 260, 73, 110, 30, 'function')
chloroplastButton.draw(display, (0, 0, 0))
pnucleolusButton = button(35, (0, 255, 0), 280, 143, 110, 30, 'function')
pnucleolusButton.draw(display, (0, 0, 0))
pribosomeButton = button(35, (0, 255, 0), 240, 215, 110, 30, 'function')
pribosomeButton.draw(display, (0, 0, 0))
pvacuoleButton = button(35, (0, 255, 0), 227, 337, 110, 30, 'function')
pvacuoleButton.draw(display, (0, 0, 0))
pmitochondrionButton = button(35, (0, 255, 0), 315, 405, 110, 30, 'function')
pmitochondrionButton.draw(display, (0, 0, 0))
pmembraneButton = button(35, (0, 255, 0), 370, 470, 110, 30, 'function')
pmembraneButton.draw(display, (0, 0, 0))
cellwallButton = button(35, (0, 255, 0), 770, 65, 110, 30, 'function')
cellwallButton.draw(display, (0, 0, 0))
pygame.display.update()
plantrunning = True
while (plantrunning):
pos = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
plantrunning = False
running =True
if event.type == pygame.MOUSEBUTTONDOWN:
if backButton.isOver(pos):
e = "a"
plantrunning = False
elif pnucleolusButton.isOver(pos):
e = "pnucleolusButton"
plantrunning = False
elif chloroplastButton.isOver(pos):
e = "chloroplastButton"
plantrunning = False
elif pribosomeButton.isOver(pos):
e = "pribosomeButton"
plantrunning = False
elif pvacuoleButton.isOver(pos):
e = "pvacuoleButton"
plantrunning = False
elif pmitochondrionButton.isOver(pos):
e = "pmitochondrionButton"
plantrunning = False
elif pmembraneButton.isOver(pos):
e = "pmembraneButton"
plantrunning = False
elif cellwallButton.isOver(pos):
e = "cellwallButton"
plantrunning = False
def df(textings):
display = pygame.display.set_mode((600, 382))
background = pygame.image.load('backforlittle.jpg').convert()
display.blit(background, (0, 0))
pygame.display.update()
text = (str(textings))
font = pygame.font.SysFont('Arial', 45)
nextButton = button(30, (255, 0, 0), 20, 25, 150, 50, 'go back!')
nextButton.draw(display, (0, 0, 0))
pygame.display.update()
littlerunning = True
while (littlerunning):
blit_text(display, text, (20, 20), font)
pygame.display.update()
pos = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
littlerunning = False
global running
running = True
if event.type == pygame.MOUSEBUTTONDOWN:
if nextButton.isOver(pos):
global e
e = "p"
littlerunning = False
global plantrunning
plantrunning = True
if e == "pnucleolusButton":
df(" \nproduction of ribosomes and synthesis of ribosomal RNA (rRNA)")
elif e == "chloroplastButton":
df(" \nabsorb sunlight from sun for carrying out photosynthesis.")
elif e == "pribosomeButton":
df(" \nresponsible for assembling the proteins of the cell")
elif e == "pvacuoleButton":
df(" \nprovide the plant with support or rigidity, a storage area for
nutrients and waste matter and can decompose complex molecules")
elif e == "pribosomeButton":
df(" \nresponsible for assembling the proteins of the cell")
elif e == "pmitochondrionButton":
df(" \nThe main function of mitochondria is the production of ATP through
cellular respiration")
elif e == "pmembraneButton":
df(" \nA cell membrane is a thin layer that acts as a barrier that separates
an individual cell or a cellular compartment from other surrounding structures")
elif e == "cellwallButton":
df(" \ngives cells shape, enables plant growth, prevents bursting from water
pressure, keeps out water and pathogens, stores carbohydrates and sends signals to
cells. ")

You might also like