from pygame import Surface, Color, Rect
from pygame.time import get_ticks

from ball_cup.pgfw.Animation import Animation

class Charge(Animation, Surface):

    def __init__(self, parent):
        Animation.__init__(self, parent, self.flash)
        self.display_surface = self.get_display_surface()
        self.input = self.get_input()
        self.load_configuration()
        self.register(self.flash, interval=self.interval)
        self.init_surface()
        self.reset()
        self.play()

    def load_configuration(self):
        config = self.get_configuration("charge")
        self.transparent_color = config["transparent-color"]
        self.peak_time = config["peak-time"]
        self.colors = self.build_color_list(config["colors"])
        self.width = config["width"]
        self.interval = config["interval"]
        self.magnitude_range = config["magnitude-range"]

    def build_color_list(self, colors):
        return [Color(color + "FF") for color in colors]

    def init_surface(self):
        Surface.__init__(self, (self.width, self.magnitude_range[1] * 2))
        self.set_colorkey(self.transparent_color)
        self.fill(self.transparent_color)
        rect = self.get_rect()
        rect.centery = self.display_surface.get_rect().centery
        self.rect = rect

    def reset(self):
        self.cancel()
        self.set_strength()
        self.color_index = 0

    def cancel(self):
        self.start = None
        self.fill(self.transparent_color)

    def set_strength(self):
        strength = 0
        if self.start:
            peak = self.peak_time
            elapsed = (get_ticks() - self.start) % peak
            strength = min(1, float(elapsed) / peak)
        self.strength = strength

    def is_charging(self):
        return self.start is not None

    def flash(self):
        if self.is_charging():
            self.increment_color_index()
            self.fill(self.transparent_color)
            self.fill(self.colors[self.color_index], self.get_fill_section())

    def get_fill_section(self):
        lower, upper = self.magnitude_range
        magnitude = self.strength * (upper - lower) + lower
        rect = Rect(0, 0, self.get_width(), magnitude * 2)
        rect.top = self.get_height() / 2 - magnitude
        return rect

    def increment_color_index(self):
        index = self.color_index + 1
        if index >= len(self.colors):
            index = 0
        self.color_index = index

    def update(self):
        self.check_input()
        self.set_strength()
        self.clear()
        Animation.update(self)
        self.draw()

    def check_input(self):
        pressed = self.input.is_command_active("left")
        charging = self.is_charging()
        if not pressed:
            if charging:
                self.release()
        elif pressed and not charging:
            self.hold()

    def release(self):
        self.parent.send()
        self.cancel()

    def hold(self):
        self.start = get_ticks()

    def clear(self):
        self.parent.parent.clear(self.rect)

    def draw(self):
        self.display_surface.blit(self, self.rect)
from ball_cup.pgfw.GameChild import GameChild
from ball_cup.field.scoreboard.Score import Score

class Scoreboard(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.display_surface = self.get_display_surface()
        self.load_configuration()
        self.set_scores()
        self.reset()

    def load_configuration(self):
        config = self.get_configuration("scoreboard")
        self.height = config["height"]
        self.segment_width = config["score-segment-width"]
        self.margin_top = config["margin-top"]
        self.border_width = config["score-border-width"]
        self.border_color = config["score-border-color"]

    def set_scores(self):
        display_surface = self.get_display_surface()
        height = self.height
        segment_width = self.segment_width
        colors = self.parent.result.success_colors
        border_width = self.border_width
        border_color = self.border_color
        centerx = display_surface.get_rect().centerx
        margin = self.margin_top
        self.scores = [Score(self, display_surface, height, segment_width,
                             colors, border_width, border_color, centerx,
                             margin),
                       Score(self, display_surface, height, segment_width,
                             colors, border_width, border_color, centerx,
                             display_surface.get_height() - height - margin)]

    def reset(self):
        for score in self.scores:
            score.reset()

    def refresh(self):
        for score in self.scores:
            score.insert(self.parent.result.color)

    def update(self):
        for score in self.scores:
            score.draw()

    def clear(self):
        for score in self.scores:
            self.parent.clear(score.rect)
from pygame import Surface

from ball_cup.pgfw.GameChild import GameChild

class Score(Surface, GameChild):

    def __init__(self, parent, display_surface, height, segment_width, colors,
                 border_width, border_color, centerx, top):
        GameChild.__init__(self, parent)
        self.display_surface = display_surface
        self.height = height
        self.segment_width = segment_width
        self.colors = colors
        self.border_width = border_width
        self.border_color = border_color
        self.centerx = centerx
        self.top = top
        self.reset()
        self.populate()

    def reset(self):
        counts = []
        for color in self.colors:
            counts.append([color, 0])
        self.draw_counts = counts
        self.populate()

    def populate(self):
        self.init_surface()
        self.fill_borders()
        self.fill_center()

    def init_surface(self):
        Surface.__init__(self, (self.measure_length(),
                                self.height + self.border_width * 2))
        rect = self.get_rect()
        rect.centerx = self.centerx
        rect.top = self.top
        self.rect = rect

    def measure_length(self):
        length = 0
        for color, count in self.draw_counts:
            length += count * self.segment_width
        return length + self.border_width * 2

    def fill_borders(self):
        color = self.border_color
        rect = self.rect
        thickness = self.border_width
        self.fill(color, (0, 0, rect.w, thickness))
        self.fill(color, (rect.w - thickness, 0, thickness, rect.h))
        self.fill(color, (0, rect.h - thickness, rect.w, thickness))
        self.fill(color, (0, 0, thickness, rect.h))

    def fill_center(self):
        offset = self.border_width
        size = self.segment_width / 2, self.get_height() - offset * 2
        right = self.rect.w
        indent = offset
        for color in self.colors:
            for _ in range(self.get_draw_count(color)):
                self.fill(color, ((indent, offset), size))
                self.fill(color, ((right - indent - size[0], offset), size))
                indent += size[0]

    def get_draw_count(self, key):
        for color, count in self.draw_counts:
            if key == color:
                return count

    def insert(self, color):
        counts = self.draw_counts
        for ii in range(len(counts)):
            if counts[ii][0] == color:
                counts[ii][1] += 1
        self.populate()

    def draw(self):
        self.display_surface.blit(self, self.rect)
18.97.14.91
18.97.14.91
18.97.14.91
 
December 3, 2013

Where in the mind's prism does light shine, inward, outward, or backward, and where in a plane does it intersect, experientially and literally, while possessing itself in a dripping wet phantasm?


Fig 1.1 What happens after you turn on a video game and before it appears?

The taxonomy of fun contains the difference between gasps of desperation and exaltation, simultaneously identical and opposite; one inspires you to have sex, while the other to ejaculate perpetually. A destruction and its procession are effervescent, while free play is an inseminated shimmer hatching inside you. Unlikely to be resolved, however, in such a way, are the climaxes of transitions between isolated, consecutive game states.

You walk through a door or long-jump face first (your face, not Mario's) into a painting. A moment passes for eternity, viscerally fading from your ego, corpus, chakra, gaia, the basis of your soul. It happens when you kill too, and especially when you precisely maim or obliterate something. It's a reason to live, a replicating stasis.


Fig 1.2 Sequence in a video game

Video games are death reanimated. You recurse through the underworld toward an illusion. Everything in a decision and logic attaches permanently to your fingerprint. At the core, you use its energy to soar, comatose, back into the biosphere, possibly because the formal structure of a mind by human standards is useful in the next world.