Title: EECS 110: Lec 16: Projects
1EECS 110 Lec 16 Projects
- Aleksandar Kuzmanovic
- Northwestern University
http//cs.northwestern.edu/akuzma/classes/EECS110
-s09/
2The Rest of the Class
the view from here
Wed., 5/27 final projects review
Fri., 5/29 project recitations by TAs (G15)
(10am)
Fri., 5/29 project recitations (Wilkinson Lab)
(1-4pm)
Sun., 5/31 Interim milestones due (1159pm)
Mon., 6/1 review for Final Exam
Tue., 6/2 project recitations (Wilkinson Lab)
(9-12)
Wed., 6/3 Final Exam
Fri., 6/5 Final exam solutions (G15) (10am)
Fri., 6/5 Final projects due (5pm)
3EECS 110 today
- Today in EECS 110
- All about the EECS 110 projects!
vPool Text Clouds pyRobot picobot
4Final projects
open-ended
Final assignment
comprehensive
more choice
Working solo or duo is OK
Pairs need to share the work equally and together
5Option 1, vPool
Cue ball
Table
Billiard Ball (at least 2)
Cue (optional)
Hole (optional)
6Option 1 virtual pool
Easily installable for windows
VPython?
Not (really) installable for the Mac
www.vpython.org
A simple example
from visual import c cylinder()
What's visual? What's c?
7Option 1 virtual pool
How many classes? How many objects? data members?
from visual import floor box( pos(0,0,0),
length4, height0.5, width4,
colorcolor.blue) ball sphere( pos(0,4,0),
radius1, colorcolor.red) ball.velocity
vector(0,-1,0) dt 0.01 while True
rate(100) ball.pos ball.pos
ball.velocitydt if ball.y lt ball.radius
ball.velocity.y -ball.velocity.y
else ball.velocity.y ball.velocity.y -
9.8dt
What's the if/else doing?
8Option 1 virtual pool
Phunky Fisicks is welcome!
Collisions with walls? Collisions with other pool
balls? Pockets?
9Option 1 virtual pool
To start, just design your table, try to
construct a scene which consists of the following
objects - table made of walls, box
objects - holes (optional) use sphere
objects - cueBall another sphere -cue
(optional) cylinder object - billiard balls
(at least 2) sphere objects - you also should
take a look at label objects to display game
texts After you place all the objects you should
have something similar to
10Option 1 virtual pool
11Option 1 virtual pool
Your main game loop should basically consist
of while gameOver False m
scene.mouse.getclick() click event cue hit
get mouse position and give the cue ball a
direction based on that perform
movement of the cue ball as shown before
handle collisions between different balls and
between balls and walls check if game
is over when all balls have been put in
12Option 1 virtual pool
Directing the cue ball temp
scene.mouse.project(normal(0,1,0),
point(0,-side,0)) this gets a vector with
the projection of the mouse on the pool table.
if temp temp is None if no intersection with
pool table cueBall.p norm(temp
cueBall.pos) The cue ball direction is now given
by the vector that results from the difference of
the point where we clicked projected on the pool
table and the actual position of the cue ball
So clicking in front of the cue ball will make
it go into that direction.
13Option 1 virtual pool
Moving the cue ball dt 0.5 t 0.0 while dt gt
0.1 sleep(.01) t t dt
dt dt-dt/200.0 cueBall.pos
cueBall.pos (cueBall.p/cueBall.mass)dt We
basically start with a bigger movement increment
(0.5), move the ball in the direction we computed
with the specific increment. Each time decrease
the increment to account for drop in velocity.
Stop at some point (0.1)
14Option 1 virtual pool
Handling collisions With walls if not (side
gt cueBall.x gt -side) cueBall.p.x
-cueBall.p.x if not (side gt cueBall.z gt -side)
cueBall.p.z -cueBall.p.z When hitting
wall, change directions
15Option 1 virtual pool
When is a ball in? if math.sqrt(math.pow(abs(ball
1.x-hole1.x),2) math.pow(abs(ball1.z-hole1.z),2)
) lt hole1.radius2 ballin 1
ball1.visible 0 ball1.y
50 Holes are just spheres so we determine
intersection between ball and hole same way as
for different balls. When ball is in we do a
few things Signal that a ball has been put in
(might be useful later) Make the specific ball
invisible Move it out of the way
16Option 1 virtual pool
- Handling the game logic?
- Need a way to keep track of players taking
turns. - Suggestion use a simple variable for that which
changes after every hit (take into account if
balls have been sunk or not) - Players need to be aware of the game flow, so
show labels that display which player has turn,
when the game was won and by whom - The game is finished when all the balls are in,
that is when all the balls are invisible. You can
use that for check.
17Project 2 text clouds
tag cloud
18Project 2 text clouds
text cloud
Summary of the words in a body of text, sized and
painted according to their frequency.
Demos http//www.cs.hmc.edu/hadas/textclouds/
or http//blue.cs.northwestern.edu/ionut/index.ht
ml on http//www.gutenberg.org/files/74/74-h/74-
h.htm http//www.gutenberg.org/files/76/76-h/76-h
.htm
19Text-cloud history
http//chir.ag/phernalia/preztags/
20Project 2 text clouds
From text
- Start with entered webpage (URL)
- Read in text
- Create list of words out of text
- "Clean" the words
- "Stem" the words
- Count the words
- Return a string with frequencies
- Add advanced features
to cloud
21Text Clouds, an example
http//cs.northwestern.edu/akuzma/classes/EECS110
-s09/projects/ project2/page1.html
ignore this link for now
Spamming spammers spammed spam. Spam spam spam! I
love spam! Page 2
'spamming', 'spammers', spammed', 'spam.',
'spam', 'spam', 'spam!', 'I', 'love', 'spam!',
'page', '2'
'spamming', 'spammers', spammed', 'spam',
'spam', 'spam', 'spam', 'love', 'spam', 'page',
'2'
'spam', 'spam', spam', 'spam', 'spam', 'spam',
'spam', 'love', 'spam', 'page', '2'
22Project 2 text clouds
An Approach
Develop the basic application the usual way (IDLE)
Use our code to read HTML, but don't bother
writing it yet
Once you have things working, try writing
HTML/searching beyond depth 1/etc (NEXT SLIDE)
Once you have everything working, transfer your
.py files to your webspace. Set up the HTML
wrapper files go!
Personalize! The project has a number of
references
23Project 2 searching beyond depth 1
An Approach (1/2)
def mtcURL(url) toVisiturl 0 toVisit is
a dictionary visitedurl 1 visited is a
dictionary returnText '' while
len(toVisit) ! 0 url, depth
toVisit.popitem() textSite, listUrls
getHTML(url)
24Project 2 searching beyond depth 1
An Approach (2/2)
for urlItem in listUrls if
visited.has_key(urlItem) False \ and depth
lt DEPTH visitedurlItem 1
toVisiturlItem depth 1 wordList
textSite.split()
25pyRobot option 3
Pt A
2d Roomba simulator
Goal get from Pt A to Pt B
Pt B
26pyRobot option 3
IMPORTANT ROBOT CAN START ANYWHERE!
Pt A
Pt B
IMPORTANT GOAL CAN BE ANYWHERE
27Project 3 pyRobot
while True
SENSE
x,y,thd, bump self.getData()
28Project 3 pyRobot
Robot control continuously runs three things
while True
SENSE
PLAN
x,y,thd, bump self.getData()
if bump0 True or bump1 True print
'BUMP!', print ' Left bump sensor',
bump0, ' ', print ' Right bump
sensor', bump1, ' ' robotTask STOP
STOP is one of the robot's states. Every 40th of
a second, the robot runs through this loop, sets
the robot's state and sets the velocities
accordingly. Don't sleep!
29Project 3 pyRobot
Robot control continuously runs three things
while True
SENSE
PLAN
ACT
x,y,thd, bump self.getData()
if bump0 True or bump1 True print
'BUMP!', print ' Left bump sensor',
bump0, ' ', print ' Right bump
sensor', bump1, ' ' robotTask STOP
STOP is one of the robot's states. Every 40th of
a second, the robot runs through this loop, sets
the robot's state and sets the velocities
accordingly. Don't sleep!
if robotTask STOP self.setVels(0,0)
robotTask KBD
30Project 3 pyRobot
BASIC ROBOT COMMANDS
STOP self.setVels(0,0) GO FORWARD self.setVels(
FV,0) GO BACKWARD self.setVels(-FV,0) GO
CLOCKWISE self.setVels(0,RV) GO
COUNTERCLOCKWISE self.setVels(0,-RV)
31Project 3 pyRobot
To make the robot go forward a set amount use The
max forward velocity FV
Example... TIME_ONE_CIRCLE_OVER RADIUS2 / FV
if stateDO_GO_LEFT_LITTLE FIGURE OUT HOW TO
TRAVEL pause_stop time.time()
TIME_ONE_CIRCLE_OVER State
GOING_LEFT_LITTLE if pause_stop gt time.time()
and stateGOING_LEFT_LITTLE
self.setVels(0,0) STOP! elif stateGOING_LEFT_L
ITTLE self.setVels(FV,0) KEEP GOING!
32Project 3 pyRobot
To rotate the robot use the Max Rotational
Velocity RV
Example... TIME_ROTATE_90_DEGREES 90.0 / RV
if stateDO_ROTATE_LEFT_DOWN c-cwise FIGURE
OUT HOW LONG TO ROTATE pause_stop time.time()
TIME_ROTATE_90_DEGREES State
ROTATING_LEFT_DOWN if pause_stop gt time.time()
and stateROTATING_LEFT_DOWN
self.setVels(0,0) STOP! elif stateROTATING_DOW
N self.setVels(0,-RV) KEEP GOING!
33Project 3 pyRobot
One way to traverse the space is GO DOWN UNTIL
BUMP SOMETHING, GO RIGHT A LITTLE GO UP UNTIL
BUMP SOMETHINGGO RIGHT A LITTLE DO THIS UNTIL
HIT CORNER THEN REVERSE....
34Maps
are set at the very bottom of the main.py file
Required
We may test on any map with rectangular objects
35Project 4 Picobot Returns!
36Project 4 Picobot
Basic idea implement Picobot (the homework
problem from Week 1) Picobot is a finite-state
machine! Requirements
Graphical output Read Picobot program from a
file Read maze description from a file Track
visited/unvisited squares Prohibit illegal moves
37Reading a Picobot program from a file
map3.txt contains solution to the HW0
problem Syntax 0 xxxx -gt N 1 0 Nxxx -gt S
2 0 xExx -gt W 3 0 xxWx -gt E 4 0 xxxS -gt N
1 0 xEWx -gt N 1 ...
38Reading a Picobot program from a file
Importing map3.txt into the program
f open('map3.txt', 'r') text f.read() L
text.split() f.close() for i in range(len(L))
if Li '-gt' if Li-1 'xxxx' ETC
39Graphics Library
- Graphics22.py (recommended)
40Graphics Library
- Graphics22.py (recommended)
- You can use others as well
- E.g., vPython
41Plotting a window
- from graphics22 import
- def main()
- win GraphWin("MyWindow", 400, 400)
42Plotting a yellow rectangle
- from graphics22 import
- def main()
- win GraphWin("MyWindow", 400, 400)
- p1 Point(0,355)
- p2 Point(400,400)
- rec1 Rectangle(p1,p2)
- rec1.setFill("yellow)
- rec1.setOutline("yellow")
- rec1.draw(win)
43Plotting an Exit button
-
- Exit button
- p1 Point(122,360)
- p2 Point(198,390)
- square1 Rectangle(p1,p2)
- square1.setFill("gray")
- square1.draw(win)
- p square1.getCenter()
- t Text(p, "Exit")
- t.draw(win)
44Accepting a mouse click
-
- loop
- while True
- K win.getMouse()
- if K.getX() gt 122 and \
- K.getX() lt 198 and \
- K.getY() gt 360 and \
- K.getY() lt 390
- win.close()
- exit("The end)
45Accepting a mouse click
-
- loop
- while True
- K win.getMouse()
- if K.getX() gt 122 and \
- K.getX() lt 198 and \
- K.getY() gt 360 and \
- K.getY() lt 390
- win.close()
- exit("The end)
46Example Functions
- createOneRow( n )
- createBoard(width, height)
- done(X) end of game all visited in matrix X
- next_state(Cstate,Icurr,Jcurr,X,STATE)
- next_direction(Cstate,Icurr,Jcurr,X,DIRECTION)
- main(nameOfFile)
47Whats due?
Sun., 5/31 Interim milestones due (1159 pm)
milestone.txt
milestone.py
- Name(s)
- Project chosen
- Description of User Interface
- What is your approach plan?
- Classes and functions with docstrings
- 60-80 lines of working, tested code
48Whats due?
Fri., 6/5 Final projects due (500 pm)
final.txt
final.py
- Name(s)
- Project chosen
- Description of User Interface
- How do we run / play your project?
- What features did you implement?
- What was your approach plan?
- Classes and functions with docstrings
- Working, tested code
A final milestone
49This and next week
Wed., 5/27 final projects review
Fri., 5/29 project recitations by TAs (G15)
(10am)
Fri., 5/29 project recitations (Wilkinson Lab)
(1-4pm)
Sun., 5/31 Interim milestones due (1159pm)
Mon., 6/1 review for Final Exam
Tue., 6/2 project recitations (Wilkinson Lab)
(9-12)
Wed., 6/3 Final Exam
Fri., 6/5 Final exam solutions (G15) (10am)
Fri., 6/5 Final projects due (5pm)
50Be inventive we will reward that! Ask TAs for
help Good luck with the projects!