def play_test_case(radius, cat_angle, mouse_angle): m, c = make_test_case(radius, cat_angle, mouse_angle) s = m.statue tk = Tk() arena = Arena (tk, meter*10, meter*10) arena.add(s) arena.add(c) arena.add(m) arena.pack() tk.mainloop()
def rungame(catRadius, catAngle, mouseAngle): tk = Tk() # Create a Tk top-level widget arena = Arena(tk) # Create an Arena widget, arena arena.pack() # Tell arena to pack itself on screen # arena.add(Turtle(Vector(200,200), 0)) # Add a very simple, basic turtle # arena.add(WalkingTurtle(Vector(300,300), 90, 0.5, arena)) statue = Statue(Vector(300, 300)) arena.add(statue) mouse = Mouse(mouseAngle, statue) arena.add(mouse) catRadius = catRadius * scalar cat = Cat(catAngle, catRadius, mouse, statue, arena) arena.add(cat) tk.mainloop() # Enter the Tkinter event loop
def runGame(catRadius, catAngle, mouseAngle): """ Main function that organizes and runs the game. Creates statue, mouse, and cat and adds them to the area. """ tk = Tk() # Create a Tk top-level widget arena = Arena(tk) # Create an Arena widget, arena arena.pack() # Tell arena to pack itself on screen statueObj = Statue(Vector(200,200)) # Create statue at 200,200 arena.add(statueObj) # Add statue to arena mouseObj = Mouse(mouseAngle, statueObj) # Create mouse with statue passed as argument arena.add(mouseObj) # Add mouse to arena cat_radius_scaled = catRadius * scale_factor # Scale the radius of the cat to pixels catObj = Cat(catAngle, cat_radius_scaled, mouseObj) # Create cat with mouse passed as argument arena.add(catObj) # Add cat to arena arena.setLabels() # added (set labels to starting position) tk.mainloop() # Enter the Tkinter event loop
def runGame(catRadius, catAngle, mouseAngle): """ Main function that organizes and runs the game. Creates statue, mouse, and cat and adds them to the area. """ tk = Tk() # Create a Tk top-level widget arena = Arena(tk) # Create an Arena widget, arena arena.pack() # Tell arena to pack itself on screen statueObj = Statue(Vector(200, 200)) # Create statue at 200,200 arena.add(statueObj) # Add statue to arena mouseObj = Mouse(mouseAngle, statueObj) # Create mouse with statue passed as argument arena.add(mouseObj) # Add mouse to arena cat_radius_scaled = catRadius * scale_factor # Scale the radius of the cat to pixels catObj = Cat(catAngle, cat_radius_scaled, mouseObj) # Create cat with mouse passed as argument arena.add(catObj) # Add cat to arena arena.setLabels() # added (set labels to starting position) tk.mainloop() # Enter the Tkinter event loop
Created on Sun Nov 18 15:44:25 2018 @author: Morten """ from tkinter import * # Import everything from Tkinter from Arena import Arena # Import our Arena from Turtle import Turtle # Import our Turtle from Vector import * # Import everything from our Vector from Statue import Statue from Mouse import Mouse from Cat import Cat from globalVariables import * statueRadius = 1 statuePosition = Vector(200, 200) mouseAngle = -57.0 catAngle = 0.0 catRadius = 4.0 tk = Tk() # Create a Tk top-level widget arena = Arena(tk) # Create an Arena widget, arena arena.pack() # Tell arena to pack itself on screen s = Statue(statuePosition, statueRadius) # Add a turtle at (200,200) heading 0=up m = Mouse(statue=s, angle=mouseAngle, arena=arena) c = Cat(arena=arena, mouse=m, angle=catAngle, radius=catRadius) arena.add(s) arena.add(m) arena.add(c) tk.mainloop()
from Tkinter import * # Import everything from Tkinter from Arena import Arena # Import our Arena from Turtle import Turtle # Import our Turtle from Vector import * # Import everything from our Vector tk = Tk() # Create a Tk top-level widget arena = Arena(tk) # Create an Arena widget, arena arena.pack() # Tell arena to pack itself on screen arena.add(Turtle(Vector(200,200), 0)) # Add a very simple, basic turtle tk.mainloop() # Enter the Tkinter event loop
'''Listen to SCOP streams for commands and render some turtles.''' from Tkinter import * from Arena import Arena from WalkingTurtle import WalkingTurtle from Vector import * import scop import os scopserver = os.getenv("SCOPCTRLSERVER", "www.srcf.ucam.org") sock1 = scop.scop_open(scopserver, "viewp1") sock2 = scop.scop_open(scopserver, "viewp2") scop.scop_listen(sock1, "p1ctrl") scop.scop_listen(sock2, "p2ctrl") tk = Tk() arena = Arena(tk, sock1, sock2) arena.pack() arena.add(WalkingTurtle(Vector(200, 300), 0, 1, fill='turquoise')) arena.add(WalkingTurtle(Vector(600, 300), 0, 1, fill='purple')) tk.mainloop()
from Tkinter import * # Import everything from Tkinter from Arena import Arena # Import our Arena from Turtle import Turtle # Import our Turtle from Vector import * # Import everything from our Vector from WalkingTurtle import WalkingTurtle tk = Tk() # Create a Tk top-level widget arena = Arena(tk) # Create an Arena widget, arena arena.pack() # Tell arena to pack itself on screen arena.add(WalkingTurtle(Vector(200, 200), 0, 1)) # Add a very simple, basic turtle tk.mainloop() # Enter the Tkinter event loop
import Cat meter = 20 # How many pixels is one meter? statue_radius = 1# What is the statue's radius cat_radius = 1.5 cat_angle = 0 mouse_angle = 45 x = Vector() print x.length() tk = Tk() # Create a Tk top-level widget arena = Arena(tk) # Create an Arena widget, arena arena.pack() # Tell arena to pack itself on screen s = Statue(Vector(200,200),statue_radius,meter) arena.add(s) m = Mouse(s,mouse_angle) c = Cat.Cat(cat_angle,cat_radius,m) arena.add(c) arena.add(m) arena.cat_rad.set('CatRadius: '+str(cat_radius)) arena.cat_rad_label = Label(arena,textvariable=arena.cat_rad) arena.cat_rad_label.pack() arena.cat_ang.set('CatAngle: '+str(cat_angle)) arena.cat_ang_label = Label(arena,textvariable=arena.cat_ang) arena.cat_ang_label.pack() arena.mouse_ang.set('CatAngle: '+str(mouse_angle)) arena.mouse_ang_label = Label(arena,textvariable=arena.mouse_ang) arena.mouse_ang_label.pack()
from Tkinter import * # Import everything from Tkinter from Arena import Arena # Import our Arena from Cat import Cat # Import our Cat from Mouse import Mouse # Import our Statue from Statue import Statue # Import our Statue from Vector import * # Import everything from our Vector from globalVars import * # Import everything from globalVars from random import random # Import random tk = Tk() # Create a Tk top-level widget arena = Arena(tk, 800, 600, padx=12, pady=6) # Create an Arena widget, arena arena.pack() # Tell arena to pack itself on screen midX = arena.width/2 # Horizontal center of window midY = arena.height/2 # Vertical center of window mouseAngle = random()*360*scaleRad # Random mouse angle to initialize catAngle = random()*360*scaleRad # Random cat angle to initialize catRadius = 5 # Random cat radius to initialize statue = Statue(Vector(midX,midY), 0) # Create a statue in center of arena, arbitrary heading arena.add(statue) # Add statue mouse = Mouse(Vector(midX + statue.radius*scalePixel*cos(mouseAngle), midY - statue.radius*scalePixel*sin(mouseAngle)), 0, arena, statue) # Create a mouse at right edge of statue, arbitrary heading since it will be overwritten in initialization arena.add(mouse) # Add mouse cat = Cat(Vector(midX + catRadius*scalePixel*cos(catAngle), midY - catRadius*scalePixel*sin(catAngle)), 0, arena, statue, mouse) # Create a cat at given angle and radius, arbitrary heading since it will be overwritten in initialization arena.add(cat, "cat") # Add cat and specify that it's a cat as extra argument tk.mainloop() # Enter the Tkinter event loop
# we decide initial positions of cat and mouse relative to the random position of the statue initialCatRadius, initialMouseAngle, initialCatAngle = inputdata() # create mouse, statue and cat with initial conditions statue = Statue(initialStatPosition, initialStatPosition, 0, 0) mouse = Mouse2(initialStatPosition, initialStatPosition + 100 * unit(initialMouseAngle), initialMouseAngle - 90, 1, initialMouseAngle) cat = Cat(initialStatPosition, initialStatPosition + initialCatRadius * unit(initialCatAngle), initialCatAngle - 90, 1, initialMouseAngle, initialCatRadius, initialCatAngle) # add these fellas arena.add(statue) # Add a turtle at (200,200) heading 0=up arena.add(mouse) arena.add(cat) def aboutWidget(): top = Toplevel(menu=filemenu) top.title('About the UC Berkeley CS9H Turtle Arena') photo = PhotoImage(file='Joshua.gif') smallphoto = photo.subsample(15) photoLabel = Label(top, image=smallphoto) photoLabel.image = smallphoto photoLabel.pack() msg = Label(
__author__ = 'zhengxiaoyu' from Tkinter import * # Import everything from Tkinter from Arena import Arena # Import our Arena from Turtle import Turtle # Import our Turtle from Vector import * # Import everything from our Vector from Mouse import * from WalkingTurtle import * from Status import * from Cat import * little_mouse = Mouse(Vector(345, 350), 1, 1) little_cat = Cat(Vector(800, 350), 1, little_mouse) little_status = Status(Vector(450, 350), 1) tk = Tk() # Create a Tk top-level widget arena = Arena(tk, little_cat) # Create an Arena widget, arena arena.pack() arena.add(little_mouse) arena.add(little_cat) arena.add(little_status) tk.mainloop() # Enter the Tkinter event loop
from Tkinter import * # Import everything from Tkinter from Arena import Arena # Import our Arena from Turtle import Turtle # Import our Turtle from Vector import * # Import everything from our Vector Turtle.m = 50.0 # Scaling factor Turtle.origin = Vector(400, 300) from Statue import * from Mouse import * from Cat import * statue = Statue(Turtle.origin + Vector(0, 0), 0) mouse = Mouse(Turtle.origin + Vector(0, -Turtle.m).rotate(40), 0) cat = Cat(Turtle.origin + Vector(0, -4 * Turtle.m).rotate(200), 0, mouse) tk = Tk() # Create a Tk top-level widget arena = Arena(tk, 800, 600) # Create an Arena widget, arena arena.pack() # Tell arena to pack itself on screen arena.add(statue) # Add a very simple, statue arena.add(mouse) # Add a green mouse centered at the base of the statue arena.add(cat) # Add a red cat cat_radius = StringVar() cat_radius.set('CatRadius: %2.f' % cat.radius) cat_angle = StringVar() cat_angle.set('CatAngle: %2.f' % cat.angle) mouse_angle = StringVar() mouse_angle.set('MouseAngle: %2.f' % mouse.angle) arena.add_labels(arena.time, cat_radius, cat_angle, mouse_angle) tk.mainloop() # Enter the Tkinter event loop
from Tkinter import * # Import everything from Tkinter from Arena import Arena # Import our Arena from Turtle import Turtle # Import our Turtle from Vector import * # Import everything from our Vector tk = Tk() # Create a Tk top-level widget arena = Arena(tk) # Create an Arena widget, arena arena.pack() # Tell arena to pack itself on screen turtle = Turtle(Vector(200, 200), 0) arena.add(turtle) # Add a very simple, basic turtle tk.mainloop() # Enter the Tkinter event loop
__author__ = 'zhengxiaoyu' from Tkinter import * # Import everything from Tkinter from Arena import Arena # Import our Arena from Turtle import Turtle # Import our Turtle from Vector import * # Import everything from our Vector from Mouse import * from WalkingTurtle import * from Status import * from Cat import * little_mouse = Mouse(Vector(345,350), 1, 1) little_cat = Cat(Vector(800,350), 1 ,little_mouse) little_status = Status(Vector(450,350), 1) tk = Tk() # Create a Tk top-level widget arena = Arena(tk, little_cat) # Create an Arena widget, arena arena.pack() arena.add(little_mouse) arena.add(little_cat) arena.add(little_status) tk.mainloop() # Enter the Tkinter event loop