| | |
Graphics help...
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Sep 2007
Posts: 4
Reputation:
Solved Threads: 0
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.
Python Syntax (Toggle Plain Text)
from graphics import * import time def moveAll(shapeList, dx, dy): for shape in shapeList: shape.move(dx, dy) def moveAllOnLine(shapeList, dx, dy, repetitions, delay): for i in range(repetitions): moveAll(shapeList, dx, dy) time.sleep(delay) def makeFace(center, win): head = Circle(center, 25) head.setFill("yellow") head.draw(win) eye1Center = center.clone() eye1Center.move(-10, 5) eye1 = Circle(eye1Center, 5) eye1.setFill('blue') eye1.draw(win) eye2End1 = eye1Center.clone() eye2End1.move(15, 0) eye2End2 = eye2End1.clone() eye2End2.move(10, 0) eye2 = Line(eye2End1, eye2End2) eye2.setWidth(3) eye2.draw(win) # noseTop = center.clone() # noseTop.move(0,0) # noseLeft = noseTop.clone() # noseLeft.move(-5,-5) # noseRight = noseLeft.cone() # noseRight.move(10,0) # nose = Polygon(noseTop,noseLeft,noseRight) # nose.draw(win) mouthCorner1 = center.clone() mouthCorner1.move(-10, -10) mouthCorner2 = mouthCorner1.clone() mouthCorner2.move(20, -5) mouth = Oval(mouthCorner1, mouthCorner2) mouth.setFill("red") mouth.draw(win) return [head, eye1, eye2, mouth] def main(): winWidth = 300 winHeight = 300 win = GraphWin('Back and Forth', winWidth, winHeight) win.setCoords(0, 0, winWidth, winHeight) # make right side up coordinates! rect = Rectangle(Point(200, 90), Point(220, 100)) rect.setFill("blue") rect.draw(win) faceList = makeFace(Point(40, 100), win) #NEW faceList2 = makeFace(Point(150,125), win) #NEW stepsAcross = 46 #NEW section dx = 5 dy = 3 wait = .05 offScreenJump = winWidth*2 for i in range(3): moveAllOnLine(faceList, dx, 0, stepsAcross, wait) moveAll(faceList2, offScreenJump, 0) # face 2 jumps off the screen moveAllOnLine(faceList, -dx, dy, stepsAcross/2, wait) moveAll(faceList2, -offScreenJump, 0) # face 2 jumps back on screen moveAllOnLine(faceList, -dx, -dy, stepsAcross/2, wait) Text(Point(winWidth/2, 20), 'Click anywhere to quit.').draw(win) win.getMouse() win.close() main()
Last edited by Roadphantom13; Oct 4th, 2007 at 10:40 pm. Reason: I figure something out
![]() |
Similar Threads
- getting graphics into c++ (C++)
- Graphics cards question? (Monitors, Displays and Video Cards)
- Graphics T and L support (Monitors, Displays and Video Cards)
- XP and Graphics card problems (Windows NT / 2000 / XP)
- graphics card (Monitors, Displays and Video Cards)
- recommendations 4 a 3D graphics prog? (Graphics and Multimedia)
Other Threads in the Python Forum
- Previous Thread: Removing elements from a list in a loop
- Next Thread: Python bug??? Or just a stupid question?
| Thread Tools | Search this Thread |
Tag cloud for Python
ansi assignment avogadro backend beginner binary bluetooth character cmd code customdialog data decimals dictionary drive dynamic error examples excel exe file float format ftp function gnu graphics gui heads homework http ideas import input java leftmouse line linux list lists logging loop module mouse newb number numbers output parsing path pointer port prime program programming progressbar projects push py2exe pygame pyqt python random recursion recursive refresh schedule screensaverloopinactive script scrolledtext sqlite ssh statistics stdout string strings sudokusolver sum table terminal text thread threading time tkinter tlapse tricks tuple tutorial ubuntu unicode update urllib urllib2 variable wikipedia windows write wxpython xlib






