def replicate(host: cell.Eukaryote): if host.cytosol.get(vp.EpiCapsid, False): if host.cytosol[vp.EpiCapsid] > Epi_virus.repnum: host.cytosol[vp.EpiCapsid] -= Epi_virus.repnum for _ in range(Epi_virus.repnum): drt = random.randint(1, 4) if drt < 3: if drt == 1: Epi_virus((host.get_rect().centerx, host.get_rect().top - 10), tool.rand_2D(1, 1)) else: Epi_virus((host.get_rect().centerx, host.get_rect().bottom + 10), tool.rand_2D(1, 2)) else: if drt == 3: Epi_virus((host.get_rect().left - 10, host.get_rect().centery), tool.rand_2D(1, 3)) else: Epi_virus((host.get_rect().right + 10, host.get_rect().centery), tool.rand_2D(1, 4)) host.necrosis()
def replicate(host: cell.Eukaryote): if host.cytosol.get(vp.HIVCapsid, False): host.cytosol[vp.HIVCapsid] -= 1 drt = random.randint(1, 4) if drt < 3: if drt == 1: HIV((host.get_rect().centerx, host.get_rect().top - 10), tool.rand_2D(1, 1)) else: HIV((host.get_rect().centerx, host.get_rect().bottom + 10), tool.rand_2D(1, 2)) else: if drt == 3: HIV((host.get_rect().left - 10, host.get_rect().centery), tool.rand_2D(1, 3)) else: HIV((host.get_rect().right + 10, host.get_rect().centery), tool.rand_2D(1, 4))
def release_cytokine(self): """ releases cytokine and resets the list """ for cy in self.cytokine: if self.cytosol.get(cy, False) and self.cytosol[cy] > 0: cy(self.pos, tool.rand_2D(1.2)) self.cytosol[cy] -= 1 else: self.ribosome.mrna(cy, 100) self.cytokine.clear()
def glucose_creator(self, num: int, rect: pygame.Rect): """ num of glucose per second(frame-based), random place in the rect glucose will not move """ if num < 0: raise UserWarning('negative number passed to glucose_creator') if num == 0: return elif self.fps < num: inte = int(num % self.fps) left = num - self.fps * inte for _ in range(inte): x = random.randint( int(rect.left + particle.Glucose.rect.width / 2), int(rect.right - particle.Glucose.rect.width / 2)) y = random.randint( int(rect.top + particle.Glucose.rect.height / 2), int(rect.bottom - particle.Glucose.rect.height / 2)) particle.Glucose((x, y), tool.rand_2D(1, 1)).add(self.ingroup) if left != 0 and self.frame % (self.fps / left) < 1: x = random.randint( int(rect.left + particle.Glucose.rect.width / 2), int(rect.right - particle.Glucose.rect.width / 2)) y = random.randint( int(rect.top + particle.Glucose.rect.height / 2), int(rect.bottom - particle.Glucose.rect.height / 2)) particle.Glucose((x, y), tool.rand_2D(1, 1)).add(self.ingroup) elif self.frame % (self.fps / num) < 1: x = random.randint( int(rect.left + particle.Glucose.rect.width / 2), int(rect.right - particle.Glucose.rect.width / 2)) y = random.randint( int(rect.top + particle.Glucose.rect.height / 2), int(rect.bottom - particle.Glucose.rect.height / 2)) particle.Glucose((x, y), tool.rand_2D(1, 1)).add(self.ingroup)
def necrosis(self): for _ in range(5): particle.NecroticBody(self.pos, tool.rand_2D(0.03)) self.kill()
def apoptosis(self): particle.ApoptoticBody(self.pos, (0, 0)) for _ in range(40): cytokine.Ab(self.pos, tool.rand_2D(1.2)) self.kill()
def replicate(self): if self.replicate_now: new = Eukaryote(self.pos, tool.rand_2D()) new.gene = self.gene.copy() self.replicate_now = False
def run(self): mainloop = True self.screen.blit(self.background, (0, 0)) self.set_skin() #self.one = eukaryote.Macrophage(tool.rand_point(self.vessel),tool.rand_2D()) tool.filler(eukaryote.Epithelium, [(0, 0)], 0, self.skin_area, [self.ingroup]) if self.render_mode: self.saver = tool.Saver('1.json') self.saver.clear_savefile() while mainloop: milliseconds = self.clock.tick(self.fps) self.playtime += milliseconds / 1000.0 self.frame += 1 if self.frame >= self.fps: self.frame = 0 ##escape for event in pygame.event.get(): if event.type == pygame.QUIT: mainloop = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: mainloop = False break #################################################### x, y = pygame.mouse.get_pos() #if event.key == pygame.K_r : # self.one.replicate_now = True if event.key == pygame.K_t: eukaryote.CD8Tcell((x, y), tool.rand_2D(1)) elif event.key == pygame.K_m: eukaryote.Macrophage((x, y), tool.rand_2D(1)) elif event.key == pygame.K_b: gramp.Aureus((x, y), tool.rand_2D(1)) elif event.key == pygame.K_e: eukaryote.Epithelium((x, y), (1, 1)) elif event.key == pygame.K_v: virus.Epi_virus((x, y), (1, 1)) elif event.key == pygame.K_s: self.take_screenshot() elif event.key == pygame.K_q: if self.render_mode: self.saver.saverapid() mainloop = False elif event.type == pygame.MOUSEBUTTONDOWN: x, y = pygame.mouse.get_pos() #virus.HIV((x,y),tool.rand_2D(1)) #particle.Chemokine((x,y), tool.rand_2D(), random.randint(1,3)) #particle.NecroticBody((x,y),tool.rand_2D(0.1)) for cll in eukaryote.Epithelium.epithelium_list: if cll.rect.collidepoint(x, y): cll.necrosis() if len(particle.Glucose.glucose_list) < self.glucose_max: self.glucose_creator(self.glucose_spawn, self.vessel) self.update() if self.render_mode: self.saver.append(self.allgroup) self.screenshot_count += 1 if sys.getsizeof(self.saver.sequel) > 70000: self.saver.saverapid() if self.screenshot_count > self.render_frame: self.saver.saverapid() mainloop = False