EE149
/
FinalProject
Final Project files for mBed development.
Diff: user-gui.py
- Revision:
- 32:8b589710632b
- Parent:
- 29:459ff10d2a07
- Child:
- 36:f25de790ea0b
--- a/user-gui.py Tue Dec 09 21:18:07 2014 +0000 +++ b/user-gui.py Tue Dec 09 22:56:54 2014 +0000 @@ -1,5 +1,5 @@ #!/usr/bin/python -""""Paint program by Dave Michell. +"""" NOTE: A substantial portion of this code was taken from Dave Michell's example illustrating how to draw on a Python-generated canvas. All credit @@ -8,6 +8,8 @@ # Start origin header ######################## +Paint program by Dave Michell. + Subject: tkinter "paint" example From: Dave Mitchell <davem@magnet.com> To: python-list@cwi.nl @@ -219,12 +221,37 @@ prev_x = prev_s[0] if prev: output_list.append(prev) - for move in output_list: - x_coord = move.split()[0] - y_coord = move.split()[1] - cmd = move.split()[2] + x0 = 0 + y0 = 0 + f_output_list = list() + i = 0 + while i < len(output_list)-1: + line1 = output_list[i].split(' ') + line2 = output_list[i+1].split(' ') + x1 = int(line1[0]) + x2 = int(line2[0]) + y1 = int(line1[1]) + y2 = int(line2[1]) + if line1[2] == line2[2] and dist(x0,y0,x1,y1) <= 10\ + and dist(x1,y1,x2,y2) <= 10: + x0 = x2 + y0 = y2 + i += 2 + f_output_list.append("%d %d %s" % (x2,y2,line1[2])); + else: + x0 = x1 + y0 = y1 + f_output_list.append(output_list[i]) + i += 1 + f_output_list.append(output_list[len(output_list)-1]) + print output_list + print "--------------------------------------------" + print f_output_list - return output_list + return f_output_list + +def dist(x1,y1,x2,y2): + return ((x2-x1)**2 + (y2-y1)**2)**.5 def b1down(event): global b1