1 / 22

EECS 110 Projects 1&2

EECS 110 Projects 1&2. Ionut Trestian Northwestern University. Option #1, vPool. Cue ball. Table. Billiard Ball (at least 2). Cue (optional). Hole (optional). Option #1: virtual pool. Easily installable for windows…. VPython?. Not (really) installable for the Mac. www.vpython.org.

jabari
Download Presentation

EECS 110 Projects 1&2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EECS 110Projects 1&2 Ionut Trestian Northwestern University

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

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

  4. Option #1: virtual pool How many classes? How many objects? data members? from visual import * floor = box( pos=(0,0,0), length=4, height=0.5, width=4, color=color.blue) ball = sphere( pos=(0,4,0), radius=1, color=color.red) ball.velocity = vector(0,-1,0) dt = 0.01 whileTrue: 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?

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

  6. 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 - 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 …

  7. Option #1: virtual pool

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

  9. 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 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.

  10. 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 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)

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

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

  13. 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.

  14. Project #2: text clouds tag cloud

  15. Project #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.html on: http://www.gutenberg.org/files/74/74-h/74-h.htm http://www.gutenberg.org/files/76/76-h/76-h.htm

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

  17. Project #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

  18. Text 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']

  19. 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…

  20. Project #2: searching beyond depth 1 An Approach (1/2) def mtcURL(url): toVisit[url] = 0 #toVisit is a dictionary visited[url] = 1 #visited is a dictionary returnText = '' while len(toVisit) != 0: [url, depth] = toVisit.popitem() [textSite, listUrls] = getHTML(url)

  21. Project #2: searching beyond depth 1 An Approach (2/2) … for urlItem in listUrls: if visited.has_key(urlItem) == False \ and depth < DEPTH: visited[urlItem] = 1 toVisit[urlItem] = depth + 1 wordList = textSite.split() …

  22. Questions?

More Related