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)
216.73.216.220
216.73.216.220
216.73.216.220
 
July 18, 2022


A new era ‼

Our infrastructure has recently upgraded ‼

Nugget Communications Bureau 👍

You've never emailed like this before ‼

Roundcube

Webmail software for reading and sending email from @nugget.fun and @shampoo.ooo addresses.

Mailman3

Email discussion lists, modernized with likes and emojis. It can be used for announcements and newsletters in addition to discussions. See lists for Picture Processing or Scrapeboard. Nowadays, people use Discord, but you really don't have to!

FreshRSS

With this hidden in plain sight, old technology, even regular people like you and me can start our own newspaper or social media feed.

Nugget Streaming Media 👍

The content you crave ‼

HLS

A live streaming, video format based on M3U playlists that can be played with HTML5.

RTMP

A plugin for Nginx can receive streaming video from ffmpeg or OBS and forward it as an RTMP stream to sites like Youtube and Twitch or directly to VLC.


Professional ‼

Nugget Productivity Suite 👍

Unleash your potential ‼

Kanboard

Virtual index cards you can use to gamify your daily grind.

Gitea

Grab whatever game code you want, share your edits, and report bugs.

Nugget Security 👍

The real Turing test ‼

Fail2ban

Banning is even more fun when it's automated.

Spamassassin

The documentation explains, "an email which mentions rolex watches, Viagra, porn, and debt all in one" will probably be considered spam.

GoAccess

Display HTTP requests in real time, so you can watch bots try to break into WordPress.

Nugget Entertainment Software 👍

The best in gaming entertainment ‼

Emoticon vs. Rainbow

With everything upgraded to the bleeding edge, this HTML4 game is running better than ever.


Zoom ‼

The game engine I've been working on, SPACE BOX, is now able to export to web, so I'm planning on turning nugget.fun into a games portal by releasing my games on it and adding an accounts system. The upgraded server and software will make it easier to create and maintain. I'm also thinking of using advertising and subscriptions to support the portal, so some of these services, like webmail or the RSS reader, may be offered to accounts that upgrade to a paid subscription.