コード例 #1
0
 def setup(self):
     """ Setting up the display and storing our initial root branch """
     self.display.fill(bg_colour)
     pygame.display.set_caption("Fractal Tree Generator")
     a = branch.Vector(self.dimensions[0]/2, self.dimensions[1])
     b = branch.Vector(self.dimensions[0]/2, self.dimensions[1] - branch_size)
     self.root = branch.Branch(a, b)
     self.tree.append(self.root)
     self.run()
コード例 #2
0
def execute():
    cv2.destroyAllWindows()
    cv2.namedWindow('tree')
    img = np.zeros((constantes.height,constantes.width) ,dtype = np.uint8)
    cv2.createTrackbar('Curviness','tree',0,100,nothing)
    branches = [branch.Branch(coords = (
    int(constantes.width/2),int(constantes.height)),
    length = constantes.length, angle = pi/2 ,thikness = constantes.thikness)]
    new_branches = []
    tscale = constantes.tscale
    while True:
        global changed
        for br in branches:
            if br.length <5:
                return 'branch became too small'
            br.draw(img)
            #branch to the right
            new_branches.append(branch.Branch(coords = br.end,
            length = br.length*constantes.length_multiplier,
            angle = br.angle + constantes.added_angle,
            thikness = br.thikness*constantes.thikness_multiplier))
            #branch to the left
            new_branches.append(branch.Branch(coords = br.end,
            length = br.length*constantes.length_multiplier,
            angle = br.angle - constantes.added_angle,
            thikness = br.thikness*constantes.thikness_multiplier))

            cv2.imshow('tree',img)
            key = cv2.waitKey(tscale)
            if key == 27:
                return 'User pressed ESC button'
            if changed:
                cur = cv2.getTrackbarPos('Curviness','tree')
                constantes.added_angle = cur * pi / 200
                changed = False
            if key == 13:
                execute()
                return 'User pressed ESC button'

        if tscale >2:
            tscale = int(tscale/2)
        branches = new_branches.copy()
        new_branches = []
コード例 #3
0
 def setup(self):
     """ Setting up the display and storing our initial root branch """
     self.display.fill(bg_colour)
     pygame.display.set_caption("Fractal Tree Generator")
     for i in range(forest_size):
         branch_size = random.randint(min_branch_size, max_branch_size)
         x = random.randint(0, self.dimensions[0])
         a = branch.Vector(x, self.dimensions[1])
         b = branch.Vector(x, self.dimensions[1] - branch_size)
         root = branch.Branch(a, b)
         self.tree.append(root)
         self.forest.append(self.tree)
     self.run()
コード例 #4
0
    def create_branch_board(self, pos_branch):
        """Returns a new board with the branch applied to it"""

        assert isinstance(pos_branch, branch.Branch)

        return_board = deepcopy(self)

        cur_piece = return_board.pieces[pos_branch.piece.location]
        new_branch = branch.Branch(cur_piece, pos_branch.to_location)

        Board.board_count += 1

        return_board.apply_branch(new_branch)
        return_board.previous_board = self

        return return_board
コード例 #5
0
	def growbranch(self):
		ungrownnodes = []
		for node in self.nodes:
			for i in range(0, 2):
				if not (node[0], node[1], i) in self.grownnodes and not node == self.nodes[0]:
					ungrownnodes.append((node, i))
				
		if ungrownnodes:
			i = random.randint(0, len(ungrownnodes) - 1)
			
			node, l = ungrownnodes[i]
			if l == 0:
				lean = -5
			else:
				lean = 5
				
			self.grownnodes.append((node[0], node[1], l))
				
			newbranch = branch.Branch(node[0], node[1], lean, self.particles, 1, self.player)
			self.branches.append(newbranch)
			self.energy -= 2.0
コード例 #6
0
ファイル: main.py プロジェクト: henrikauzins/PizzaApplication
def OrderingSystem():
    ## customer_order will be storing the objects of the pizza order

    #stores order details
    customer_order = []
    #stores prices of order elements
    total_price = []

    location = ["london", "newcastle", "bath", "liverpool", "kent"]
    orderNumber = 0

    while True:
        pizza_name = input("what pizza would you like?")
        pizza_choices = {
            "margherita": 10.00,
            "pepperoni": 11.00,
            "hawaiian": 10.00,
            "meat feast": 12.00,
            "bbq chicken": 13.00
        }

        if pizza_name in pizza_choices:
            print(pizza_name, "exists")
            # prints cost of selected topping
            print("this will cost you £", pizza_choices[pizza_name])
            total_price.append(pizza_choices[pizza_name])
            print(total_price)
            break

        # if inputted base does not exist
        elif pizza_name not in pizza_choices:
            print(pizza_name, "is not on offer")

    while True:
        pizza_type = input("what pizza type would you like?")
        pizza_types = {
            "deep dish": 4.00,
            "sicilian": 5.00,
            "greek": 6.00,
            "calzone": 7.00,
            "neapolitan": 8.00,
            "new york style": 9.00
        }

        if pizza_type in pizza_types:
            print(pizza_type, "exists")
            # prints cost of selected pizza type
            print("this will cost you £", pizza_types[pizza_type])
            total_price.append(pizza_types[pizza_type])
            print(total_price)
            break

        elif pizza_type not in pizza_types:
            print(pizza_type, "is not on offer")

        new_pizza = pizza.Pizza(pizza_name, pizza_type)

        customer_order.append(new_pizza)

    while True:

        pizza_topping = input("what pizza topping would you like?")
        toppings = {"cheese": 0.86, "sausage": 0.90, "ham": 1.0}
        if pizza_topping in toppings:
            print(pizza_topping, "exists")
            #prints cost of selected topping
            print("this will cost you £", toppings[pizza_topping])
            total_price.append(toppings[pizza_topping])
            print(total_price)
            new_topping = topping.Topping(pizza_topping)
            customer_order.append(new_topping)
            break

# if inputted topping does not exist
        elif pizza_topping not in toppings:
            print(pizza_topping, "is not on offer")

    while True:
        print("base choices are small, medium or large")
        pizza_base = input("what size pizza base would you like?")

        base_selection = {"small": 5, "medium": 6, "large": 7}

        if pizza_base in base_selection:
            print(pizza_base, "exists")
            # prints cost of selected topping
            print("this will cost you £", base_selection[pizza_base])
            total_price.append(base_selection[pizza_base])
            print(total_price)

            # new base object initialised
            new_base = base.Base(pizza_base)
            customer_order.append(new_base)
            break

        # if inputted base does not exist
        elif pizza_base not in base_selection:
            print(pizza_base, "is not on offer")

    customer_location = input("which branch would you like to order from: ")

    while customer_location not in location:
        if customer_location in location:
            print("location exists")
            new_branch = branch.Branch(customer_location)
            customer_order.append(new_branch)
            break

        else:
            print("location does not exist")
            print(location)
            customer_location = input(
                "which branch would you like to order from: ")

    orderNumber = orderNumber + 1

    customer_order.append(orderNumber)

    print("Order Summary")
    print(customer_order)
    #add dictionary for total prices of items on the customers order
    placed = "order placed"
    not_placed = "order not placed"

    print("the total cost of your order is: £", sum(total_price))

    place_order = input("would you like to place your order: ")

    if place_order == "yes":
        print(bool(placed))
        customer_order.clear()
        total_price.clear()
        main()
    elif place_order == "no":
        print(bool(not_placed))
        customer_order.clear()
        total_price.clear()
        main()
コード例 #7
0
import pieces
import board
import branch
import player
import random
import time

start_time = time.time()

foo = board.Board()

piece = pieces.Pawn()
print str(piece.points) + ": " + piece.name

foo.add_piece(piece)
bar = branch.Branch(piece, (1, 1))
foo.apply_branch(bar)

piece = pieces.Knight()
print str(piece.points) + ": " + piece.name

foo.add_piece(piece)
bar = branch.Branch(piece, (2, 2))
foo.apply_branch(bar)

piece = pieces.Bishop()
print str(piece.points) + ": " + piece.name

foo.add_piece(piece)
bar = branch.Branch(piece, (3, 3))
foo.apply_branch(bar)