Skip to content

Commit

Permalink
reverts lates changes beginning from 7569a4b
Browse files Browse the repository at this point in the history
  • Loading branch information
nitram509 committed Jun 6, 2019
1 parent 8160654 commit 930aa00
Show file tree
Hide file tree
Showing 20 changed files with 219 additions and 164,773 deletions.
5 changes: 1 addition & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
.idea
.cache
.gitignore
.dockerignore
.travis.yml
dev_requirements.txt
screenshots
Dockerfile
tests
Dockerfile
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
# command to install dependencies
install: "pip install -r dev_requirements.txt"
# command to run tests
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM python:3.7-alpine

ENV mode stdout
ENV input_file movies/short_intro.txt
ENV input_file sample_movies/short_intro.txt

RUN mkdir /app
WORKDIR /app
Expand Down
41 changes: 8 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ Original art work : Simon Jansen [http://www.asciimation.co.nz/](http://www.asci
Telnetification & Player coding : Martin W. Kirst
Python3 Update: Ryan Jarvis
Dockerfile contributed by: Manuel Eusebio de Paz Carmona
The asciimation of the video Big Apple contributed by @ZenithalHourlyRate

Available movies
----------------

See

Command line parameters
-----------------------
Expand All @@ -31,7 +25,6 @@ See program output:

$ python ascii_telnet_server.py --help
Usage: ascii_telnet_server.py [options]

Options:
-h, --help show this help message and exit
--standalone Run as stand alone multi threaded TCP server (default)
Expand All @@ -45,29 +38,14 @@ See program output:
-p PORT, --port=PORT Bind to this port (default 23, Telnet)
-v, --verbose Verbose (default for TCP server)
-q, --quiet Quiet! (default for STDIN STDOUT server)
-r FPS, --framerate=FPS
Set the framerate of the movie (default 24)
-s WIDTHxHEIGHT, --screen_size=WIDTHxHEIGHT
Set the screen size of the movie (default 80x24).
Including the timeline, so the maximum frame size is
WIDTHx(HEIGHT-1) (default maximum 80x23)
-S FRAME_WIDTHxFRAME_HEIGHT, --frame_size=FRAME_WIDTHxFRAME_HEIGHT
Set the movie's frame size (depending on the movie you
are to play) (default 67x13)

Run as stdout local player
--------------------------

Simply call this Python script by using the sample movie file:

$> python ascii_telnet_server.py --stdout -f ./movies/sw1.txt

Run as stand alone server
-------------------------

Simply call this Python script by using the sample movie file:
Simple call this Python script by using the sample movie file:

$> python ascii_telnet_server.py --standalone -f ./movies/sw1.txt
$> python ascii_telnet_server.py --standalone -f ../sample_movies/sw1.txt
Running TCP server on 0.0.0.0:23
Playing movie sw1.txt

Expand All @@ -79,21 +57,18 @@ Simply build & run the container and use the movie file as environment parameter
# Build image:
$> docker build -t ascii-art-movie-telnet-player .

# MODE STDOUT: Run as local player

## MODE STDOUT

# Run as local player with the default movie
$> docker run -it --rm ascii-art-movie-telnet-player
# with the default movie
$> docker run -it --rm -e mode=stdout ascii-art-movie-telnet-player

# with a custom movie file.txt (absolute path to file it's required):
$> docker run -it --rm -v $(pwd)/your_movie.txt:/app/input_file.txt -e input_file=input_file.txt ascii-art-movie-telnet-player

# MODE STANDALONE: Run as local telnet server
# To test, open a telnet client in other terminal/session i.e. $> telnet localhost 23

## MODE STANDALONE:

# Run as local telnet server to test,
# open a telnet client in other terminal/session i.e. $> telnet localhost 23
# (with the default movie)
# with the default movie
$> docker run -it --rm -p 23:23 -e mode=standalone ascii-art-movie-telnet-player

# Run with custon input_file.txt movie
Expand Down
77 changes: 62 additions & 15 deletions ascii_telnet/ascii_movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

from __future__ import division, print_function


class Frame(object):
def __init__(self, display_time=1):
Expand Down Expand Up @@ -78,7 +80,7 @@ def _empty_timebar(self):

return u"{tb.left_decorator}{internals}{tb.right_decorator}".format(internals=time_bar_internals, tb=self)

def get_marker_position(self, frame_num):
def get_marker_postion(self, frame_num):
"""
Return the index for the marker position on the TimeBar's internal length
Args:
Expand All @@ -88,6 +90,7 @@ def get_marker_position(self, frame_num):
int: index number for marker
"""

return int(round(self.internal_length / self.duration * frame_num, 0))

def get_timebar(self, frame_num):
Expand All @@ -99,7 +102,7 @@ def get_timebar(self, frame_num):
str: String representation of the TimeBar at the given Frame Number
Example: "< o >"
"""
marker_pos = self.get_marker_position(frame_num)
marker_pos = self.get_marker_postion(frame_num)

if marker_pos >= self.internal_length:
# Make sure we never overwrite the end decorator.
Expand All @@ -111,29 +114,73 @@ def get_timebar(self, frame_num):


class Movie(object):
# TODO: screen width and height should be derived from frame size per default, no need for configuration
# TODO: try to be smart and determine frame height and width as well automatically
def __init__(self, screen_width=80, screen_height=24, frame_width=0, frame_height=0):
def __init__(self, width=80, height=24):
"""
A Movie object consists of frames and is empty by default.
Movies are loaded from text files.
A movie only can be loaded once. A second try will fail.
Args:
screen_width (int): Screen width
screen_height (int): Screen height (Including the timebar)
frame_width (int): Movie width, if value < 0 means auto determine frame width
frame_height (int): Movie height
width (int): Movie screen width.
height (int): Movie screen height
"""
self.frames = []
self._loaded = False

self.frame_width = frame_width # type: int
self.frame_height = frame_height # type: int
self._frame_width = 67
self._frame_height = 13

f = Frame()
f.data.append("No movie yet loaded.")
self.frames.append(f)

self.screen_width = screen_width
self.screen_height = screen_height
self.screen_width = width
self.screen_height = height

self.left_margin = (self.screen_width - self._frame_width) // 2
self.top_margin = (self.screen_height - self._frame_height - TimeBar.height) // 2

def load(self, filepath):
"""
Loads the ASCII movie from given text file.
Using an encoded format, described on
http://www.asciimation.co.nz/asciimation/ascii_faq.html
In short:
67x14 chars
lines separated with \n
first line is a number telling delay in number of frames
13 lines effective frame size
15 frames per second
self.left_margin = (self.screen_width - self.frame_width) // 2
self.top_margin = (self.screen_height - self.frame_height - TimeBar.height) // 2
Args:
filepath (str): Path to Ascii Movie Data
"""
if self._loaded:
# we don't want to be loaded twice.
return False
self.frames = []
current_frame = None
lines_per_frame = self._frame_height + TimeBar.height # incl. meta data (time information)

with open(filepath) as f:
for line_num, line in enumerate(f):
time_metadata = None

if line_num % lines_per_frame == 0:
time_metadata = int(line.strip())

if time_metadata is not None:
current_frame = Frame(display_time=time_metadata)
self.frames.append(current_frame)
else:
# First strip every white character from the right
# The amount of white space can be variable
line = line.rstrip()
# Second fill line out with blanks so that any previous
# characters are overwritten
line = line.ljust(self._frame_width)
# Third center the frame on the screen
line = line.rjust(self.left_margin + self._frame_width)
current_frame.data.append(line)
self._loaded = True
return True
85 changes: 0 additions & 85 deletions ascii_telnet/ascii_movie_loader.py

This file was deleted.

Loading

0 comments on commit 930aa00

Please sign in to comment.