<commit_before>import collections

from calcium import draw
from calcium.core import CalciumSprite


class InvertScreenEffect:
    @staticmethod
    def process(screen):
        for line in screen.lines:
            for i, pixel in enumerate(line):
                line[i] = 1 - pixel


class HorizontalOffset:
    @staticmethod
    def process(screen, length=10):
        for i, line in enumerate(screen.lines):
            deque = collections.deque(line)
            deque.rotate(length)
            screen.lines[i] = list(deque)


class BorderScreenEffect:
    @staticmethod
    def process(screen):
        rec = draw.rectangle(screen.width, screen.height, fill=False)
        sprite = CalciumSprite(0, 0, {'default': [rec, ]})
        screen.plot(sprite)<commit_msg>#21 - Flash effect<commit_after>"""effects.py is a experimental module for making effects in virtual screen."""
import collections

from calcium import draw
from calcium.core import CalciumSprite
from calcium.core import Timer


class InvertScreenEffect:
    @staticmethod
    def process(screen):
        # benchmark who is more faster
        # screen.lines = [[int(not col) for col in line] for line in screen.lines]
        for line in screen.lines:
            for i, pixel in enumerate(line):
                line[i] = 1 - pixel


class HorizontalOffset:
    @staticmethod
    def process(screen, length=10):
        for i, line in enumerate(screen.lines):
            deque = collections.deque(line)
            deque.rotate(length)
            screen.lines[i] = list(deque)


class BorderScreenEffect:
    @staticmethod
    def process(screen):
        rec = draw.rectangle(screen.width, screen.height, fill=False)
        sprite = CalciumSprite(0, 0, {'default': [rec, ]})
        screen.plot(sprite)


class FlashScreenEffect:
    """Flash/flick the screen in a specific frequency."""

    timer = Timer()
    active = True
    screen = None
    _binded = False
    frequency = 2
    # states: 0 - normal 1 - inverted
    state = 0

    @staticmethod
    def _process():
        if FlashScreenEffect.active:
            # toggle boolean
            FlashScreenEffect.state = int(not FlashScreenEffect.state)

            FlashScreenEffect.timer.after(
                FlashScreenEffect.frequency, FlashScreenEffect._process)

    @staticmethod
    def process(screen, frequency=0.1):
        """Will be called every frame."""
        FlashScreenEffect.screen = screen
        FlashScreenEffect.frequency = frequency

        if not FlashScreenEffect._binded:
            FlashScreenEffect.timer.after(
                frequency, FlashScreenEffect._process)
            FlashScreenEffect._binded = True

        if FlashScreenEffect.state == 1:
            InvertScreenEffect.process(FlashScreenEffect.screen)

        FlashScreenEffect.timer.tick()
{'fraction_non_alphanumeric': 0.08837044892188052, 'fraction_numerical': 0.00671615411806292, 'mean_word_length': 2.5286783042394014, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6673703', 'n_tokens_mistral': 798, 'n_tokens_neox': 746, 'n_words': 213}