EECS 110 Lec 16 Projects Aleksandar Kuzmanovic Northwestern

  • Slides: 50
Download presentation
EECS 110: Lec 16: Projects Aleksandar Kuzmanovic Northwestern University http: //networks. cs. northwestern. edu/EECS

EECS 110: Lec 16: Projects Aleksandar Kuzmanovic Northwestern University http: //networks. cs. northwestern. edu/EECS 110 -s 18/

The Rest of the Class… the view from here… project recitations by TAs (10

The Rest of the Class… the view from here… project recitations by TAs (10 am) Fri. , 6/1 – project recitations (Wilkinson Lab) (1 -3 pm) Fri. , 6/1 – Interim milestones due (11: 59 pm) Mon. , 6/4 – review for Final Exam Tue. , 6/5 – project recitations (Wilkinson Lab) (9 -12) Wed. , 6/6 – Final Exam Fri. , 6/8 – Final exam solutions (10 am) Sun. , 6/3 – Sun. , 6/10 – Final projects due (11: 59 pm)

EECS 110 today… Today in EECS 110 • All about the EECS 110 projects!

EECS 110 today… Today in EECS 110 • All about the EECS 110 projects! v. Pool Text Clouds py. Robot picobot

Final projects open-ended Final assignment comprehensive more choice… Working solo or duo is OK

Final projects open-ended Final assignment comprehensive more choice… Working solo or duo is OK Pairs need to share the work equally and together

Option #1, v. Pool Table Cue ball Billiard Ball (at least 2) Cue (optional)

Option #1, v. Pool Table Cue ball Billiard Ball (at least 2) Cue (optional) Hole (optional)

Option #1: virtual pool VPython? Easily installable for windows… Not (really) installable for the

Option #1: virtual pool VPython? Easily installable for windows… Not (really) installable for the Mac www. vpython. org A simple example from visual import * c = cylinder() What's visual? What's c?

Option #1: virtual pool from visual import * floor = box( pos=(0, 0, 0),

Option #1: virtual pool from visual import * floor = box( pos=(0, 0, 0), length=4, height=0. 5, width=4, color=color. blue) How many classes? How many objects? data members? ball = sphere( pos=(0, 4, 0), radius=1, color=color. red) ball. velocity = vector(0, -1, 0) dt = 0. 01 while True: rate(100) ball. pos = ball. pos + ball. velocity*dt if ball. y < ball. radius: ball. velocity. y = -ball. velocity. y else: ball. velocity. y = ball. velocity. y - 9. 8*dt What's the if/else doing?

Option #1: virtual pool Phunky Fisicks is welcome! Collisions with walls? Collisions with other

Option #1: virtual pool Phunky Fisicks is welcome! Collisions with walls? Collisions with other pool balls? Pockets?

Option #1: virtual pool To start, just design your table, try to construct a

Option #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 - cue. Ball – 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 …

Option #1: virtual pool

Option #1: virtual pool

Option #1: virtual pool Your main game loop should basically consist of: while game.

Option #1: virtual pool Your main game loop should basically consist of: while game. Over == 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

Option #1: virtual pool Directing the cue ball: temp = scene. mouse. project(normal=(0, 1,

Option #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 cue. Ball. p = norm(temp – cue. Ball. 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.

Option #1: virtual pool Moving the cue ball: dt = 0. 5 t =

Option #1: virtual pool Moving the cue ball: dt = 0. 5 t = 0. 0 while dt > 0. 1: sleep(. 01) t = t + dt dt = dt-dt/200. 0 cue. Ball. pos = cue. Ball. pos + (cue. Ball. p/cue. Ball. 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)

Option #1: virtual pool Handling collisions: With walls: if not (side > cue. Ball.

Option #1: virtual pool Handling collisions: With walls: if not (side > cue. Ball. x > -side): cue. Ball. p. x = -cue. Ball. p. x if not (side > cue. Ball. z > -side): cue. Ball. p. z = -cue. Ball. p. z When hitting wall, change directions

Option #1: virtual pool When is a ball in? if math. sqrt(math. pow(abs(ball 1.

Option #1: virtual pool When is a ball in? if math. sqrt(math. pow(abs(ball 1. x-hole 1. x), 2) + math. pow(abs(ball 1. z-hole 1. z), 2)) <= hole 1. radius*2: ballin = 1 ball 1. visible = 0 ball 1. 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

Option #1: virtual pool Handling the game logic? • Need a way to keep

Option #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.

Project #2: text clouds tag cloud

Project #2: text clouds tag cloud

Project #2: text clouds text cloud Summary of the words in a body of

Project #2: text clouds text cloud Summary of the words in a body of text, sized and painted according to their frequency. Demo: http: //blue. cs. northwestern. edu/~ionut/index. html on: http: //www. gutenberg. org/files/74/74 -h. htm http: //www. gutenberg. org/files/76/76 -h. htm

Text-cloud history http: //chir. ag/phernalia/preztags/

Text-cloud history http: //chir. ag/phernalia/preztags/

Project #2: text clouds From text… 1. Start with entered webpage (URL) 2. Read

Project #2: text clouds From text… 1. Start with entered webpage (URL) 2. Read in text 3. Create list of words out of text 4. "Clean" the words 5. "Stem" the words 6. Count the words 7. Return a string with frequencies 8. Add advanced features… … to cloud

Text Clouds, an example http: //networks. cs. northwestern. edu/EECS 110 -s 18/projects/ project 2/page

Text Clouds, an example http: //networks. cs. northwestern. edu/EECS 110 -s 18/projects/ project 2/page 1. htm ignore this link for now Spamming spammers spammed spam. Spam spam! I love spam! Page 2 ['spamming', 'spammers', spammed', 'spam', 'spam!', 'I', 'love', 'spam!', 'page', '2'] ['spamming', 'spammers', spammed', 'spam', 'love', 'spam', 'page', '2'] ['spam', 'spam', 'love', 'spam', 'page', '2']

Project #2: text clouds An Approach Develop the basic application the usual way (IDLE)

Project #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…

Project #2: searching beyond depth 1 An Approach (1/2) def mtc. URL(url): to. Visit[url]

Project #2: searching beyond depth 1 An Approach (1/2) def mtc. URL(url): to. Visit[url] = 0 #to. Visit is a dictionary visited[url] = 1 #visited is a dictionary return. Text = '' while len(to. Visit) != 0: [url, depth] = to. Visit. popitem() [text. Site, list. Urls] = get. HTML(url)

Project #2: searching beyond depth 1 An Approach (2/2) … for url. Item in

Project #2: searching beyond depth 1 An Approach (2/2) … for url. Item in list. Urls: if visited. has_key(url. Item) == False and depth < DEPTH: visited[url. Item] = 1 to. Visit[url. Item] = depth + 1 word. List = text. Site. split() …

py. Robot option #3 Pt A 2 d Roomba simulator Pt B Goal: get

py. Robot option #3 Pt A 2 d Roomba simulator Pt B Goal: get from Pt A to Pt B

py. Robot Pt A option #3 IMPORTANT: ROBOT CAN START ANYWHERE! Pt B IMPORTANT:

py. Robot Pt A option #3 IMPORTANT: ROBOT CAN START ANYWHERE! Pt B IMPORTANT: GOAL CAN BE ANYWHERE

Project #3: while True: SENSE [x, y, thd], bump = self. get. Data() py.

Project #3: while True: SENSE [x, y, thd], bump = self. get. Data() py. Robot

Project #3: while True: SENSE py. Robot control continuously runs three things: PLAN [x,

Project #3: while True: SENSE py. Robot control continuously runs three things: PLAN [x, y, thd], bump = self. get. Data() if bump[0] == True or bump[1] == True: print 'BUMP!', print ' [Left bump sensor: ', bump[0], '] print ' [Right bump sensor: ', bump[1], '] robot. Task = STOP is one of the robot's states. Every 40 th of a second, the robot runs through this loop, sets the robot's state and sets the velocities accordingly. Don't sleep! ', '

Project #3: while True: SENSE py. Robot control continuously runs three things: PLAN ACT

Project #3: while True: SENSE py. Robot control continuously runs three things: PLAN ACT [x, y, thd], bump = self. get. Data() if bump[0] == True or bump[1] == True: print('BUMP!’) print(' [Left bump sensor: ', bump[0], '] print(' [Right bump sensor: ', bump[1], '] robot. Task = STOP is one of the robot's states. Every 40 th of a second, the robot runs through this loop, sets the robot's state and sets the velocities accordingly. Don't sleep! if robot. Task == STOP: self. set. Vels(0, 0) robot. Task = KBD ‘) ’)

Project #3: BASIC ROBOT COMMANDS: STOP: self. set. Vels(0, 0) GO FORWARD: self. set.

Project #3: BASIC ROBOT COMMANDS: STOP: self. set. Vels(0, 0) GO FORWARD: self. set. Vels(FV, 0) GO BACKWARD: self. set. Vels(-FV, 0) GO CLOCKWISE: self. set. Vels(0, RV) GO COUNTERCLOCKWISE: self. set. Vels(0, -RV) py. Robot

Project #3: py. Robot To make the robot go forward a set amount use

Project #3: py. Robot To make the robot go forward a set amount use The max forward velocity: FV Example. . . TIME_ONE_CIRCLE_OVER = RADIUS*2 / FV if state==DO_GO_LEFT_LITTLE: #FIGURE OUT HOW TO TRAVEL pause_stop = time() + TIME_ONE_CIRCLE_OVER State = GOING_LEFT_LITTLE if pause_stop > time() and state==GOING_LEFT_LITTLE: self. set. Vels(0, 0) #STOP! elif state==GOING_LEFT_LITTLE: self. set. Vels(FV, 0) #KEEP GOING!

Project #3: py. Robot To rotate the robot use the Max Rotational Velocity: RV

Project #3: py. Robot To rotate the robot use the Max Rotational Velocity: RV Example. . . TIME_ROTATE_90_DEGREES = 90. 0 / RV if state==DO_ROTATE_LEFT_DOWN: #c-cwise #FIGURE OUT HOW LONG TO ROTATE pause_stop = time() + TIME_ROTATE_90_DEGREES State = ROTATING_LEFT_DOWN if pause_stop > time() and state==ROTATING_LEFT_DOWN: self. set. Vels(0, 0) #STOP! elif state==ROTATING_LEFT_DOWN: self. set. Vels(0, -RV) #KEEP GOING!

Project #3: One way to traverse the space is GO DOWN UNTIL BUMP SOMETHING,

Project #3: One way to traverse the space is GO DOWN UNTIL BUMP SOMETHING, GO RIGHT A LITTLE GO UP UNTIL BUMP SOMETHING GO RIGHT A LITTLE DO THIS UNTIL HIT CORNER THEN REVERSE. . py. Robot

Maps are set at the very bottom of the main. py file: Required We

Maps are set at the very bottom of the main. py file: Required We may test on any map with rectangular objects

Project #4: Picobot Returns!

Project #4: Picobot Returns!

Project 4: Picobot Basic idea: implement Picobot (the homework problem from Week 1) Picobot

Project 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

Reading a Picobot program from a file map 3. txt contains solution to the

Reading a Picobot program from a file map 3. txt contains solution to the HW 0 problem Syntax: 0 xxxx -> N 1 0 Nxxx -> S 2 0 x. Exx -> W 3 0 xx. Wx -> E 4 0 xxx. S -> N 1 0 x. EWx -> N 1. . .

Reading a Picobot program from a file Importing map 3. txt into the program

Reading a Picobot program from a file Importing map 3. txt into the program f = open('map 3. txt', 'r') text = f. read() L = text. split() f. close() for i in range(len(L)): if L[i] == '->': if L[i-1] == 'xxxx': #ETC

Graphics Library • Graphics 22. py (recommended)

Graphics Library • Graphics 22. py (recommended)

Graphics Library • Graphics 22. py (recommended) • You can use others as well:

Graphics Library • Graphics 22. py (recommended) • You can use others as well: – E. g. , v. Python

Plotting a window from graphics 22 import * def main(): win = Graph. Win("My.

Plotting a window from graphics 22 import * def main(): win = Graph. Win("My. Window", 400)

Plotting a yellow rectangle from graphics 22 import * def main(): win = Graph.

Plotting a yellow rectangle from graphics 22 import * def main(): win = Graph. Win("My. Window", 400) p 1 = Point(0, 355) p 2 = Point(400, 400) rec 1 = Rectangle(p 1, p 2) rec 1. set. Fill("yellow“) rec 1. set. Outline("yellow") rec 1. draw(win)

Plotting an Exit button … #Exit button p 1 = Point(122, 360) p 2

Plotting an Exit button … #Exit button p 1 = Point(122, 360) p 2 = Point(198, 390) square 1 = Rectangle(p 1, p 2) square 1. set. Fill("gray") square 1. draw(win) p = square 1. get. Center() t = Text(p, "Exit") t. draw(win)

Accepting a mouse click … #loop while True: K = win. get. Mouse() if

Accepting a mouse click … #loop while True: K = win. get. Mouse() if K. get. X() > 122 and K. get. X() < 198 and K. get. Y() > 360 and K. get. Y() < 390: win. close() exit("The end“)

Accepting a mouse click … #loop while True: K = win. get. Mouse() if

Accepting a mouse click … #loop while True: K = win. get. Mouse() if K. get. X() > 122 and K. get. X() < 198 and K. get. Y() > 360 and K. get. Y() < 390: win. close() exit("The end“)

Example Functions create. One. Row( n ) create. Board(width, height) done(X) #end of game:

Example Functions create. One. Row( n ) create. Board(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(name. Of. File)

What’s due? Sun. , 6/3 – Interim milestones due (11: 59 pm) milestone. txt

What’s due? Sun. , 6/3 – Interim milestones due (11: 59 pm) milestone. txt – Name(s) – Project chosen – Description of User Interface What is your approach & plan? milestone. py – Classes and functions with docstrings – 60 -80+ lines of working, tested code

What’s due? Sun. , 6/10 – Final projects due (11: 59 pm) final. txt

What’s due? Sun. , 6/10 – Final projects due (11: 59 pm) final. txt final. py – Name(s) – Classes and functions with docstrings – Project chosen – Working, tested code – Description of User Interface How do we run / play your project? What features did you implement? What was your approach & plan? A final milestone

This and next week project recitations by TAs (10 am) Fri. , 6/1 –

This and next week project recitations by TAs (10 am) Fri. , 6/1 – project recitations (Wilkinson Lab) (1 -3 pm) Fri. , 6/1 – Interim milestones due (11: 59 pm) Mon. , 6/4 – review for Final Exam Tue. , 6/5 – project recitations (Wilkinson Lab) (9 -12) Wed. , 6/6 – Final Exam Fri. , 6/8 – Final exam solutions (10 am) Sun. , 6/3 – Sun. , 6/10 – Final projects due (11: 59 pm)

Be inventive – we will reward that! Ask TAs for help Good luck with

Be inventive – we will reward that! Ask TAs for help Good luck with the projects!