CS 177 – Project #1
Summer 2015
Due Date:
==========
This project is due Thursday July 9th before 11:59pm.
This assignment is an individual project and should be completed on your own using only your own
personally written code. You will submit one (1) copy of the completed Python program to the
Project 1 assignment on Blackboard. The completed file will include your name, the name of the
project and a description of its functionality and purpose of in the comments header. The file should
be named ”Project-1.py”.
This project will be the foundation of future assignments this semester, so it is important that you
maximize your program’s functionality.
Problem Description: Simulating the Movements of Cells in a Microscope
==============================================================
In 2014 Virginia scientist Eric Betzig won a Nobel Prize for his research in microscope technology.
Since receiving the award, Betzig has improved the technology so that cell functions, growth and
even movements can now be seen in real time while minimizing the damage caused by prior
methods. This allows the direct study of living nerve cells forming synapses in the brain, cells
undergoing mitosis and internal cell functions like protein translation and mitochondrial movements.
Your assignment is to write a Python program that graphically simulates viewing cellular organisms,
as they might be observed using Betzig’s technology. These simulated cells will be shown in a
graphics window (representing the field of view through Betzig’s microscope) and must be
animated, exhibiting behaviors based on the “Project Specifications” below. The simulation will
terminate based on user input (a mouse click) and will include two (2) types of cells, Crete and
Laelaps, (pronounced KREET and LEE-laps).
Crete cells should be represented in this simulation as three (3) small green circles with a radius of
8 pixels. These cells move nonlinearly in steps of 1-4 graphics window pixels. This makes their
movement appear jerky and random. Crete cells cannot move outside the microscope slide, (the
‘field’), so they may bump along the borders or even wander out into the middle of the field at times.
These cells have the ability to pass “through” each other.
A single red circle with a radius of 16 pixels will represent a Laelaps cell in this simulation. Laelaps
cells move across the field straight lines, appearing to ‘bounce’ off the field boundaries. Laelaps
sometimes appear to pass through other cells, however this is an optical illusion as they are very
thin and tend to slide over or under the other cells in the field of view.
Project Specifications:
====================
Graphics Window
• 500 x 500 pixel window
• White background
• 0,0 (x,y) coordinate should be set to the lower left-hand corner
Crete Cells
• Three (3) green filled circles with radius of 8 pixels
• Move in random increments between -4 and 4 pixels p.
CS 177 – Project #1 Summer 2015 Due Date =========.docx
1. CS 177 – Project #1
Summer 2015
Due Date:
==========
This project is due Thursday July 9th before 11:59pm.
This assignment is an individual project and should be
completed on your own using only your own
personally written code. You will submit one (1) copy of the
completed Python program to the
Project 1 assignment on Blackboard. The completed file will
include your name, the name of the
project and a description of its functionality and purpose of in
the comments header. The file should
be named ”Project-1.py”.
This project will be the foundation of future assignments this
semester, so it is important that you
maximize your program’s functionality.
Problem Description: Simulating the Movements of Cells in a
Microscope
===============================================
===============
In 2014 Virginia scientist Eric Betzig won a Nobel Prize for his
research in microscope technology.
Since receiving the award, Betzig has improved the technology
so that cell functions, growth and
even movements can now be seen in real time while minimizing
the damage caused by prior
2. methods. This allows the direct study of living nerve cells
forming synapses in the brain, cells
undergoing mitosis and internal cell functions like protein
translation and mitochondrial movements.
Your assignment is to write a Python program that graphically
simulates viewing cellular organisms,
as they might be observed using Betzig’s technology. These
simulated cells will be shown in a
graphics window (representing the field of view through
Betzig’s microscope) and must be
animated, exhibiting behaviors based on the “Project
Specifications” below. The simulation will
terminate based on user input (a mouse click) and will include
two (2) types of cells, Crete and
Laelaps, (pronounced KREET and LEE-laps).
Crete cells should be represented in this simulation as three (3)
small green circles with a radius of
8 pixels. These cells move nonlinearly in steps of 1-4 graphics
window pixels. This makes their
movement appear jerky and random. Crete cells cannot move
outside the microscope slide, (the
‘field’), so they may bump along the borders or even wander out
into the middle of the field at times.
These cells have the ability to pass “through” each other.
A single red circle with a radius of 16 pixels will represent a
Laelaps cell in this simulation. Laelaps
cells move across the field straight lines, appearing to ‘bounce’
off the field boundaries. Laelaps
sometimes appear to pass through other cells, however this is an
optical illusion as they are very
3. thin and tend to slide over or under the other cells in the field of
view.
Project Specifications:
====================
Graphics Window
• 500 x 500 pixel window
• White background
• 0,0 (x,y) coordinate should be set to the lower left-hand corner
Crete Cells
• Three (3) green filled circles with radius of 8 pixels
• Move in random increments between -4 and 4 pixels per step
• Movements are not in straight lines, but appear wander
aimlessly
Laelaps Cells
• One (1) red filled circle with a radius of 16 pixels
• Move more quickly than Crete cells and in straight lines
• The Laelaps cell should advance in either -10 or 10 pixels per
step
TODO #1: Initialize the simulation environment
========================================
• Import any libraries needed for the simulation
• Display a welcome message in the Python Shell. Describe the
4. program’s functionality
• Create the 500 x 500 graphics window named “Field”
• Set the Field window parameters as specified
TODO #2: Create the Crete cells – makeCrete()
========================================
• Write a function that creates three green circle objects (radius
8) and stores them in a list
• Each entry of the list represents one Crete cell
• The starting (x, y) locations of the Crete cells will be random
values between 50 – 450
• The function should return the list of Crete cells
TODO #3: Create the Laelaps cell – makeLaelaps()
===========================================
• Write a function that creates a list containing a single entry; a
red filled circle (radius 16)
representing the Laelaps cell
• The starting (x, y) location of these cells should be random
values between 100–400
• Add two randomly selected integers to the list. They should be
either -10 or 10
• The function should return the Laelaps cell list
TODO #4: Define the bounce() function
==================================
5. • Write a function that accepts two (2) integers as parameters
• If the first integer is either less than 10 or greater than 490,
the function should return the
inverse value of the 2nd integer, (ie: multiplying it by -1)
• Otherwise, the function should return the 2nd integer
unmodified
TODO #5: Define the main() function
==================================
• Using the makeCrete() function, create a list of Crete cells
• Draw the Crete cells in the Field graphics window
• Using the makeLaelaps() function, create the Laelaps list
• Draw the Laelaps cell in the Field window
• Using a while loop, animate the cells in the Field window
o Animate each Crete cell by moving it’s (x,y) position by a
number of pixels specified
by a randomly selected integer between -4 and 4
o Animate the Laelaps cell by moving it’s (x,y) position by the
number of pixels
specified in the integer values in it’s list (this will always be
either -10 or 10 pixels)
o HINT: Use the bounce() function to make sure the change in a
cell’s position doesn’t
move the cell outside the Field boundaries
o End the while loop if a mouse click is detected in the Field
graphics window
• Close the Field graphics window
• Print a message that the simulation has terminated
6. Extra Credit Challenges: 10 points each only if TODO #1 - 5
are complete
===============================================
================
• CROSSING GUARD: Laelaps cell ‘bounces’ off the Crete
cells instead sliding past them
• NO PASSING ZONE: Crete cells bounce off each other
instead of passing through
Project 1 Grading Rubric: Points
TODO #1: Libraries imported, message shown, graphics window
created to specifications 15
TODO #2: List of three (3) circle objects is created as specified
10
TODO #2: makeCrete() function properly returns list of circle
objects 5
TODO #3: List including one circle object and 2 integers is
created as specified 10
TODO #3: makeLaelaps() function properly returns list 5
TODO #4: bounce() function created as specified 10
TODO #5: makeCrete() and makeLaelaps() functions called,
lists created successfully 10
TODO #5: Crete and LaeLaps cells drawn in the Field window 5
TODO #5: Cells move as specified within the Field window,
bouncing off boundaries 20
TODO #5: Animation loop terminates when mouse clicked in
7. the Field window 5
TODO #5: Message is displayed indicating the simulation has
terminated 5
Total Points 100
You will submit one (1) copy of the completed Python program
to the Project 1 assignment on
Blackboard. The completed file will include your name, the
name of the project and a description of
its functionality and purpose of in the comments header. The
file should be named ”Project-1.py”.
Coding Standards and Guidelines:
=============================
In this project, you are required to follow modular coding
standards, particularly with respect to
modular design, indentation and comments. Your score will be
affected if your code does not
conform to these standards.
Modular Design
Divide your program into functions to improve readability and
to reduce redundanct code. Your
Python code should not have repetitve copies of the same block
of statements. Instead, functions
to simplify and reduce the size of your code.
For example, if you had to find the distance between two x,y
coordinate points in several different
parts of your code, instead of creating the formula to calculate
this distance over and over again,
create a function “def distance(x1, y1, x2, y2):” and code it to
8. calculate and return the distance
between the point using the Pythagorean Theorum.
Indentation
Following are a few rules on how to use indentation in your
program,
• Use tabs for indentations
• Pay attention to indentation in nested for loops and if-else
blocks
Comments
Your code for this project must also include appropriate
comments about how functions are
implemented. Comments make your code more readable and
easier to understand.
• Add a comment before a function describing what it does.
• Before a nested for loop, describe what happens in the loop
and what controls the
iterations.
• Before an if-else block, explain what should happen for both
the true and false cases.
• Always make a priority of keeping the comments up-to-date
when the code changes.
For all variables that you use in your program, use meaningful
variable and function names to help
make your program more readable. Names do not have to be
long, but should give a clear
indication of the intended purpose of the variable.
9. Teambuilding Week IV Assessment
Only 100% original, non-plagiarized responses to include all
references and
citations.
1. Select one of the team mediation techniques (negotiation,
role clarification, or start-stop-
continue) and describe how you would use this technique to
diffuse a team conflict
situation.
Your response should be at least 200 words in length. All
sources used must be
referenced; paraphrased and quoted material must have
accompanying citations.
2. Since violated expectations often lead to conflict for
individual and team relationships,
explain some of the most common expectations that leaders and
subordinates often
violate. Share personal work-related examples to solidify your
understanding of the
concept. In addition, discuss how these types of problems were
handled in your
workplace. Were the methods used correct or incorrect? Explain
your answer.
Your response should be at least 200 words in length. All
sources used, must be
10. referenced; paraphrased and quoted material must have
accompanying citations.
3. Identify some of the sources of conflict often experienced in
teams. Select one of the
sources and describe an exercise the team could utilize to
overcome the conflict.
Your response should be at least 200 words in length. All
sources used, must be
referenced; paraphrased and quoted material must have
accompanying citations.
CS 177 – Project #3
Summer 2015
PROJECT 3 TEAM ASSIGNMENTS ARE POSTED ON
BLACKBOARD
YOU MUST WORK WITH YOUR ASSIGNED TEAM TO
RECEIVE CREDIT
Due Date:
==========
This project is due Saturday August 1st before 11:59pm.
This assignment is an team project and should be completed
working cooperatively with your
team members – however your team may use only Python 3 code
that has been personally written
11. by one of the members assigned to your team. Your team will
submit one (1) copy of the completed
Python program to the Project 3 assignment on Blackboard.
ONLY ONE TEAM MEMBER
SHOULD SUBMIT A COPY The completed file will include the
names of all you team members, the
name of the project and a description of its functionality and
purpose of in the comments header.
The file should be named ”Project-3.py”.
This project is a continuation of your earlier projects and will
be based on the Project 2 code written
by one (or more) of your team members. It is important that you
carefully choose the starting code
before beginning Project 3 to maximize your final program’s
functionality.
Problem Description: Enhancing and Finalizing the Simulation
===============================================
======
Your second Crete and Laelaps simulation program was
excellent and you have been asked to
continue to enhance it with more realistic cellular behavior.
Crete and Laelaps cells should be able to consume food dropped
in the field. In addition, the
temperature of the field should affect their movements. In
addition, the scientists have asked for the
ability to save the simulation in a given state and then be able
to restart it from that point later.
Finally, you should come up with three of your own
enhancements to the program.
12. Project Specifications:
====================
PROJECT 2 BASE SCENARIO:
• Start with a completed simulation that fully meets the
specifications of Project 2
• If any Project 2 specification is incomplete, they must be
finished before starting Project 3
PAUSE, SAVE & RESTART:
• When the ‘Pause’ button on the Control Panel is clicked, in
addition to pausing the
simulation, all of the current parameters and objects are saved
to a file named “simData.txt”
• A message should be printed to the IDLE window:
“Simulation Data Saved”
• The simData.txt file should include everything shown in both
the Field and Control Panel,
including but not limited to:
o All Crete and Laelaps cell locations and properties
o The location of any food in the field
o The current simulation speed and temperature settings
o Any other information that would be necessary to recreate the
simulation exactly as it
appears when it was paused
• When the program starts, if it detects a simData.txt file, before
13. creating any graphics
windows or objects, the user should get the option to restart
with data from the saved file
DINNER TIME:
• Any cell that contacts “food” will increase their radius by 4
pixels, (food disappears)
HOT IN HERE:
• Changing the temperature affects the cell movement speed
• Higher temperatures cause Laelaps to move faster, Crete to
move slower
• Lower temperatures cause Laelaps to move slower, Crete to
move faster
o HINT: Use the temperature value to modify the cell’s dx and
dy settings
PYTHON NINJA STYLE:
• Your team must develop three (3) further modifications to the
simulation
• These modifications should be fully described and documented
in either:
o a readme.txt file that is uploaded along with your Blackboard
submission -or-
o in comments within your project-3.py program
• The scope and functionality of these modifications are totally
up to you and your team. Up to
25 points will be awarded for each of the 3 modifications based
on functionality (it should
14. work as you describe) and creativity.
Project 3 Grading Rubric: Points
Simulation should meets all Project 2 Specifications
Program meets all coding standards and guidelines (see next
page) 5
PAUSE, SAVE & RESTART 10
DINNER TIME 5
HOT IN HERE 5
PYTHON NINJA STYLE #1 25
PYTHON NINJA STYLE #2 25
PYTHON NINJA STYLE #3 25
Total Points 100
This assignment is an team project and should be completed
working cooperatively with your
team members – however your team may use only Python 3 code
that has been personally written
by one of the members assigned to your team. Your team will
submit one (1) copy of the completed
Python program to the Project 3 assignment on Blackboard.
ONLY ONE TEAM MEMBER
15. SHOULD SUBMIT A COPY The completed file will include the
names of all you team members, the
name of the project and a description of its functionality and
purpose of in the comments header.
The file should be named ”Project-3.py”.
Coding Standards and Guidelines:
=============================
In this project, you are required to follow modular coding
standards, particularly with respect to
modular design, indentation and comments. Your score will be
affected if your code does not
conform to these standards.
Modular Design
Divide your program into functions to improve readability and
to reduce redundanct code. Your
Python code should not have repetitve copies of the same block
of statements. Instead, functions
to simplify and reduce the size of your code.
For example, if you had to find the distance between two x,y
coordinate points in several different
parts of your code, instead of creating the formula to calculate
this distance over and over again,
create a function “def distance(x1, y1, x2, y2):” and code it to
calculate and return the distance
between the point using the Pythagorean Theorum.
Indentation
Following are a few rules on how to use indentation in your
program,
16. • Use tabs for indentations
• Pay attention to indentation in nested for loops and if-else
blocks
Comments
Your code for this project must also include appropriate
comments about how functions are
implemented. Comments make your code more readable and
easier to understand.
• Add a comment before a function describing what it does.
• Before a nested for loop, describe what happens in the loop
and what controls the
iterations.
• Before an if-else block, explain what should happen for both
the true and false cases.
• Always make a priority of keeping the comments up-to-date
when the code changes.
For all variables that you use in your program, use meaningful
variable and function names to help
make your program more readable. Names do not have to be
long, but should give a clear
indication of the intended purpose of the variable.
import time
from graphics import *
17. import random
print("Welcome, this program simulates viewing cells in real
time")
win = GraphWin("Field", 500, 500)
Control = GraphWin("Control Panel",400, 300)
Control.setBackground('grey')
Control.setCoords(0, 0, 299, 199)
win.setCoords(0, 0, 499, 499)
temperature = 42
Speed = 10
def Controlpanel():
global te
global temperature
global Speed
global spe
global restart
global heat
faster = Rectangle(Point(35, 130), Point(85, 180))
faster.draw(Control)
f = Text(Point(60, 155), "faster")
f.draw(Control)
pause = Rectangle(Point(95, 130), Point(145, 180))
pause.draw(Control)
p = Text(Point(120, 155), "pause")
p.draw(Control)
food = Rectangle(Point(155, 130), Point(205, 180))
food.draw(Control)
fo = Text(Point(180, 155), "DINNER")
fo.draw(Control)
warmer = Rectangle(Point(215, 130), Point(265, 180))
warmer.draw(Control)
19. global te
global Speed
global spe
blah = Control.checkMouse()
if blah != None:
x = blah.getX()
y = blah.getY()
if (35 <= x <= 85) and (130 <= y <= 180):#make it faster
and change speed
if a > 0.05:
a -= 0.05
Speed = int(spe.getText()) + 1
spe.setText(Speed)
return a
if (95 <= x <= 145) and (130 <= y <= 180):
if(flagStart==True):
flagStart =False
return(a)
else:
file = open('simData.txt', 'w+')
file.write(str(win))
file.write(str(te))
file.write(str(a))
sim = Text(Point(120, 53), "Simulation Data Saved")
sim.draw(win)
flagStart =True
win.getMouse() #pause works correctly
elif (35 <= x <= 85) and (20 <= y <= 70):#make it slower
and change speed
a += 0.05
Speed = int(spe.getText()) - 1
spe.setText(Speed)
return a
if (155 <= x <= 205) and (130 <= y <= 180):#food
i = random.randint(5, 494)
20. c = random.randint(5, 494)
rec = Rectangle(Point(i, c), Point(i + 5, c + 5))
rec.setFill('black')
rec.draw(win)
if (215 <= x <= 265) and (130 <= y <= 180):#warmer
temperature = int(te.getText()) + 1
te.setText(temperature)
elif (215 <= x <= 265) and (20 <= y <= 180):#cooler
temperature = int(te.getText()) - 1
te.setText(temperature)
return(a)
def makeCrete():
mylist = []
for x in range(random.randint(5, 12)):
i = Circle(Point(random.randint(50, 451),
random.randint(50, 451)), 8)
i.setFill('green')
i.setOutline('green')
mylist.append(i)
return mylist
def makeLaelaps():
mylist2 = []
for y in range(random.randint(3, 6)):
p = Circle(Point(random.randint(100, 401),
random.randint(100, 401)), 16)
p.setFill('red')
p.setOutline('red')
laelist = [p, random.choice([-12, -10, -8, 8, 10, 12]),
random.choice([-12, -10, -8, 8, 10, 12])]
mylist2.append(laelist)
return mylist2
def bounce(int1, int2):
21. if int1 < 15 or int1 > 485:
return ((-1) * int2)
else:
return(int2)
def main():
Speedr = 0.25
Controlpanel()
mylist2 = makeLaelaps()
mylist = makeCrete()
for x in mylist:
x.draw(win)
for j in range(len(mylist2)):#must do range(len(mylist2)) or
they will move in a staggered way (like the Crete cells)
mylist2[j][0].draw(win)
while win.checkMouse()== None:
Speedr = checkbutton(Speedr)
time.sleep(Speedr)
# make laelaps bounce off of crete
for x in mylist:
for j in range(len(mylist2)):
pop = (x.getCenter().getX()) -
(mylist2[j][0].getCenter().getX())
crackle = (x.getCenter().getY()) -
(mylist2[j][0].getCenter().getY())
c = 28
if((pop**2) + (crackle**2) < (c**2)):
mylist2[j][1] *= (-1)
mylist2[j][2] *= (-1)
#make crete bounce off each other
for x in mylist:
pop = (x.getCenter().getX())
crackle = (x.getCenter().getY())
c = 16
22. if abs((pop**2) + (crackle**2) < (c**2)):
x.move(bounce((x.getCenter().getX()),
random.choice([-20, 20])), bounce((x.getCenter().getY()),
random.choice([-20, 20])))
#make laelaps bounce off each other
for j in range(len(mylist2)):
pop = (mylist2[j][0].getCenter().getX())
crackle = (mylist2[j][0].getCenter().getY())
c = 36
if abs((pop**2) + (crackle**2) < (c**2)):
mylist2[j][1] *= (-1) #have to redefine this or else it
will not move in a straight line
mylist2[j][2] *= (-1)
#makes crete cells bounce in separate directions
for x in mylist:
x.move(bounce((x.getCenter().getX()), random.randint(-
6, 6)), bounce((x.getCenter().getY()), random.randint(-6, 6)))
#laelaps bounce in separate directions
for j in range(len(mylist2)):
mylist2[j][1] = bounce(mylist2[j][0].getCenter().getX(),
mylist2[j][1])
mylist2[j][2] = bounce(mylist2[j][0].getCenter().getY(),
mylist2[j][2])
mylist2[j][0].move(mylist2[j][1], mylist2[j][2])
Control.close()
win.close()
print("This simulation has terminated!!!! Yay!!!! :) ")
main()