예제 #1
0
class AntPlot:
	"""Class that uses wx to draw a plot of the Ants in the World."""
	
	def __init__(self, world):
		self.world = world
		self.app = wx.PySimpleApp()
		self.w = 500
		self.h = 500
		self.frame = wx.Frame(None, -1, 'Ant Plot', 
				      size=(self.w, self.h))
		self.canvas = FloatCanvas(self.frame, -1)
		
	
	def draw(self):
		"""Pops up a wx window that represents the current state of
		the World.
		"""
		positions = self.world.get_ant_dict()
		for pos in positions:
			x, y = pos
			x -= self.w / 2
			y -= self.h / 2
			self.canvas.AddPoint((x, y))
		self.frame.Show()
		self.app.MainLoop()
예제 #2
0
파일: rentals.py 프로젝트: mpomery/CITS4403
class CityPrinter(object):
    
    def __init__(self, city, population):
        self.city = city
        self.population = population
        
        self.app = wx.App(False)
        self.w = self.city.size + 100
        self.h = self.city.size + 120
        self.frame_rent = wx.Frame(None, -1, 'Rent Map', size=(self.w, self.h))
        self.frame_income = wx.Frame(None, -1, 'Income Map', size=(self.w, self.h))
        self.canvas_rent = FloatCanvas(self.frame_rent, -1)
        self.canvas_income = FloatCanvas(self.frame_income, -1)
    
    def create_heatmaps(self):
        self.create_rent_map()
        self.create_income_map()
        self.app.MainLoop()
    
    def create_rent_map(self):
        print("Lowest Rent: " + str(self.city.min_price))
        print("Highest Rent: " + str(self.city.max_price))
        min_price = self.city.min_price
        max_price = self.city.max_price

        time1 = time.time()
        print("Generating Rent Map")
        
        for house in self.city.houses:
            x = house.x - self.city.size / 2
            y = house.y - self.city.size / 2
            col = self.color(self.city.get_house(house).price, min_price, max_price, \
                    self.city.get_house(house).occupant == None)
            self.canvas_rent.AddPoint((x, y), Color = col)
        
        time2 = time.time()
        print('Generating Image took %0.3f ms' % ((time2-time1) * 1000.0))
        
        self.frame_rent.Show()
    
    def create_income_map(self):
        print("Lowest Income: " + str(self.population.min_income))
        print("Highest Income: " + str(self.population.max_income))
        min_income = self.population.min_income
        max_income = self.population.max_income

        time1 = time.time()
        print("Generating Income Map")
        
        for house in self.city.houses:
            x = house.x - self.city.size / 2
            y = house.y - self.city.size / 2
            person = self.city.get_house(house).occupant
            if person != None:
                col = self.color(person.income, min_income, max_income)
                self.canvas_income.AddPoint((x, y), Color = col)
        
        time2 = time.time()
        print('Generating Image took %0.3f ms' % ((time2-time1) * 1000.0))
        
        self.frame_income.Show()
    
    def color(self, value, min, max, red=False):
        #print("Colouring In")
        
        if not red:
            # Approximating http://geog.uoregon.edu/datagraphics/color/Bu_10.txt on the fly
            red_range = (0, 0.9)
            green_range = (0.25, 1.0)
            blue_range = (1.0, 1.0)
        else:
            # Colour Shifting it to red
            red_range = (1.0, 1.0)
            green_range = (0, 0.9)
            blue_range = (0.25, 1.0)
        
        percentage_of_range = 1 - (value - min)/(max - min)
        
        red = (((red_range[1] - red_range[0]) * percentage_of_range) + red_range[0]) * 255
        green = (((green_range[1] - green_range[0]) * percentage_of_range) + green_range[0]) * 255
        blue = (((blue_range[1] - blue_range[0]) * percentage_of_range) + blue_range[0]) * 255
        
        return wx.Colour(red, green, blue, 1)
    
    """
    Write the city to standard out for quick testing and debugging.
    """
    def __str__(self):
        output = ""
        output += "Cheapest Place: " + str(self.city.min_price) + "\n"
        output += "Most Expensive Place: " + str(self.city.max_price) + "\n"
        output += "\n"
        for y in range(self.city.size):
            row = ""
            for x in range(self.city.size):
                coords = Coordinates(x, y)
                occupied_string = "_" if self.city.get_house(coords).occupant == None else "X"
                row += str("%3d%s " % (self.city.get_house(coords).price, occupied_string))
            output += row + "\n"
        return output
예제 #3
0
파일: income.py 프로젝트: mpomery/CITS4403
class CityPrinter(object):
    def __init__(self, city, population):
        self.city = city
        self.population = population

        self.app = wx.App(False)
        self.w = self.city.size + 100
        self.h = self.city.size + 120
        self.frame = wx.Frame(None, -1, 'Income Map', size=(self.w, self.h))
        self.canvas = FloatCanvas(self.frame, -1)

    def create_heatmap(self):
        min_income = self.population.min_income
        max_income = self.population.max_income
        print("Lowest Income: " + str(min_income))
        print("Highest Income: " + str(max_income))

        for house in self.city.houses:
            x = house.x - self.city.size / 2
            y = house.y - self.city.size / 2
            person = self.city.get_house(house)
            if person != None:
                col = self.color(person.income, min_income, max_income)
                self.canvas.AddPoint((x, y), Color=col)

        self.frame.Show()
        self.app.MainLoop()

    def color(self, value, min_val, max_val):
        # Approximating http://geog.uoregon.edu/datagraphics/color/Bu_10.txt on the fly
        red_range = (0, 0.9)
        green_range = (0.25, 1.0)
        blue_range = (1.0, 1.0)

        percentage_of_range = 1 - (value - min_val) / (max_val - min_val)

        red = (((red_range[1] - red_range[0]) * percentage_of_range) +
               red_range[0]) * 255
        green = (((green_range[1] - green_range[0]) * percentage_of_range) +
                 green_range[0]) * 255
        blue = (((blue_range[1] - blue_range[0]) * percentage_of_range) +
                blue_range[0]) * 255

        return wx.Colour(red, green, blue, 1)

    """
    Write the city to standard out for quick testing and debugging.
    """

    def __str__(self):
        output = ""
        for y in range(self.city.size):
            row = ""
            for x in range(self.city.size):
                coords = Coordinates(x, y)
                occupied = self.city.get_house(coords) != None
                if occupied:
                    row += str("%3d " % (self.city.get_house(coords).income))
                else:
                    row += str("    ")
            output += row + "\n"
        return output