Dancing Man – Rick Roll
This was the very first “long” program that I wrote. It incorporates math modules, random modules, a graphics module (a tkinter spin off provided by Zelle) and functions. This was a little bit of extra credit I did during the semester. I am sure that there are plenty of short cuts that I could have used and some of my code may be obsolete, but considering it’s my very first complicated program, I figure its all good. I also wanted to show it off to people that would understand the fundamentals behind it. To a normal person, it’s just a dancing stick figure. To me, it’s 3 long nights of straight work and 5 pages worth of code. I submitted it with the Rick Ashley song in the background for fun effect. Enjoy!
Click here for The final Product with the Rick Roll song
from graphics import * from time import * from random import * def drawMan(center, size, moverr, moverl, moverLL, moverRL, window): bodyLength = size * 3 topllx = 225 botllx = 190 toplrx = 275 botlrx = 310 topy = 435 boty = 470 end = Point(center.getX(), center.getY() + bodyLength) leftLTop = Line(end, Point(topllx + moverLL ,topy + moverLL)) llbpt = leftLTop.getP2() llbptx = llbpt.getX() llbpty = llbpt.getY() leftLBot = Line(Point(llbptx,llbpty), Point(botllx + moverLL * 3 ,boty + moverLL * 3)) rightLTop = Line(end, Point(toplrx + moverRL,topy + moverRL)) rlbpt = rightLTop.getP2() rlbptx = rlbpt.getX() rlbpty = rlbpt.getY() rightLBot = Line(Point(rlbptx,rlbpty), Point(botlrx + moverRL * 3,boty + moverRL * 3)) toplx = 220 consty = 325 botlx = 190 toprx = 280 botrx = 310 mid = Point((center.getX()+center.getX())//2, (center.getY() + (center.getY()+bodyLength))//2) leftTop = Line(mid, Point(toplx, consty)) lbpt = leftTop.getP2() lbptx = lbpt.getX() lbpty = lbpt.getY() leftBot = Line(Point(lbptx,lbpty), Point(botlx + moverl * 2,consty + moverl * 2)) varleft = leftBot.getP1() rightTop = Line(mid, Point(toprx + moverr,consty + moverr)) rbpt = rightTop.getP2() rbptx = rbpt.getX() rbpty = rbpt.getY() rightBot = Line(Point(rbptx,rbpty), Point(botrx + moverr * 2,consty + moverr * 2)) eyeSize = 0.15 * size eyeOff = size / 3.0 mouthSize = 0.8 * size mouthOff = size / 2.0 head = Circle(center, size) head.setFill("yellow") leftEye = Circle(center, eyeSize) leftEye.move(-eyeOff, -eyeOff) rightEye = Circle(center, eyeSize) rightEye.move(eyeOff, -eyeOff) p1 = center.clone() mouth = Circle(p1, size/1.5) p2 = center.clone() p2.move(0,-10) mouth1 = Circle(p2, size/1.4) mouth1.setFill('yellow') mouth1.setOutline('yellow') bodyM = Line(Point(center.getX(),center.getY()), (Point(center.getX(), center.getY()+bodyLength))) bodyM.draw(window) head.draw(window) mouth.draw(window) mouth1.draw(window) leftEye.draw(window) rightEye.draw(window) leftTop.draw(window) leftBot.draw(window) rightTop.draw(window) rightBot.draw(window) leftLTop.draw(window) leftLBot.draw(window) rightLTop.draw(window) rightLBot.draw(window) sleep(0.2) leftLTop.undraw() leftLBot.undraw() rightLTop.undraw() rightLBot.undraw() leftTop.undraw() leftBot.undraw() rightTop.undraw() rightBot.undraw() head.undraw() bodyM.undraw() leftEye.undraw() rightEye.undraw() mouth.undraw() mouth1.undraw() def disco(window): filler = ['white', 'black', 'blue', 'purple', 'yellow', 'pink', 'green'] rand = randint(0,6) setFi = filler[rand] disco = Circle(Point(100,75), 50) disco1 = disco.clone() disco1.move(150,0) disco1.setFill(setFi) disco1.setOutline(setFi) disco2 = disco1.clone() disco2.move(150,0) disco2.setFill(setFi) disco2.setOutline(setFi) disco2.draw(window) disco1.draw(window) disco.draw(window) disco.setFill(setFi) disco.setOutline(setFi) def intervals(): rand = randint(0,5) rand1 = randint(0,1) nega = [1,-1] mover = rand * nega[rand1] return mover def faceMove(): rand = randint(0,5) rand1 = randint(0,1) nega = [1,-1] mover = rand * nega[rand1] return mover def main(): win = GraphWin("", 500, 500) bg1 = Rectangle(Point (0,0), Point(500, 500)) bg1.setFill('red') bg1.draw(win) center = Point(250, 250) size = 50 moverl = 0 moverr = 0 moverRL = 0 moverLL = 0 amoverl = 0 amoverr = 0 amoverRL = 0 amoverLL = 0 disco(win) while win.checkMouse() == None: center = Point(center.getX() + faceMove(), center.getY() + faceMove()) cgx = center.getX() cgy = center.getY() amoverl = amoverl + moverl amoverr = amoverr + moverr amoverRL = amoverRL + moverRL amoverLL = amoverLL + moverLL drawMan(center,size, moverr, moverl, moverLL, moverRL, win) moverl = intervals() moverr = intervals() moverRL = intervals() moverLL = intervals() if amoverl > 20: moverl = moverl * -1 if amoverRL > 20: moverRL = moverRL * -1 if amoverl < -20: moverl = moverl * -1 if amoverRL 20: moverr = moverr * -1 if amoverLL > 20: moverLL = moverLL * -1 if amoverr < -20: moverr = moverr * -1 if amoverLL < -20: moverLL = moverLL * -1 if cgy 260: center = Point(250,250) disco(win) if cgx < 240: center = Point(250,250) disco(win) win.getMouse() win.close() main()