def __init__(self, name="score-cld-esc", **kwargs): super(CloudScene, self).__init__(**kwargs) # self.normalize = normalize # heredado # self.adjust = adjust # heredado self.range_in = (0, 100) self.name = name self.formula = Expression.Exponential(rango=self.range_in, normalizar=self.normalize, **kwargs)
def __init__(self, **kwargs): """ Score para el porcentaje de nubes de la escena completa. La band resultante de cualquiera de los metodos tendrá como name 'pnube_es' :param a: valor **a** de la funcion EXPONENCIAL :type a: float :param rango: range de valores entre los que puede oscilar la variable :type rango: tuple :param normalizar: Hacer que el resultado varie entre 0 y 1 independientemente del range :type normalizar: bool """ super(CloudScene, self).__init__(**kwargs) # self.normalize = normalize # heredado # self.adjust = adjust # heredado self.range_in = (0, 100) self.name = kwargs.get("name", "score-cld-esc") self.formula = Expression.Exponential(rango=self.range_in, normalizar=self.normalize, **kwargs)
def __init__(self, rhs): Expression.__init__(self, rhs)
Statement.ebnf( ) EquationArray.ebnf( syntax = ZeroOrMore(Equation.names('equations') + Suppress(";")), action = lambda s,l,t: EquationArray(**dict(t)) ) StatementArray.ebnf( syntax = ZeroOrMore(Statement.names('statements') + Suppress(";")), action = lambda s,l,t: StatementArray(**dict(t)) ) IfEquation.ebnf( syntax =\ Suppress("if") + Expression.name('expressions') + Suppress('then') +\ ZeroOrMore(Equation.ebnf() + Suppress(";")).setResultsName('equations',listAllMatches = True) +\ ZeroOrMore( Suppress("elseif") + Expression.names('expressions') + Suppress('then') + ZeroOrMore(Equation.ebnf() + Suppress(";")).setResultsName('equations',listAllMatches = True)) +\ Optional(Literal("else") + ZeroOrMore(Equation.ebnf() + Suppress(";")).setResultsName('equations', listAllMatches = True)) +\ Literal('end') + Literal("if"), action = lambda s, l, t: IfEquation(expressions = t['expressions'], equations = t['equations']) ) IfStatement.ebnf( syntax = ( Literal("if") + Expression.ebnf().setResultsName('expressions',listAllMatches=True) + Literal('then') + ZeroOrMore(Statement.ebnf() + Suppress(";")).setResultsName('statements',listAllMatches = True) + ZeroOrMore( Literal("elseif") + Expression.ebnf().setResultsName('expressions',listAllMatches=True) + Literal('then') +
import sys import game from expressions import Expression if len(sys.argv) > 1: y = Expression(parse=''.join(sys.argv[1:])) dy = y.differentiate() dy.collect_terms() print(str(dy)) else: game.install_dependencies() import pygame game.play() #game.play((1920, 1080), pygame.FULLSCREEN | pygame.DOUBLEBUF | pygame.HWSURFACE)
def update(self, events, screen, width, height): if not self.closing and not self.opening\ and self.inputbox.update(events) and self.questions[-1]: try: entered = Expression(parse=self.inputbox.get_text()) entered.collect_terms() except: entered = None self.inputbox.clear_text() if entered == self.questions[-1].y_prime: self.score += 1 logger.info(f"Answer correct: y' = {self.questions[-1][1]}") self.questions.append(None) self.next_time = self._make_next_time(self.question_length) logger.info(f'Timer reset to {self.question_length} seconds') self.question_length = max(self.question_length - 0.5, 5) self.audio.zap.play() self.last_correct = datetime.now() else: logger.info(f'Answer incorrect') self.audio.bad.play() if not self.closing and not self.opening and self.next_time < datetime.now(): logger.info(f"Timed out, the correct answer was: y' = {self.questions[-1][1]}") self.closing = True if not self.questions[-1]: self.questions[-1] = self._make_question() logger.info(f'Question presented: y = {self.questions[-1][0]}') half_width = int(width / 2) half_height = int(height / 2 - 1) screen.fill(BACKGROUND_COLOR) now = datetime.now() correct_delta = now - self.last_correct # Draw stars for star in self.stars: star.draw(screen) removeif(lambda x: x.update(width, height, now - self.last_correct), self.stars) # X grid if not self.lines: self.lines.append(HorizontalLine(half_height, width)) self.lines.append(HorizontalLine(half_height + (half_height / 2), width)) self.lines.append(HorizontalLine(half_height + (half_height / 4), width)) self.lines.append(HorizontalLine(half_height + (half_height / 8), width)) for line in self.lines: line.draw(screen) line.update(height, correct_delta) # Y grid for i in range(-width * 100, half_width, 1000): pygame.draw.line(screen, FOREGROUND_COLOR, (half_width, half_height), (i, height)) pygame.draw.line(screen, FOREGROUND_COLOR, (half_width, half_height), (width - i, height)) # Horizon pygame.draw.line(screen, FOREGROUND_COLOR, (0, half_height), (width, half_height)) # Time left bar_length = width if self.opening else width * ( self.next_time - datetime.now()).total_seconds() / self.question_length screen.fill(FOREGROUND_COLOR, pygame.Rect(0, height - 10, int(bar_length), 10)) # Question 'glitchy' text if not self.low_graphics: for i in range(3): ptext.draw(f'y = {self.questions[-1].y}', midtop=(half_width + random.randint(-5, 5), (half_height / 2) + random.randint(-5, 5)), alpha=0.2, fontsize=54, surf=screen) # Question text ptext.draw(f'y = {self.questions[-1].y}', midtop=(half_width, half_height / 2), fontsize=54, surf=screen) # Score text ptext.draw(f'Score: {self.score}', midbottom=(half_width, (half_height / 2) - 10), surf=screen) # Input text intext = self.inputbox.get_surface() screen.blit(intext, intext.get_rect(center=(width / 2, height / 2 - 30))) # Add stars for i in range(int((0.5 if self.low_graphics else 2) * max(4 - correct_delta.total_seconds(), 0))): x_speed = random.uniform(-40, 40) y_speed = random.uniform(2, 10) self.stars.append(Star(half_width, half_height, x_speed, abs(y_speed - abs(x_speed / 2)) + 1, self)) self.fade.blit_onto(screen) if self.opening: self.fade.fade_in() if self.fade.is_complete(True): self.opening = False self.reset_times() elif self.closing: self.fade.fade_out() if self.fade.is_complete(): return GameOverState(self.score, self.questions, self.previous_state, (width, height), self.audio) return self
def _make_question(self): exp = Expression(parse=' + '.join([self._make_question_part() for i in range(3)])) der = exp.differentiate() der.collect_terms() return Question(exp, der)