예제 #1
0
    def startSimulation(self):
        nbCells = int(self.txtNbCell.toPlainText())
        albedoCloud = float(self.txtAlbedo.toPlainText())
        greenHouse = float(self.txtGreenHouse.toPlainText())
        fTempInit = float(self.txtTempInit.toPlainText())

        matSize = int(math.sqrt(nbCells))
        tempInit = np.zeros((matSize, matSize))
        tempInit.fill(fTempInit)

        self.grpInitialParameters.setEnabled(False)
        self.grpIterCtrl.setEnabled(True)
        self.grpCurrentIter.setEnabled(True)

        # Creating the Earth object
        self.earth = Earth(nbCells, albedoCloud, greenHouse, tempInit)

        self.matOverall = np.zeros(1)
        matAvgPerZone = self.earth.getAvgPerZone()
        self.matOverall[0] = self.computeOverallAvg(matAvgPerZone)

        self.graphCurrent.show()
        self.graphCurrent.update_figure(0, matAvgPerZone)
        self.graphOverall.show()
        self.graphOverall.update_figure(1, self.matOverall)
예제 #2
0
 def earth(self):
     earth = Earth()
     for t in self.tiles.itervalues():
         elevation = earth.sample(t.lat, t.lon) / 900.0
         if elevation < 0:
             elevation = 0
         t.bottom = -1
         t.layers = [Layer({ 'type': 'S', 'toughness': 0.5 }, elevation + 1)]
         t.limit()
     self.erode()
예제 #3
0
 def earth(self):
     earth = Earth()
     for t in self.tiles.itervalues():
         elevation = earth.sample(t.lat, t.lon) / 900.0
         if elevation < 0:
             elevation = 0
         t.bottom = -1
         t.layers = [Layer('S', elevation + 1)]
         t.limit()
     self.classify()
예제 #4
0
def main():
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))  #,RESIZABLE)
    pygame.display.set_caption("Alien Invasion")
    play_button = Button(ai_settings, screen, "Play")
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    ship = Ship(ai_settings, screen)
    moon = Moon(ai_settings, screen)
    earth = Earth(ai_settings, screen)
    stars = Group()
    bullets = Group()
    aliens = Group()
    gf.create_fleet(ai_settings, screen, ship, aliens)
    gf.create_multilayer_star(ai_settings, screen, stars)
    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        aliens, bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                              bullets)
            gf.update_aliens(ai_settings, stats, sb, screen, ship, aliens,
                             bullets)
            stats.update_highscore()
        gf.update_screen(ai_settings, screen, stats, stars, sb, [moon, earth],
                         [ship], play_button, aliens, bullets)
예제 #5
0
    def __init__(self):
        pygame.init()
        self.clock = pygame.time.Clock()
        self.font = pygame.font.SysFont("Arial", 18)
        self.settings = Settings()
        self.screen = pygame.display.set_mode(
            (self.settings.screen_width, self.settings.screen_height))
        pygame.display.set_caption("Alienz")
        self.logger = Logger(self)

        self.earth = Earth(self)
        self.bullets = pygame.sprite.Group()
        self.ships = pygame.sprite.Group()
        self.enemies = pygame.sprite.Group()

        self.is_encounter_active = False
        self.encounter = Encounter(self)
예제 #6
0
def run_game():
    pygame.init()
    pygame.mixer.music.load('music/Phantom from Space.mp3')
    pygame.mixer.music.play(-1)
    pygame.mixer.music.set_volume(0.5)
    sw_settings = Settings()
    screen = pygame.display.set_mode(
        (sw_settings.screen_width, sw_settings.screen_height))
    pygame.display.set_caption("Earth's Defender")
    earth = Earth(sw_settings, screen)
    moon = Moon(sw_settings, screen)
    sun = Sun(sw_settings, screen)
    play_button = Button(sw_settings, screen, "Play")
    pause_message = PauseMessage(sw_settings, screen, "Pause")
    game_stats = GameStats(sw_settings)
    scoreboard = Scoreboard(sw_settings, screen, game_stats)
    ship = Ship(sw_settings, screen)
    alien_boss = AlienBoss(sw_settings, screen)
    bullets = Group()
    aliens = Group()
    aliens_bullets = Group()
    asteroids = Group()
    gf.create_fleet(sw_settings, screen, ship, aliens)

    while True:
        gf.check_events(sw_settings, screen, game_stats, scoreboard,
                        play_button, pause_message, ship, aliens, bullets,
                        aliens_bullets, asteroids)
        if game_stats.game_active and game_stats.game_pause:
            ship.update()
            gf.update_bullets(sw_settings, screen, game_stats, scoreboard,
                              ship, aliens, bullets, aliens_bullets, asteroids,
                              alien_boss)
            gf.update_aliens(sw_settings, game_stats, scoreboard, screen, ship,
                             aliens, bullets, aliens_bullets, asteroids)
            gf.check_alien_fires(sw_settings, screen, aliens, aliens_bullets)
            gf.update_aliens_bullets(sw_settings, game_stats, scoreboard,
                                     screen, ship, aliens, bullets,
                                     aliens_bullets, asteroids)
            gf.check_asteroid_fall(sw_settings, screen, asteroids)
            gf.update_asteroids(sw_settings, game_stats, scoreboard, screen,
                                ship, aliens, bullets, aliens_bullets,
                                asteroids)
            gf.update_alien_boss(sw_settings, screen, game_stats, alien_boss,
                                 aliens, aliens_bullets, bullets, asteroids)
        gf.update_screen(sw_settings, screen, earth, moon, sun, game_stats,
                         scoreboard, ship, aliens, bullets, aliens_bullets,
                         asteroids, play_button, pause_message, alien_boss)
예제 #7
0
 def earthavailable(self):
     return Earth.available()
예제 #8
0
class Alienz:
    # This is the overall class to manage game assets and behaviour

    def __init__(self):
        pygame.init()
        self.clock = pygame.time.Clock()
        self.font = pygame.font.SysFont("Arial", 18)
        self.settings = Settings()
        self.screen = pygame.display.set_mode(
            (self.settings.screen_width, self.settings.screen_height))
        pygame.display.set_caption("Alienz")
        self.logger = Logger(self)

        self.earth = Earth(self)
        self.bullets = pygame.sprite.Group()
        self.ships = pygame.sprite.Group()
        self.enemies = pygame.sprite.Group()

        self.is_encounter_active = False
        self.encounter = Encounter(self)

    def run_game(self):
        # main loop for the game
        while True:
            self._check_events()
            self._update_screen()
            self._update_ships()
            self._update_enemies()
            self._update_bullets()
            self._check_collisions()
            self._update_encounter_status()
            self.clock.tick(60)

    def _check_events(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_a:
                    self.earth.create_factory()
                elif event.key == pygame.K_s:
                    self.earth.create_ship()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                pos = pygame.mouse.get_pos()
                print(pos)

    def _update_screen(self):
        self.screen.fill(self.settings.bg_color)
        self.earth.blitme()
        for factory in self.earth.factories:
            factory.blitme()
        for ship in self.earth.ships:
            ship.blitme()
        for enemy in self.encounter.enemies:
            enemy.blitme()
        for bullet in self.bullets:
            bullet.blitme()

        self.screen.blit(update_fps(self), (3, 0))
        self.screen.blit(
            log_message(self, self.logger.log_message, self.logger.color),
            (800, 0))

        pygame.display.flip()

    def _update_ships(self):
        for ship in self.earth.ships:
            ship.update_position()

    def _update_enemies(self):
        for enemy in self.encounter.enemies:
            enemy.update_position()

    def _update_bullets(self):
        for bullet in self.bullets:
            bullet.update_position()

    def _check_collisions(self):
        collisions = pygame.sprite.groupcollide(self.bullets, self.enemies,
                                                False, False)
        for bullet in collisions:
            collisions[bullet][0].receive_damage(bullet.damage)
            bullet.kill()

    def _update_encounter_status(self):
        self.encounter.check_encounter()
        #print(self.is_encounter_active)
        if self.is_encounter_active == False:
            self.encounter = Encounter(self)
예제 #9
0
 def action(self):
     x = self.__outer.x
     y = self.__outer.y
     earth = Earth(self.__outer._ecosystem, x, y, water_amount=self.__outer.water_amount)
     self.__outer._ecosystem.plant_map[x][y] = earth
     self._status = bt.Status.FAIL
예제 #10
0
    def initialize_forest(self):
        """Adds initial organisms to the map."""

        directions = list(Direction)
        # Water map
        for pool_size in WATER_POOLS:
            rand_x = random.randint(0, self.width - 1)
            rand_y = random.randint(0, self.height - 1)
            while self.water_map[rand_x][rand_y]:
                rand_x = random.randint(0, self.width - 1)
                rand_y = random.randint(0, self.height - 1)
            water_pools_added = 0
            positions = [(rand_x, rand_y)]
            WATER_POOLS_POSITIONS.append((rand_x, rand_y))
            while water_pools_added < pool_size and positions:
                # Breadth first add water pools around
                x, y = positions.pop(0)
                if not self.water_map[x][y]:
                    water = Water(self, x, y)
                    self.water_map[x][y] = water
                    water_pools_added += 1
                    # Insert all neighbors
                    random.shuffle(
                        directions)  # shuffle for a bit random shapes
                    for dir in directions:
                        new_x = x + dir.value[0]
                        new_y = y + dir.value[1]
                        # Check if out of bounds
                        if new_x < 0 or new_x >= self.width or new_y < 0 or new_y >= self.height:
                            continue
                        if self.water_map[new_x][new_y]:
                            continue
                        positions.append((new_x, new_y))

        # Plant map
        for x in range(self.width):
            for y in range(self.height):
                # check if water
                if self.water_map[x][y]:
                    continue
                if random.random() <= TREE_PERCENTAGE:
                    tree = Tree(self, x, y)
                    self.plant_map[x][y] = tree
                    if random.random() <= HIVES_PER_TREE:
                        hive = Hive(self, x, y)
                        self.animal_map[x][y].append(hive)
                        bee_amount = random.randint(HIVE_BEE_MIN_AMOUNT,
                                                    HIVE_BEE_MAX_AMOUNT)
                        bee = Bee(self,
                                  x,
                                  y,
                                  hive=hive,
                                  scout=True,
                                  age=random.randint(0, 24 * 150))
                        hive.bees.append(bee)
                        self.animal_map[x][y].append(bee)
                        for _ in range(bee_amount):
                            bee = Bee(self,
                                      x,
                                      y,
                                      hive=hive,
                                      scout=False,
                                      age=random.randint(0, 24 * 150))
                            self.animal_map[x][y].append(bee)
                            hive.bees.append(bee)
                elif random.random() <= GRASS_INIT_PERCENTAGE:
                    grass = Grass(self, x, y, random.randint(-80, 100), None,
                                  self.get_initial_water_level(x, y))
                    self.plant_map[x][y] = grass
                else:
                    earth = Earth(self, x, y,
                                  self.get_initial_water_level(x, y))
                    self.plant_map[x][y] = earth

        # Flower map
        from organisms import Type
        for x in range(self.width):
            for y in range(self.height):
                if self.water_map[x][y]:
                    continue
                if random.random() <= FLOWER_PERCENTAGE:
                    if self.plant_map[x][y] and self.plant_map[x][
                            y].type == Type.TREE:
                        continue
                    for _ in range(random.randint(1, 4)):
                        flower = Flower(self,
                                        x,
                                        y,
                                        random.randint(-50, 100),
                                        nectar=random.randint(0, 100),
                                        has_seed=random.choice([True, False]))
                        self.flower_map[x][y].append(flower)

        # Animal map
        import numpy as np
        # Rabbits
        for _ in range(BURROW_AMOUNT):
            x = random.randint(0, self.width - 1)
            y = random.randint(0, self.height - 1)
            while self.water_map[x][y]:
                x = random.randint(0, self.width - 1)
                y = random.randint(0, self.height - 1)
            burrow = Burrow(self, x, y)
            self.animal_map[x][y].append(burrow)
            rabbit_amount = random.randint(BURROW_RABBIT_MIN_AMOUNT,
                                           BURROW_RABBIT_MAX_AMOUNT)
            for _ in range(rabbit_amount):
                dx = random.randint(-3, 3)
                dy = random.randint(-3, 3)

                if x + dx < 0 or x + dx >= self.width or y + dy < 0 or y + dy >= self.height:
                    continue

                if self.water_map[x + dx][y + dy]:
                    continue

                rabbit = Rabbit(self,
                                x + dx,
                                y + dy,
                                random.choice([True, False]),
                                adult=True,
                                burrow=burrow,
                                age=random.randint(24 * 30, 24 * 30 * 3),
                                reproduction_timer=random.randint(0, 24 * 6),
                                genetics_factor=np.random.normal(1, 0.1))
                self.animal_map[x + dx][y + dy].append(rabbit)

        # Foxes
        for _ in range(FOX_AMOUNT):
            x = random.randint(0, self.width - 1)
            y = random.randint(0, self.height - 1)
            while self.water_map[x][y]:
                x = random.randint(0, self.width - 1)
                y = random.randint(0, self.height - 1)
            fox = Fox(self,
                      x,
                      y,
                      random.choice([True, False]),
                      adult=True,
                      age=random.randint(24 * 30 * 2, 24 * 30 * 6),
                      genetics_factor=np.random.normal(1, 0.1))
            self.animal_map[x][y].append(fox)
예제 #11
0
class Ui_MainWindow(object):
    DEFAULT_CELL_NUMBERS = 121
    DEFAULT_ALBEDO_CLOUD = 0.2
    DEFAULT_GREEN_HOUSE = 0.2
    DEFAULT_INITIAL_TEMP = 273

    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(730, 650)
        MainWindow.setFocusPolicy(QtCore.Qt.NoFocus)
        MainWindow.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.grpInitialParameters = QtWidgets.QGroupBox(self.centralwidget)
        self.grpInitialParameters.setGeometry(QtCore.QRect(10, 10, 191, 181))
        self.grpInitialParameters.setObjectName("grpInitialParameters")
        self.txtNbCell = QtWidgets.QTextEdit(self.grpInitialParameters)
        self.txtNbCell.setGeometry(QtCore.QRect(130, 20, 51, 20))
        self.txtNbCell.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.txtNbCell.setInputMethodHints(QtCore.Qt.ImhDigitsOnly
                                           | QtCore.Qt.ImhPreferNumbers)
        self.txtNbCell.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.txtNbCell.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.txtNbCell.setObjectName("txtNbCell")
        self.txtTempInit = QtWidgets.QTextEdit(self.grpInitialParameters)
        self.txtTempInit.setGeometry(QtCore.QRect(130, 110, 51, 20))
        self.txtTempInit.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.txtTempInit.setInputMethodHints(QtCore.Qt.ImhDigitsOnly
                                             | QtCore.Qt.ImhPreferNumbers)
        self.txtTempInit.setVerticalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.txtTempInit.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.txtTempInit.setTabChangesFocus(False)
        self.txtTempInit.setLineWrapMode(QtWidgets.QTextEdit.NoWrap)
        self.txtTempInit.setObjectName("txtTempInit")
        self.lblAlbedoCloud = QtWidgets.QLabel(self.grpInitialParameters)
        self.lblAlbedoCloud.setGeometry(QtCore.QRect(10, 50, 91, 20))
        self.lblAlbedoCloud.setObjectName("lblAlbedoCloud")
        self.txtAlbedo = QtWidgets.QTextEdit(self.grpInitialParameters)
        self.txtAlbedo.setGeometry(QtCore.QRect(130, 50, 51, 20))
        self.txtAlbedo.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.txtAlbedo.setInputMethodHints(QtCore.Qt.ImhDigitsOnly
                                           | QtCore.Qt.ImhPreferNumbers)
        self.txtAlbedo.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.txtAlbedo.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.txtAlbedo.setObjectName("txtAlbedo")
        self.lblNbCell = QtWidgets.QLabel(self.grpInitialParameters)
        self.lblNbCell.setGeometry(QtCore.QRect(10, 20, 81, 20))
        self.lblNbCell.setObjectName("lblNbCell")
        self.lblGreenHouse = QtWidgets.QLabel(self.grpInitialParameters)
        self.lblGreenHouse.setGeometry(QtCore.QRect(10, 80, 121, 21))
        self.lblGreenHouse.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.lblGreenHouse.setAutoFillBackground(False)
        self.lblGreenHouse.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.lblGreenHouse.setTextFormat(QtCore.Qt.AutoText)
        self.lblGreenHouse.setIndent(1)
        self.lblGreenHouse.setObjectName("lblGreenHouse")
        self.txtGreenHouse = QtWidgets.QTextEdit(self.grpInitialParameters)
        self.txtGreenHouse.setGeometry(QtCore.QRect(130, 80, 51, 20))
        self.txtGreenHouse.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.txtGreenHouse.setInputMethodHints(QtCore.Qt.ImhDigitsOnly
                                               | QtCore.Qt.ImhPreferNumbers)
        self.txtGreenHouse.setVerticalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.txtGreenHouse.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.txtGreenHouse.setObjectName("txtGreenHouse")
        self.btnStart = QtWidgets.QPushButton(self.grpInitialParameters)
        self.btnStart.setGeometry(QtCore.QRect(50, 140, 91, 31))
        self.btnStart.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.btnStart.setObjectName("btnStart")
        self.lblTempInit = QtWidgets.QLabel(self.grpInitialParameters)
        self.lblTempInit.setGeometry(QtCore.QRect(10, 110, 121, 21))
        self.lblTempInit.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.lblTempInit.setAutoFillBackground(False)
        self.lblTempInit.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.lblTempInit.setTextFormat(QtCore.Qt.AutoText)
        self.lblTempInit.setIndent(1)
        self.lblTempInit.setObjectName("lblTempInit")
        self.grpIterCtrl = QtWidgets.QGroupBox(self.centralwidget)
        self.grpIterCtrl.setGeometry(QtCore.QRect(220, 10, 331, 51))
        self.grpIterCtrl.setObjectName("grpIterCtrl")
        self.btnPlusOneIter = QtWidgets.QPushButton(self.grpIterCtrl)
        self.btnPlusOneIter.setGeometry(QtCore.QRect(10, 20, 75, 23))
        self.btnPlusOneIter.setObjectName("btnPlusOneIter")
        self.btnPlusFiveIter = QtWidgets.QPushButton(self.grpIterCtrl)
        self.btnPlusFiveIter.setGeometry(QtCore.QRect(90, 20, 75, 23))
        self.btnPlusFiveIter.setObjectName("btnPlusFiveIter")
        self.btnPlusTenIter = QtWidgets.QPushButton(self.grpIterCtrl)
        self.btnPlusTenIter.setGeometry(QtCore.QRect(170, 20, 75, 23))
        self.btnPlusTenIter.setObjectName("btnPlusTenIter")
        self.btnPlusHundredIter = QtWidgets.QPushButton(self.grpIterCtrl)
        self.btnPlusHundredIter.setGeometry(QtCore.QRect(250, 20, 75, 23))
        self.btnPlusHundredIter.setObjectName("btnPlusHundredIter")
        self.grpCurrentIter = QtWidgets.QGroupBox(self.centralwidget)
        self.grpCurrentIter.setGeometry(QtCore.QRect(220, 80, 331, 111))
        self.grpCurrentIter.setObjectName("grpCurrentIter")
        self.graphCurrent = DynamicMplCanvas(self.centralwidget)
        self.graphCurrent.setGeometry(QtCore.QRect(10, 200, 500, 200))
        self.graphCurrent.setObjectName("graphCurrent")
        self.graphOverall = DynamicMplCanvas(self.centralwidget)
        self.graphOverall.setGeometry(QtCore.QRect(10, 420, 500, 200))
        self.graphOverall.setObjectName("graphOverall")
        self.graphCurrent.axes.set_title(
            'Current temperature in Kelvin depending on the zone')
        self.graphOverall.axes.set_title(
            'Overall temperature in Kelvin depending on the iteration')
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 560, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.currGraphImage = QtWidgets.QLabel(self.centralwidget)
        self.currGraphImage.setScaledContents(True)
        #self.currGraphImage.rotate(-90)

        # Initial values
        self.txtNbCell.setText(str(self.DEFAULT_CELL_NUMBERS))
        self.txtAlbedo.setText(str(self.DEFAULT_ALBEDO_CLOUD))
        self.txtGreenHouse.setText(str(self.DEFAULT_GREEN_HOUSE))
        self.txtTempInit.setText(str(self.DEFAULT_INITIAL_TEMP))

        self.grpIterCtrl.setEnabled(False)
        self.grpCurrentIter.setEnabled(False)
        self.graphCurrent.hide()
        self.graphOverall.hide()

        # Events
        self.btnStart.clicked.connect(self.startSimulation)
        self.btnPlusOneIter.clicked.connect(self.handlerBtnPlusOne)
        self.btnPlusFiveIter.clicked.connect(self.handlerBtnPlusFive)
        self.btnPlusTenIter.clicked.connect(self.handlerBtnPlusTen)
        self.btnPlusHundredIter.clicked.connect(self.handlerBtnPlusHundred)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(
            _translate("MainWindow", "Snowball Earth Theorem"))
        self.grpInitialParameters.setTitle(
            _translate("MainWindow", "Initial parameters"))
        self.lblAlbedoCloud.setText(
            _translate("MainWindow", "Albedo Constant:"))
        self.lblNbCell.setText(_translate("MainWindow", "Number of cells:"))
        self.lblGreenHouse.setText(
            _translate("MainWindow", "Green House Constant:"))
        self.btnStart.setText(_translate("MainWindow", "Start  simulation"))
        self.lblTempInit.setText(
            _translate("MainWindow", "Initial temperature:"))
        self.grpIterCtrl.setTitle(_translate("MainWindow",
                                             "Iteration control"))
        self.btnPlusOneIter.setText(_translate("MainWindow", "+ 1"))
        self.btnPlusFiveIter.setText(_translate("MainWindow", "+ 5"))
        self.btnPlusTenIter.setText(_translate("MainWindow", "+ 10"))
        self.btnPlusHundredIter.setText(_translate("MainWindow", "+ 100"))
        self.grpCurrentIter.setTitle(
            _translate("MainWindow", "Current iteration"))

    def startSimulation(self):
        nbCells = int(self.txtNbCell.toPlainText())
        albedoCloud = float(self.txtAlbedo.toPlainText())
        greenHouse = float(self.txtGreenHouse.toPlainText())
        fTempInit = float(self.txtTempInit.toPlainText())

        matSize = int(math.sqrt(nbCells))
        tempInit = np.zeros((matSize, matSize))
        tempInit.fill(fTempInit)

        self.grpInitialParameters.setEnabled(False)
        self.grpIterCtrl.setEnabled(True)
        self.grpCurrentIter.setEnabled(True)

        # Creating the Earth object
        self.earth = Earth(nbCells, albedoCloud, greenHouse, tempInit)

        self.matOverall = np.zeros(1)
        matAvgPerZone = self.earth.getAvgPerZone()
        self.matOverall[0] = self.computeOverallAvg(matAvgPerZone)

        self.graphCurrent.show()
        self.graphCurrent.update_figure(0, matAvgPerZone)
        self.graphOverall.show()
        self.graphOverall.update_figure(1, self.matOverall)

    def iterate(self):
        matAvgPerZone = np.zeros(1)

        while self.nbIter > 0:
            self.earth.iterate()
            self.nbIter -= 1

            matAvgPerZone = self.earth.getAvgPerZone()
            self.matOverall = np.append(self.matOverall,
                                        self.computeOverallAvg(matAvgPerZone))

        # Current iteration graph
        self.graphCurrent.update_figure(0, matAvgPerZone)

        # Overall graph
        self.graphOverall.update_figure(1, self.matOverall)

        graphWidth = self.centralwidget.width() - 20
        graphHeight = (int)(
            (self.centralwidget.height() - (self.graphCurrent.x() + 200)) / 2)

        self.graphCurrent.setGeometry(
            QtCore.QRect(10, 200, (int)((graphWidth / 3) * 2) - 5,
                         graphHeight))
        self.graphOverall.setGeometry(
            QtCore.QRect(10, 200 + self.graphCurrent.height() + 15, graphWidth,
                         graphHeight))

        imgWidth = (int)(graphWidth / 3) - 5
        imgPosX = (int)(self.graphCurrent.x() + ((graphWidth / 3) * 2)) + 5
        self.currGraphImage.setGeometry(imgPosX, self.graphCurrent.y(),
                                        imgWidth, graphHeight)

        BuildTempsImage(self.earth.getMatTemp(), min(matAvgPerZone),
                        max(matAvgPerZone))

        pixmap = QtGui.QPixmap('temperatureImage.png')
        transform = QtGui.QTransform().rotate(90)
        pixmap = pixmap.transformed(transform)
        self.currGraphImage.setPixmap(pixmap)

    def handlerBtnPlusOne(self):
        self.nbIter = 1
        self.iterate()

    def handlerBtnPlusFive(self):
        self.nbIter = 5
        self.iterate()

    def handlerBtnPlusTen(self):
        self.nbIter = 10
        self.iterate()

    def handlerBtnPlusHundred(self):
        self.nbIter = 100
        self.iterate()

    def computeOverallAvg(self, mat):
        arrayWidth = mat.shape[0]
        lineAvgTemp = 0
        for i in range(arrayWidth):
            lineAvgTemp += mat[i]

        return lineAvgTemp / arrayWidth