|
@@ -1,38 +1,84 @@
|
|
-#14.06.2018
|
|
|
|
|
|
+
|
|
#Linda Napieralski
|
|
#Linda Napieralski
|
|
#Andre Giesbrecht
|
|
#Andre Giesbrecht
|
|
#Alexa Tschernitschek
|
|
#Alexa Tschernitschek
|
|
|
|
|
|
#Modul importieren
|
|
#Modul importieren
|
|
import Tkinter as tk
|
|
import Tkinter as tk
|
|
-import turtle
|
|
|
|
|
|
+import turtle
|
|
|
|
+
|
|
|
|
+#Groesse des Fensters
|
|
|
|
+
|
|
|
|
+BREITE= 1024
|
|
|
|
+
|
|
|
|
+HOEHE = 756
|
|
|
|
+
|
|
|
|
+#global
|
|
|
|
+#global
|
|
|
|
+
|
|
|
|
+class Roboter(object):
|
|
|
|
+ def __init__(self, Hauptfenster, canvas, BREITE, HOEHE, Roboter_width, Farbe, Geschwindigkeit, start_x, start_y, tag):
|
|
|
|
+ self.width = BREITE
|
|
|
|
+ self.height = HOEHE
|
|
|
|
+ self.canvas = canvas
|
|
|
|
+ self.Geschwindigkeit = Geschwindigkeit
|
|
|
|
+ self.Richtung_x = 0.5
|
|
|
|
+ self.Richtung_y = 0.5
|
|
|
|
+ self.tag = tag
|
|
|
|
+ self.canvas.create_oval(start_x, start_y, start_x + Roboter_width, start_y + Roboter_width, fill=Farbe, tag=tag)
|
|
|
|
+
|
|
|
|
|
|
-#Hauptfenster erstellen
|
|
|
|
-Hauptfenster = tk.Tk()
|
|
|
|
-Hauptfenster.title ("Roboter") #Fenstertitel
|
|
|
|
-cv = tk.Canvas(Hauptfenster, width=600, height=600, background= "white") #canvas=Zeichenflaeche
|
|
|
|
-cv.pack(side = tk.LEFT) #Zeichenflaeche links positionieren
|
|
|
|
|
|
+ def fahren(self):
|
|
|
|
|
|
|
|
+ self.canvas.move(self.tag, self.Richtung_x, self.Richtung_y)
|
|
|
|
|
|
-#Turtle_Fenster = Rasenfenster (gruen) erzeugen
|
|
|
|
-t = turtle.RawTurtle(cv)
|
|
|
|
-screen = t.getscreen()
|
|
|
|
-screen.setworldcoordinates(0,0,400,400)
|
|
|
|
-screen.bgcolor("green") #Hintergrundfarbe gruen
|
|
|
|
|
|
+ position = self.canvas.coords(self.tag)
|
|
|
|
+ if position[0] == 0:
|
|
|
|
+ self.Richtung_x = 0.5 #Geschwindigkeit nach Kollision
|
|
|
|
+ if position[1] == 0:
|
|
|
|
+ self.Richtung_y = 0.5
|
|
|
|
+ if position[2] == self.width:
|
|
|
|
+ self.Richtung_x = -0.5
|
|
|
|
+ if position[3] == self.height:
|
|
|
|
+ self.Richtung_y = -0.5
|
|
|
|
+ self.canvas.after(self.Geschwindigkeit, self.fahren)
|
|
|
|
|
|
-#Frame auf der Rechten Seite
|
|
|
|
-frame= tk.Frame(Hauptfenster)
|
|
|
|
-frame.pack(side= tk.RIGHT, fill=tk.BOTH)
|
|
|
|
|
|
+ x0= position[0]
|
|
|
|
+ y0= position[1]
|
|
|
|
+ x1= position[2]
|
|
|
|
+ y1= position[3]
|
|
|
|
+ self.canvas.create_oval(x0, y0,x1, y1, fill="white")
|
|
|
|
|
|
-pointLabel = tk.Label(frame,width = 50, height= 10)
|
|
|
|
-pointLabel.pack()
|
|
|
|
|
|
+# def maehen(self):
|
|
|
|
+ # line1= self.canvas.create_line(self.Richtung_x,self.Richtung_y ,width=1, fill="#000")
|
|
|
|
+# self.canvas.move(self.tag, self.Richtung_x, self.Richtung_y)
|
|
|
|
|
|
-button= tk.Button(frame)
|
|
|
|
-button ["text"] = "Start"
|
|
|
|
-button ["background"] = "blue"
|
|
|
|
-button.pack()
|
|
|
|
|
|
+# position = self.canvas.coords(self.tag)
|
|
|
|
+# if position[0] == 0:
|
|
|
|
+# self.Richtung_x = 0.5 #Geschwindigkeit nach Kollision
|
|
|
|
+# if position[1] == 0:
|
|
|
|
+# self.Richtung_y = 0.5
|
|
|
|
+# if position[2] == self.width:
|
|
|
|
+# self.Richtung_x = -0.5
|
|
|
|
+# if position[3] == self.height:
|
|
|
|
+# self.Richtung_y = -0.5
|
|
|
|
+ # self.canvas.after(self.Geschwindigkeit, self.fahren)
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+Hauptfenster=tk.Tk()
|
|
|
|
+Hauptfenster.title("Maehroboter")
|
|
|
|
+Garten = tk.Canvas(Hauptfenster, bg='green', width=BREITE, height=HOEHE)
|
|
|
|
+Garten.pack()
|
|
|
|
+Roboter = Roboter(Hauptfenster, Garten, BREITE, HOEHE, 100, "Red", 2,20, 300,"Roboter")
|
|
|
|
+
|
|
|
|
+Roboter.fahren()
|
|
|
|
+#Roboter.maehen()
|
|
Hauptfenster.mainloop()
|
|
Hauptfenster.mainloop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|