analitics

Pages

Sunday, February 10, 2019

Using the asciimatics and pyfiglet python modules

This is a simple example how to use the asciimatics and pyfiglet python modules with python version 3.6.4.
First you need to install with the pip tool.
The source code is simple and start with the import it.
The Fire, Print and Screen is used to show the fire effect and print text with Figlet and FigletText.
Because the fire and text use the console application I used the default Screen Buffer Size set to 80.
The Screen.wrapper(my_work_web) show all effects from the my_work_web.
In this area is created variables for font type: banner_font and web_font.
The main reason I named the web_font was to show my web page but the size of the over the screensize.
I tested most of the fonts from pyfiglet python module but I cannot find one to show a web page link.
This is the source code I tested:
# -*- coding: utf-8 -*-
"""
@author: catafest
"""

from asciimatics.renderers import FigletText, Fire
from asciimatics.scene import Scene
from asciimatics.screen import Screen
from asciimatics.effects import Print
from asciimatics.exceptions import ResizeScreenError
from pyfiglet import Figlet
import sys

def my_work_web(screen):
    banner_font = "banner3"
    web_font = "block"
    scenes = []
    effects = [
        Print(screen,
              Fire(screen.height, 80, "*" * 70, 0.8, 60, screen.colours,
                   bg=screen.colours >= 256),
              0,
              speed=1,
              transparent=False),
        Print(screen,
              FigletText("Follow ", banner_font),
              (screen.height - 4) // 2,
              colour=Screen.COLOUR_BLUE,
              speed=1,
              stop_frame=30),
        Print(screen,
              FigletText("me", banner_font),
              (screen.height - 4) // 2,
              colour=Screen.COLOUR_BLUE,
              speed=1,
              start_frame=30,
              stop_frame=50),
        Print(screen,
              FigletText("on web", banner_font),
              (screen.height - 4) // 2,
              colour=Screen.COLOUR_BLUE,
              speed=1,
              start_frame=50,
              stop_frame=70),
        Print(screen,
              FigletText("catafest", banner_font),
              (screen.height - 4) // 2,
              colour=Screen.COLOUR_BLUE,
              speed=1,
              start_frame=70),
    ]
    scenes.append(Scene(effects, 100))

    text = Figlet(font=web_font, width=300).renderText("bye!")
    width = max([len(x) for x in text.split("\n")])

    effects = [
        Print(screen,
              Fire(screen.height, 80, "*" * 70, 0.8, 60, screen.colours),
              0,
              speed=1,
              transparent=False),

        Print(screen,
              FigletText("bye!", web_font),
              (screen.height - 2)  // 2,
              colour=Screen.COLOUR_WHITE,
              bg=Screen.COLOUR_BLUE,
              speed=1)
    ]
    scenes.append(Scene(effects, -1))
    screen.play(scenes, stop_on_resize=True)


if __name__ == "__main__":
    while True:
        try:
            Screen.wrapper(my_work_web)
            sys.exit(0)
        except ResizeScreenError:
            pass
The result of this source code is this:

Monday, January 28, 2019

Testing imageio python module.

This python module comes with this intro from pypi website:
Imageio is a Python library that provides an easy interface to read and write a wide range of image data, including animated images, volumetric data, and scientific formats. It is cross-platform, runs on Python 2.7 and 3.4+, and is easy to install.
Let's install this python module:
C:\>cd C:\Python364
C:\Python364>cd Scripts
C:\Python364\Scripts>pip3.6.exe install imageio
Collecting imageio
...
Successfully built imageio
Installing collected packages: imageio
Successfully installed imageio-2.4.1
You are using pip version 18.0, however version 18.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' comm
and.
I tested with a simple read medical data (DICOM - CT-MONO2-16-brain), see here.
The Digital Imaging and Communications in Medicine (DICOM) standard start with the basic idea is that patient and machine-readable information is embedded within a file (usually an image) as it’s created or converted.
This is a simple example without security.
Without encrypted connections between applications, anyone on the network could intercept the DICOM files and extract the patient information.
The Imageio provides a range of example images:
  1. Read an image;
  2. Iterate over frames in a movie;
  3. Grab screenshot or image from the clipboard;
  4. Convert a movie;
  5. Writing videos with FFMPEG and vaapi;
All file formats (93 files type ) can be read by this python module, see webpage here.
The examples from the official webpage work well.
Only the example with the DICOM file cannot be tested.
The main reason: I try to find a DICOM file but I don't find one.