Graphics help...

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Sep 2007
Posts: 4
Reputation: Roadphantom13 is an unknown quantity at this point 
Solved Threads: 0
Roadphantom13 Roadphantom13 is offline Offline
Newbie Poster

Graphics help...

 
0
  #1
Oct 4th, 2007
Hey everyone. Noob poster here so bear with me. So the code below makes a drawing of a face move around the graphics window. However, the face is noseless. My dilema is that I absolutely can't figure out how to add a nose to the face and have it move around with the face as well. As far as I know, there is no way to create a triangle, only a polygon but a polygon requires specific coordinates to create it. How do I make a triangle nose for this guy, writing code in relation to the face and not using general coordinates? If any of what I said made sense... Also, I tried to write some code to do this, and the code that I did is currently set as a note. Any help would be appreciated. No need for a straight anwer if you don't want, just something to help get me moving. Thanks all.
  1. from graphics import *
  2. import time
  3.  
  4. def moveAll(shapeList, dx, dy):
  5.  
  6. for shape in shapeList:
  7. shape.move(dx, dy)
  8.  
  9. def moveAllOnLine(shapeList, dx, dy, repetitions, delay):
  10.  
  11.  
  12. for i in range(repetitions):
  13. moveAll(shapeList, dx, dy)
  14. time.sleep(delay)
  15.  
  16. def makeFace(center, win):
  17.  
  18.  
  19. head = Circle(center, 25)
  20. head.setFill("yellow")
  21. head.draw(win)
  22.  
  23. eye1Center = center.clone()
  24. eye1Center.move(-10, 5)
  25. eye1 = Circle(eye1Center, 5)
  26. eye1.setFill('blue')
  27. eye1.draw(win)
  28.  
  29. eye2End1 = eye1Center.clone()
  30. eye2End1.move(15, 0)
  31. eye2End2 = eye2End1.clone()
  32. eye2End2.move(10, 0)
  33. eye2 = Line(eye2End1, eye2End2)
  34. eye2.setWidth(3)
  35. eye2.draw(win)
  36.  
  37.  
  38.  
  39. # noseTop = center.clone()
  40. # noseTop.move(0,0)
  41. # noseLeft = noseTop.clone()
  42. # noseLeft.move(-5,-5)
  43. # noseRight = noseLeft.cone()
  44. # noseRight.move(10,0)
  45. # nose = Polygon(noseTop,noseLeft,noseRight)
  46. # nose.draw(win)
  47.  
  48.  
  49.  
  50. mouthCorner1 = center.clone()
  51. mouthCorner1.move(-10, -10)
  52. mouthCorner2 = mouthCorner1.clone()
  53. mouthCorner2.move(20, -5)
  54. mouth = Oval(mouthCorner1, mouthCorner2)
  55. mouth.setFill("red")
  56. mouth.draw(win)
  57.  
  58. return [head, eye1, eye2, mouth]
  59.  
  60. def main():
  61. winWidth = 300
  62. winHeight = 300
  63. win = GraphWin('Back and Forth', winWidth, winHeight)
  64. win.setCoords(0, 0, winWidth, winHeight) # make right side up coordinates!
  65.  
  66. rect = Rectangle(Point(200, 90), Point(220, 100))
  67. rect.setFill("blue")
  68. rect.draw(win)
  69.  
  70. faceList = makeFace(Point(40, 100), win) #NEW
  71. faceList2 = makeFace(Point(150,125), win) #NEW
  72.  
  73. stepsAcross = 46 #NEW section
  74. dx = 5
  75. dy = 3
  76. wait = .05
  77. offScreenJump = winWidth*2
  78. for i in range(3):
  79. moveAllOnLine(faceList, dx, 0, stepsAcross, wait)
  80. moveAll(faceList2, offScreenJump, 0) # face 2 jumps off the screen
  81.  
  82. moveAllOnLine(faceList, -dx, dy, stepsAcross/2, wait)
  83. moveAll(faceList2, -offScreenJump, 0) # face 2 jumps back on screen
  84. moveAllOnLine(faceList, -dx, -dy, stepsAcross/2, wait)
  85.  
  86. Text(Point(winWidth/2, 20), 'Click anywhere to quit.').draw(win)
  87. win.getMouse()
  88. win.close()
  89.  
  90. main()
Last edited by Roadphantom13; Oct 4th, 2007 at 10:40 pm. Reason: I figure something out
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,113
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 944
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Graphics help...

 
0
  #2
Oct 5th, 2007
I am not familiar with this old graphics module, but generally you draw the face inside a rectangle/frame/canvas and move the whole rectangle/frame/canvas around.
Last edited by vegaseat; Oct 5th, 2007 at 10:17 pm.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC