<s> from __future__ import division <EOL> from __future__ import absolute_import <EOL> from __future__ import print_function <EOL> from builtins import chr <EOL> from builtins import object <EOL> from builtins import range <EOL> from future . utils import with_metaclass <EOL> from abc import ABCMeta , abstractmethod , abstractproperty <EOL> from random import randint , random , choice <EOL> from math import sin , cos , pi <EOL> from asciimatics . paths import DynamicPath <EOL> from . screen import Screen <EOL> import datetime <EOL> class Effect ( with_metaclass ( ABCMeta , object ) ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , start_frame = <NUM_LIT:0> , stop_frame = <NUM_LIT:0> , delete_count = None ) : <EOL> """<STR_LIT>""" <EOL> self . _start_frame = start_frame <EOL> self . _stop_frame = stop_frame <EOL> self . _delete_count = delete_count <EOL> self . _scene = None <EOL> def update ( self , frame_no ) : <EOL> """<STR_LIT>""" <EOL> if ( frame_no > self . _start_frame and <EOL> ( self . _stop_frame == <NUM_LIT:0> or frame_no < self . _stop_frame ) ) : <EOL> self . _update ( frame_no ) <EOL> def register_scene ( self , scene ) : <EOL> """<STR_LIT>""" <EOL> self . _scene = scene <EOL> @ abstractmethod <EOL> def reset ( self ) : <EOL> """<STR_LIT>""" <EOL> @ abstractmethod <EOL> def _update ( self , frame_no ) : <EOL> """<STR_LIT>""" <EOL> @ abstractproperty <EOL> def stop_frame ( self ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def delete_count ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _delete_count <EOL> @ delete_count . setter <EOL> def delete_count ( self , value ) : <EOL> self . _delete_count = value <EOL> def process_event ( self , event ) : <EOL> """<STR_LIT>""" <EOL> return event <EOL> class Scroll ( Effect ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , screen , rate , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( Scroll , self ) . __init__ ( ** kwargs ) <EOL> self . _screen = screen <EOL> self . _rate = rate <EOL> self . _last_frame = None <EOL> def reset ( self ) : <EOL> self . _last_frame = <NUM_LIT:0> <EOL> def _update ( self , frame_no ) : <EOL> if ( frame_no - self . _last_frame ) >= self . _rate : <EOL> self . _screen . scroll ( ) <EOL> self . _last_frame = frame_no <EOL> @ property <EOL> def stop_frame ( self ) : <EOL> return <NUM_LIT:0> <EOL> class Cycle ( Effect ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , screen , renderer , y , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( Cycle , self ) . __init__ ( ** kwargs ) <EOL> self . _screen = screen <EOL> self . _renderer = renderer <EOL> self . _y = y <EOL> self . _colour = <NUM_LIT:0> <EOL> def reset ( self ) : <EOL> pass <EOL> def _update ( self , frame_no ) : <EOL> if frame_no % <NUM_LIT:2> == <NUM_LIT:0> : <EOL> return <EOL> y = self . _y <EOL> image , _ = self . _renderer . rendered_text <EOL> for line in image : <EOL> if self . _screen . is_visible ( <NUM_LIT:0> , y ) : <EOL> self . _screen . centre ( line , y , self . _colour ) <EOL> y += <NUM_LIT:1> <EOL> self . _colour = ( self . _colour + <NUM_LIT:1> ) % <NUM_LIT:8> <EOL> @ property <EOL> def stop_frame ( self ) : <EOL> return <NUM_LIT:0> <EOL> class BannerText ( Effect ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , screen , renderer , y , colour , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( BannerText , self ) . __init__ ( ** kwargs ) <EOL> self . _screen = screen <EOL> self . _renderer = renderer <EOL> self . _y = y <EOL> self . _colour = colour <EOL> self . _text_pos = None <EOL> self . _scr_pos = None <EOL> def reset ( self ) : <EOL> self . _text_pos = <NUM_LIT:0> <EOL> self . _scr_pos = self . _screen . width <EOL> def _update ( self , frame_no ) : <EOL> if self . _scr_pos == <NUM_LIT:0> and self . _text_pos < self . _renderer . max_width : <EOL> self . _text_pos += <NUM_LIT:1> <EOL> if self . _scr_pos > <NUM_LIT:0> : <EOL> self . _scr_pos -= <NUM_LIT:1> <EOL> image , colours = self . _renderer . rendered_text <EOL> for ( i , line ) in enumerate ( image ) : <EOL> line += "<STR_LIT:U+0020>" <EOL> colours [ i ] . append ( ( None , None ) ) <EOL> end_pos = min ( <EOL> len ( line ) , <EOL> self . _text_pos + self . _screen . width - self . _scr_pos - <NUM_LIT:1> ) <EOL> self . _screen . paint ( line [ self . _text_pos : end_pos ] , <EOL> self . _scr_pos , <EOL> self . _y + i , <EOL> self . _colour , <EOL> colour_map = colours [ i ] [ self . _text_pos : end_pos ] ) <EOL> @ property <EOL> def stop_frame ( self ) : <EOL> return self . _start_frame + self . _renderer . max_width + self . _screen . width <EOL> class Print ( Effect ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , screen , renderer , y , x = None , colour = <NUM_LIT:7> , attr = <NUM_LIT:0> , bg = <NUM_LIT:0> , <EOL> clear = False , transparent = True , speed = <NUM_LIT:4> , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( Print , self ) . __init__ ( ** kwargs ) <EOL> self . _screen = screen <EOL> self . _renderer = renderer <EOL> self . _transparent = transparent <EOL> self . _y = y <EOL> self . _x = ( ( self . _screen . width - renderer . max_width ) // <NUM_LIT:2> if x is None <EOL> else x ) <EOL> self . _colour = colour <EOL> self . _attr = attr <EOL> self . _bg = bg <EOL> self . _clear = clear <EOL> self . _speed = speed <EOL> self . _frame_no = <NUM_LIT:0> <EOL> def reset ( self ) : <EOL> pass <EOL> def _update ( self , frame_no ) : <EOL> self . _frame_no = frame_no <EOL> if self . _clear and ( frame_no == self . _stop_frame - <NUM_LIT:1> ) or ( self . _delete_count == <NUM_LIT:1> ) : <EOL> for i in range ( <NUM_LIT:0> , self . _renderer . max_height ) : <EOL> self . _screen . print_at ( "<STR_LIT:U+0020>" * self . _renderer . max_width , <EOL> self . _x , <EOL> self . _y + i , <EOL> bg = self . _bg ) <EOL> elif frame_no % self . _speed == <NUM_LIT:0> : <EOL> image , colours = self . _renderer . rendered_text <EOL> for ( i , line ) in enumerate ( image ) : <EOL> self . _screen . paint ( line , self . _x , self . _y + i , self . _colour , <EOL> attr = self . _attr , <EOL> bg = self . _bg , <EOL> transparent = self . _transparent , <EOL> colour_map = colours [ i ] ) <EOL> @ property <EOL> def stop_frame ( self ) : <EOL> return self . _stop_frame <EOL> class Mirage ( Effect ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , screen , renderer , y , colour , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( Mirage , self ) . __init__ ( ** kwargs ) <EOL> self . _screen = screen <EOL> self . _renderer = renderer <EOL> self . _y = y <EOL> self . _colour = colour <EOL> def reset ( self ) : <EOL> pass <EOL> def _update ( self , frame_no ) : <EOL> if frame_no % <NUM_LIT:2> == <NUM_LIT:0> : <EOL> return <EOL> y = self . _y <EOL> image , colours = self . _renderer . rendered_text <EOL> for i , line in enumerate ( image ) : <EOL> if self . _screen . is_visible ( <NUM_LIT:0> , y ) : <EOL> x = ( self . _screen . width - len ( line ) ) // <NUM_LIT:2> <EOL> for j , c in enumerate ( line ) : <EOL> if c != "<STR_LIT:U+0020>" and random ( ) > <NUM_LIT> : <EOL> if colours [ i ] [ j ] [ <NUM_LIT:0> ] is not None : <EOL> self . _screen . print_at ( c , x , y , <EOL> colours [ i ] [ j ] [ <NUM_LIT:0> ] , <EOL> colours [ i ] [ j ] [ <NUM_LIT:1> ] ) <EOL> else : <EOL> self . _screen . print_at ( c , x , y , self . _colour ) <EOL> x += <NUM_LIT:1> <EOL> y += <NUM_LIT:1> <EOL> @ property <EOL> def stop_frame ( self ) : <EOL> return self . _stop_frame <EOL> class _Star ( object ) : <EOL> """<STR_LIT>""" <EOL> _star_chars = "<STR_LIT>" <EOL> def __init__ ( self , screen ) : <EOL> """<STR_LIT>""" <EOL> self . _screen = screen <EOL> self . _cycle = None <EOL> self . _old_char = None <EOL> self . _respawn ( ) <EOL> def _respawn ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _cycle = randint ( <NUM_LIT:0> , len ( self . _star_chars ) ) <EOL> ( height , width ) = self . _screen . dimensions <EOL> while True : <EOL> self . _x = randint ( <NUM_LIT:0> , width - <NUM_LIT:1> ) <EOL> self . _y = randint ( <NUM_LIT:0> , height - <NUM_LIT:1> ) <EOL> if self . _screen . get_from ( self . _x , self . _y ) [ <NUM_LIT:0> ] == <NUM_LIT:32> : <EOL> break <EOL> self . _old_char = "<STR_LIT:U+0020>" <EOL> def update ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _screen . is_visible ( self . _x , self . _y ) : <EOL> self . _respawn ( ) <EOL> cur_char , _ , _ , _ = self . _screen . get_from ( self . _x , self . _y ) <EOL> if cur_char not in ( ord ( self . _old_char ) , <NUM_LIT:32> ) : <EOL> self . _respawn ( ) <EOL> self . _cycle += <NUM_LIT:1> <EOL> if self . _cycle >= len ( self . _star_chars ) : <EOL> self . _cycle = <NUM_LIT:0> <EOL> new_char = self . _star_chars [ self . _cycle ] <EOL> if new_char == self . _old_char : <EOL> return <EOL> self . _screen . print_at ( new_char , self . _x , self . _y ) <EOL> self . _old_char = new_char <EOL> class Stars ( Effect ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , screen , count , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( Stars , self ) . __init__ ( ** kwargs ) <EOL> self . _screen = screen <EOL> self . _max = count <EOL> self . _stars = [ ] <EOL> def reset ( self ) : <EOL> self . _stars = [ _Star ( self . _screen ) for _ in range ( self . _max ) ] <EOL> def _update ( self , frame_no ) : <EOL> for star in self . _stars : <EOL> star . update ( ) <EOL> @ property <EOL> def stop_frame ( self ) : <EOL> return <NUM_LIT:0> <EOL> class _Trail ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , screen , x ) : <EOL> """<STR_LIT>""" <EOL> self . _screen = screen <EOL> self . _x = x <EOL> self . _y = <NUM_LIT:0> <EOL> self . _life = <NUM_LIT:0> <EOL> self . _rate = <NUM_LIT:0> <EOL> self . _clear = True <EOL> self . _maybe_reseed ( True ) <EOL> def _maybe_reseed ( self , normal ) : <EOL> """<STR_LIT>""" <EOL> self . _y += self . _rate <EOL> self . _life -= <NUM_LIT:1> <EOL> if self . _life <= <NUM_LIT:0> : <EOL> self . _clear = not self . _clear if normal else True <EOL> self . _rate = randint ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> if self . _clear : <EOL> self . _y = <NUM_LIT:0> <EOL> self . _life = self . _screen . height // self . _rate <EOL> else : <EOL> self . _y = randint ( <NUM_LIT:0> , self . _screen . height // <NUM_LIT:2> ) - self . _screen . height // <NUM_LIT:4> <EOL> self . _life = randint ( <NUM_LIT:1> , self . _screen . height - self . _y ) // self . _rate <EOL> def update ( self , reseed ) : <EOL> """<STR_LIT>""" <EOL> if self . _clear : <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:3> ) : <EOL> self . _screen . print_at ( "<STR_LIT:U+0020>" , <EOL> self . _x , <EOL> self . _screen . start_line + self . _y + i ) <EOL> self . _maybe_reseed ( reseed ) <EOL> else : <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:3> ) : <EOL> self . _screen . print_at ( chr ( randint ( <NUM_LIT:32> , <NUM_LIT> ) ) , <EOL> self . _x , <EOL> self . _screen . start_line + self . _y + i , <EOL> Screen . COLOUR_GREEN ) <EOL> for i in range ( <NUM_LIT:4> , <NUM_LIT:6> ) : <EOL> self . _screen . print_at ( chr ( randint ( <NUM_LIT:32> , <NUM_LIT> ) ) , <EOL> self . _x , <EOL> self . _screen . start_line + self . _y + i , <EOL> Screen . COLOUR_GREEN , <EOL> Screen . A_BOLD ) <EOL> self . _maybe_reseed ( reseed ) <EOL> class Matrix ( Effect ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , screen , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( Matrix , self ) . __init__ ( ** kwargs ) <EOL> self . _screen = screen <EOL> self . _chars = [ ] <EOL> def reset ( self ) : <EOL> self . _chars = [ _Trail ( self . _screen , x ) for x in <EOL> range ( self . _screen . width ) ] <EOL> def _update ( self , frame_no ) : <EOL> if frame_no % <NUM_LIT:2> == <NUM_LIT:0> : <EOL> for char in self . _chars : <EOL> char . update ( ( self . _stop_frame == <NUM_LIT:0> ) or ( <EOL> self . _stop_frame - frame_no > <NUM_LIT:100> ) ) <EOL> @ property <EOL> def stop_frame ( self ) : <EOL> return self . _stop_frame <EOL> class Wipe ( Effect ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , screen , bg = <NUM_LIT:0> , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( Wipe , self ) . __init__ ( ** kwargs ) <EOL> self . _screen = screen <EOL> self . _bg = bg <EOL> self . _y = None <EOL> def reset ( self ) : <EOL> self . _y = <NUM_LIT:0> <EOL> def _update ( self , frame_no ) : <EOL> if frame_no % <NUM_LIT:2> == <NUM_LIT:0> : <EOL> if self . _screen . is_visible ( <NUM_LIT:0> , self . _y ) : <EOL> self . _screen . print_at ( <EOL> "<STR_LIT:U+0020>" * self . _screen . width , <NUM_LIT:0> , self . _y , bg = self . _bg ) <EOL> self . _y += <NUM_LIT:1> <EOL> @ property <EOL> def stop_frame ( self ) : <EOL> return self . _stop_frame <EOL> class Sprite ( Effect ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , screen , renderer_dict , path , colour = Screen . COLOUR_WHITE , <EOL> clear = True , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( Sprite , self ) . __init__ ( ** kwargs ) <EOL> self . _screen = screen <EOL> self . _renderer_dict = renderer_dict <EOL> self . _path = path <EOL> self . _index = None <EOL> self . _colour = colour <EOL> self . _clear = clear <EOL> self . _old_height = None <EOL> self . _old_width = None <EOL> self . _old_x = None <EOL> self . _old_y = None <EOL> self . _dir_count = <NUM_LIT:0> <EOL> self . _dir_x = None <EOL> self . _dir_y = None <EOL> self . _old_direction = None <EOL> self . reset ( ) <EOL> def reset ( self ) : <EOL> self . _dir_count = <NUM_LIT:0> <EOL> self . _dir_x = None <EOL> self . _dir_y = None <EOL> self . _old_direction = None <EOL> self . _path . reset ( ) <EOL> def last_position ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _old_x , self . _old_y , self . _old_width , self . _old_height <EOL> def overlaps ( self , other , use_new_pos = False ) : <EOL> """<STR_LIT>""" <EOL> ( x , y ) = self . _path . next_pos ( ) if use_new_pos else ( self . _old_x , <EOL> self . _old_y ) <EOL> w = self . _old_width <EOL> h = self . _old_height <EOL> x2 , y2 , w2 , h2 = other . last_position ( ) <EOL> if ( ( x > x2 + w2 - <NUM_LIT:1> ) or ( x2 > x + w - <NUM_LIT:1> ) or <EOL> ( y > y2 + h2 - <NUM_LIT:1> ) or ( y2 > y + h - <NUM_LIT:1> ) ) : <EOL> return False <EOL> else : <EOL> return True <EOL> def _update ( self , frame_no ) : <EOL> if frame_no % <NUM_LIT:2> == <NUM_LIT:0> : <EOL> if ( self . _clear and <EOL> self . _old_x is not None and self . _old_y is not None ) : <EOL> for i in range ( <NUM_LIT:0> , self . _old_height ) : <EOL> self . _screen . print_at ( <EOL> "<STR_LIT:U+0020>" * self . _old_width , self . _old_x , self . _old_y + i , <NUM_LIT:0> ) <EOL> if self . _delete_count is not None and self . _delete_count <= <NUM_LIT:2> : <EOL> return <EOL> ( x , y ) = self . _path . next_pos ( ) <EOL> if self . _dir_count % <NUM_LIT:3> == <NUM_LIT:0> : <EOL> direction = None <EOL> if self . _dir_x is not None : <EOL> dx = ( x - self . _dir_x ) // <NUM_LIT:2> <EOL> dy = y - self . _dir_y <EOL> if dx * dx > dy * dy : <EOL> direction = "<STR_LIT:left>" if dx < <NUM_LIT:0> else "<STR_LIT:right>" <EOL> elif dx == <NUM_LIT:0> and dy == <NUM_LIT:0> : <EOL> direction = "<STR_LIT:default>" <EOL> else : <EOL> direction = "<STR_LIT>" if dy < <NUM_LIT:0> else "<STR_LIT>" <EOL> self . _dir_x = x <EOL> self . _dir_y = y <EOL> else : <EOL> direction = self . _old_direction <EOL> self . _dir_count += <NUM_LIT:1> <EOL> if direction not in self . _renderer_dict : <EOL> direction = "<STR_LIT:default>" <EOL> x -= self . _renderer_dict [ direction ] . max_width // <NUM_LIT:2> <EOL> y -= self . _renderer_dict [ direction ] . max_height // <NUM_LIT:2> <EOL> if self . _path . is_finished ( ) : <EOL> self . _path . reset ( ) <EOL> image , colours = self . _renderer_dict [ direction ] . rendered_text <EOL> for ( i , line ) in enumerate ( image ) : <EOL> self . _screen . paint ( line , x , y + i , self . _colour , <EOL> colour_map = colours [ i ] ) <EOL> self . _old_width = self . _renderer_dict [ direction ] . max_width <EOL> self . _old_height = self . _renderer_dict [ direction ] . max_height <EOL> self . _old_direction = direction <EOL> self . _old_x = x <EOL> self . _old_y = y <EOL> @ property <EOL> def stop_frame ( self ) : <EOL> return self . _stop_frame <EOL> def process_event ( self , event ) : <EOL> if isinstance ( self . _path , DynamicPath ) : <EOL> return self . _path . process_event ( event ) <EOL> else : <EOL> return event <EOL> class _Flake ( object ) : <EOL> """<STR_LIT>""" <EOL> _snow_chars = "<STR_LIT>" <EOL> _drift_chars = "<STR_LIT>" <EOL> def __init__ ( self , screen ) : <EOL> """<STR_LIT>""" <EOL> self . _screen = screen <EOL> self . _x = <NUM_LIT:0> <EOL> self . _y = <NUM_LIT:0> <EOL> self . _rate = <NUM_LIT:0> <EOL> self . _char = None <EOL> self . _reseed ( ) <EOL> def _reseed ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _char = choice ( self . _snow_chars ) <EOL> self . _rate = randint ( <NUM_LIT:1> , <NUM_LIT:3> ) <EOL> self . _x = randint ( <NUM_LIT:0> , self . _screen . width - <NUM_LIT:1> ) <EOL> self . _y = self . _screen . start_line + randint ( <NUM_LIT:0> , self . _rate ) <EOL> def update ( self , reseed ) : <EOL> """<STR_LIT>""" <EOL> self . _screen . print_at ( "<STR_LIT:U+0020>" , self . _x , self . _y ) <EOL> current_char = None <EOL> for _ in range ( self . _rate ) : <EOL> self . _y += <NUM_LIT:1> <EOL> current_char , _ , _ , _ = self . _screen . get_from ( self . _x , self . _y ) <EOL> if current_char != <NUM_LIT:32> : <EOL> break <EOL> if ( ( current_char in [ ord ( x ) for x in self . _snow_chars + "<STR_LIT:U+0020>" ] ) and <EOL> ( self . _y < self . _screen . start_line + self . _screen . height ) ) : <EOL> self . _screen . print_at ( self . _char , <EOL> self . _x , <EOL> self . _y ) <EOL> else : <EOL> if self . _y >= self . _screen . start_line + self . _screen . height : <EOL> self . _y = self . _screen . start_line + self . _screen . height - <NUM_LIT:1> <EOL> drift_index = self . _drift_chars . find ( chr ( current_char ) ) <EOL> if <NUM_LIT:0> <= drift_index < len ( self . _drift_chars ) - <NUM_LIT:1> : <EOL> drift_char = self . _drift_chars [ drift_index + <NUM_LIT:1> ] <EOL> self . _screen . print_at ( drift_char , self . _x , self . _y ) <EOL> else : <EOL> self . _screen . print_at ( "<STR_LIT:U+002C>" , self . _x , self . _y - <NUM_LIT:1> ) <EOL> if reseed : <EOL> self . _reseed ( ) <EOL> class Snow ( Effect ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , screen , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( Snow , self ) . __init__ ( ** kwargs ) <EOL> self . _screen = screen <EOL> self . _chars = [ ] <EOL> def reset ( self ) : <EOL> self . _chars = [ ] <EOL> def _update ( self , frame_no ) : <EOL> if frame_no % <NUM_LIT:3> == <NUM_LIT:0> : <EOL> if len ( self . _chars ) < self . _screen . width // <NUM_LIT:3> : <EOL> self . _chars . append ( _Flake ( self . _screen ) ) <EOL> for char in self . _chars : <EOL> char . update ( ( self . _stop_frame == <NUM_LIT:0> ) or ( <EOL> self . _stop_frame - frame_no > <NUM_LIT:100> ) ) <EOL> @ property <EOL> def stop_frame ( self ) : <EOL> return self . _stop_frame <EOL> class Clock ( Effect ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , screen , x , y , r , bg = Screen . COLOUR_BLACK , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( Clock , self ) . __init__ ( ** kwargs ) <EOL> self . _screen = screen <EOL> self . _x = x <EOL> self . _y = y <EOL> self . _r = r <EOL> self . _bg = bg <EOL> self . _old_time = None <EOL> def reset ( self ) : <EOL> pass <EOL> def _update ( self , frame_no ) : <EOL> def _hour_pos ( t ) : <EOL> return ( t . tm_hour + t . tm_min / <NUM_LIT> ) * pi / <NUM_LIT:6> <EOL> def _min_pos ( t ) : <EOL> return t . tm_min * pi / <NUM_LIT:30> <EOL> def _sec_pos ( t ) : <EOL> return t . tm_sec * pi / <NUM_LIT:30> <EOL> if self . _old_time is not None : <EOL> ot = self . _old_time <EOL> self . _screen . move ( self . _x , self . _y ) <EOL> self . _screen . draw ( self . _x + ( self . _r * sin ( _hour_pos ( ot ) ) ) , <EOL> self . _y - ( self . _r * cos ( _hour_pos ( ot ) ) / <NUM_LIT:2> ) , <EOL> char = "<STR_LIT:U+0020>" , bg = self . _bg ) <EOL> self . _screen . move ( self . _x , self . _y ) <EOL> self . _screen . draw ( self . _x + ( self . _r * sin ( _min_pos ( ot ) ) * <NUM_LIT:2> ) , <EOL> self . _y - ( self . _r * cos ( _min_pos ( ot ) ) ) , <EOL> char = "<STR_LIT:U+0020>" , bg = self . _bg ) <EOL> self . _screen . move ( self . _x , self . _y ) <EOL> self . _screen . draw ( self . _x + ( self . _r * sin ( _sec_pos ( ot ) ) * <NUM_LIT:2> ) , <EOL> self . _y - ( self . _r * cos ( _sec_pos ( ot ) ) ) , <EOL> char = "<STR_LIT:U+0020>" , bg = self . _bg ) <EOL> new_time = datetime . datetime . now ( ) . timetuple ( ) <EOL> self . _screen . move ( self . _x , self . _y ) <EOL> self . _screen . draw ( self . _x + ( self . _r * sin ( _hour_pos ( new_time ) ) ) , <EOL> self . _y - ( self . _r * cos ( _hour_pos ( new_time ) ) / <NUM_LIT:2> ) , <EOL> colour = Screen . COLOUR_WHITE , bg = self . _bg ) <EOL> self . _screen . move ( self . _x , self . _y ) <EOL> self . _screen . draw ( self . _x + ( self . _r * sin ( _min_pos ( new_time ) ) * <NUM_LIT:2> ) , <EOL> self . _y - ( self . _r * cos ( _min_pos ( new_time ) ) ) , <EOL> colour = Screen . COLOUR_WHITE , bg = self . _bg ) <EOL> self . _screen . move ( self . _x , self . _y ) <EOL> self . _screen . draw ( self . _x + ( self . _r * sin ( _sec_pos ( new_time ) ) * <NUM_LIT:2> ) , <EOL> self . _y - ( self . _r * cos ( _sec_pos ( new_time ) ) ) , <EOL> colour = Screen . COLOUR_CYAN , bg = self . _bg , thin = True ) <EOL> self . _screen . print_at ( "<STR_LIT:o>" , self . _x , self . _y , Screen . COLOUR_YELLOW , <EOL> Screen . A_BOLD , bg = self . _bg ) <EOL> self . _old_time = new_time <EOL> @ property <EOL> def stop_frame ( self ) : <EOL> return self . _stop_frame <EOL> class Cog ( Effect ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , screen , x , y , radius , direction = <NUM_LIT:1> , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( Cog , self ) . __init__ ( ** kwargs ) <EOL> self . _screen = screen <EOL> self . _x = x <EOL> self . _y = y <EOL> self . _radius = radius <EOL> self . _old_frame = <NUM_LIT:0> <EOL> self . _rate = <NUM_LIT:2> <EOL> self . _direction = direction <EOL> def reset ( self ) : <EOL> pass <EOL> def _update ( self , frame_no ) : <EOL> if frame_no % self . _rate != <NUM_LIT:0> : <EOL> return <EOL> def f ( p ) : <EOL> return self . _x + ( self . _radius * <NUM_LIT:2> - ( <NUM_LIT:6> * ( p // <NUM_LIT:4> % <NUM_LIT:2> ) ) ) * sin ( <EOL> ( self . _old_frame + p ) * pi / <NUM_LIT> ) <EOL> def g ( p ) : <EOL> return self . _y + ( self . _radius - ( <NUM_LIT:3> * ( p // <NUM_LIT:4> % <NUM_LIT:2> ) ) ) * cos ( <EOL> ( self . _old_frame + p ) * pi / <NUM_LIT> ) <EOL> if self . _old_frame != <NUM_LIT:0> : <EOL> self . _screen . move ( f ( <NUM_LIT:0> ) , g ( <NUM_LIT:0> ) ) <EOL> for x in range ( <NUM_LIT> ) : <EOL> self . _screen . draw ( f ( x ) , g ( x ) , char = "<STR_LIT:U+0020>" ) <EOL> self . _old_frame += self . _direction <EOL> self . _screen . move ( f ( <NUM_LIT:0> ) , g ( <NUM_LIT:0> ) ) <EOL> for x in range ( <NUM_LIT> ) : <EOL> self . _screen . draw ( f ( x ) , g ( x ) ) <EOL> @ property <EOL> def stop_frame ( self ) : <EOL> return self . _stop_frame <EOL> class RandomNoise ( Effect ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , screen , signal = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( RandomNoise , self ) . __init__ ( ** kwargs ) <EOL> self . _screen = screen <EOL> self . _signal = signal <EOL> self . _strength = <NUM_LIT:0.0> <EOL> self . _step = None <EOL> def reset ( self ) : <EOL> self . _strength = <NUM_LIT:0.0> <EOL> self . _step = - <NUM_LIT> <EOL> def _update ( self , frame_no ) : <EOL> if self . _signal : <EOL> start_x = int ( ( self . _screen . width - self . _signal . max_width ) // <NUM_LIT:2> ) <EOL> start_y = int ( ( self . _screen . height - self . _signal . max_height ) // <NUM_LIT:2> ) <EOL> text , colours = self . _signal . rendered_text <EOL> else : <EOL> start_x = start_y = <NUM_LIT:0> <EOL> text , colours = "<STR_LIT>" , [ ] <EOL> for y in range ( self . _screen . height ) : <EOL> if self . _strength < <NUM_LIT:1.0> : <EOL> offset = randint ( <NUM_LIT:0> , int ( <NUM_LIT:6> - <NUM_LIT:6> * self . _strength ) ) <EOL> else : <EOL> offset = <NUM_LIT:0> <EOL> for x in range ( self . _screen . width ) : <EOL> ix = x - start_x <EOL> iy = y - start_y <EOL> if ( self . _signal and random ( ) <= self . _strength and <EOL> x >= start_x and y >= start_y and <EOL> iy < len ( text ) and ix + offset < len ( text [ iy ] ) ) : <EOL> self . _screen . paint ( text [ iy ] [ ix + offset ] , <EOL> x , y , <EOL> colour_map = [ colours [ iy ] [ ix ] ] ) <EOL> else : <EOL> if random ( ) < <NUM_LIT> : <EOL> self . _screen . print_at ( chr ( randint ( <NUM_LIT> , <NUM_LIT> ) ) , x , y ) <EOL> self . _strength += self . _step <EOL> if self . _strength >= <NUM_LIT> or self . _strength <= - <NUM_LIT:0.5> : <EOL> self . _step = - self . _step <EOL> @ property <EOL> def stop_frame ( self ) : <EOL> return self . _stop_frame <EOL> class Julia ( Effect ) : <EOL> """<STR_LIT>""" <EOL> _greyscale = '<STR_LIT>' <EOL> _256_palette = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:50> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT:200> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> ] <EOL> def __init__ ( self , screen , c = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( Julia , self ) . __init__ ( ** kwargs ) <EOL> self . _screen = screen <EOL> self . _width = screen . width <EOL> self . _height = screen . height <EOL> self . _centre = [ <NUM_LIT:0.0> , <NUM_LIT:0.0> ] <EOL> self . _size = [ <NUM_LIT> , <NUM_LIT> ] <EOL> self . _min_x = self . _min_y = - <NUM_LIT> <EOL> self . _max_x = self . _max_y = <NUM_LIT> <EOL> self . _c = c if c is not None else [ - <NUM_LIT> , <NUM_LIT> ] <EOL> self . _scale = <NUM_LIT> <EOL> def reset ( self ) : <EOL> pass <EOL> def _update ( self , frame_no ) : <EOL> c = complex ( self . _c [ <NUM_LIT:0> ] , self . _c [ <NUM_LIT:1> ] ) <EOL> sx = self . _centre [ <NUM_LIT:0> ] - ( self . _size [ <NUM_LIT:0> ] / <NUM_LIT> ) <EOL> sy = self . _centre [ <NUM_LIT:1> ] - ( self . _size [ <NUM_LIT:1> ] / <NUM_LIT> ) <EOL> for y in range ( self . _height ) : <EOL> for x in range ( self . _width ) : <EOL> z = complex ( sx + self . _size [ <NUM_LIT:0> ] * ( x / self . _width ) , <EOL> sy + self . _size [ <NUM_LIT:1> ] * ( y / self . _height ) ) <EOL> n = len ( self . _256_palette ) <EOL> while abs ( z ) < <NUM_LIT:10> and n >= <NUM_LIT:1> : <EOL> z = z ** <NUM_LIT:2> + c <EOL> n -= <NUM_LIT:1> <EOL> colour = self . _256_palette [ <EOL> n - <NUM_LIT:1> ] if self . _screen . colours >= <NUM_LIT> else <NUM_LIT:7> <EOL> self . _screen . print_at ( self . _greyscale [ n - <NUM_LIT:1> ] , x , y , colour ) <EOL> self . _size = [ i * self . _scale for i in self . _size ] <EOL> area = self . _size [ <NUM_LIT:0> ] * self . _size [ <NUM_LIT:1> ] <EOL> if area <= <NUM_LIT> or area >= <NUM_LIT:16> : <EOL> self . _scale = <NUM_LIT:1.0> / self . _scale <EOL> self . _c = [ self . _c [ <NUM_LIT:0> ] * cos ( pi / <NUM_LIT> ) - self . _c [ <NUM_LIT:1> ] * sin ( pi / <NUM_LIT> ) , <EOL> self . _c [ <NUM_LIT:0> ] * sin ( pi / <NUM_LIT> ) + self . _c [ <NUM_LIT:1> ] * cos ( pi / <NUM_LIT> ) ] <EOL> @ property <EOL> def stop_frame ( self ) : <EOL> return self . _stop_frame </s>
