Screen saver with Prism and cellular automata

Introduction

The post is devoted to the application that is complete screen saver. Sure, screen saver is quite old technology, and there is no necessity to use it on modern displays. But from my point of view moving objects on display until computer fall to sleep looks better than stable background picture.

The application bases on the idea of mathematical objects modelling application, as it could provide interesting visual patterns. This version uses 2D closed cellular automaton, and it could be iterated in natural way. These automata are quite interesting, and you can read more about it in Wikipedia: Cellular automaton, Conway’s Game of Life.

The application provides settings that controls size and colors of cells and current automaton algorithm. Statistics views could be shown on the main window. There are line chart with series of born, died and total amount of cells; and column chart with distribution of cells per their age. As the application is a screen saver, it exits at any key or left mouse click, but user may use context menu to show/hide statistics and restart automaton.

The code of the application and its features is described in additional posts that are listed below. This post describes to user features of application.

There is an application archive automata_screen_saver_app. Full code is accessible on GitHub Apps repository.

Gallery

The gallery shows the application window with various colors, cell sizes and different modes.

Features

Application demonstrates the following features:

  1. adapt to the current size of displays;
  2. support many displays;
  3. visual look of automaton, i.e. colors, borders, could be tuned;
  4. automaton has been uploaded in the background;
  5. context menu allows to change settings and to show/hide statistics without interrupting screen saver;
  6. user may restart automaton on the fly;
  7. for installation it is necessary copy files and install screen saver;
  8. new automaton types could be easily added as Prism modules;
  9. features are implemented in NuGet packages;
  10. use Unity as dependency container;
  11. use log4net for logging;
  12. save settings in xml.

Application launch

Zip archive contains Automata Screen Saver.scr file that should be installed like a screen saver. It is necessary to call context menu for Automata Screen Saver.scr file in File Explorer, and then click on Install item. Screen Saver Window could be used to set timeout, settings of screen saver, and preview it. Images below show these steps.

The main window

By default, the main window demonstrates current automaton, mouse cursor is hided. If user moves mouse, cursor shows and again hides in one second. User may right click and calls context menu.

Context menu:

  1. Statistics – checked item, show/hide statistics for automaton at the current screen;
  2. Restart – init all automata (on all screens) with initial set of points, that depending on the settings;
  3. Settings – show settings window and allow user to change settings without interrupting automaton iteration;
  4. About – show about dialog.

Statistics is presented by two float semi-transparent windows in the left part of screen. Each automaton window has its own statistics window. The application uses OxyPlot library for chart controls, as it is lightweight and easy to use. The top statistics window shows column chart with distribution of cells per their age. There exist life algorithms such that cells could live many iterations, and chart summarizes count of all cells with age more than 50.

Second statistics window show line chart with series of born, died and total amount of cells.

When user restart automaton, all statistics values are reset to zero, and then automaton is recreated. All cells in the initial automaton are one iteration old, and born and died lines has empty values and intersects X-axis.

Settings

Settings contains life algorithm, colors, cell sizes. Let us consider it in details.

The application

  1. Automaton type – type of the automaton; currently only one value that is equal to “cellular automaton”;
  2. Secondary displays – which window is shown on secondary displays. There are the following options:
    • Empty window – empty, black window is shown on secondary displays;
    • Automaton – the same window as the main window is shown on secondary displays. Each of them contains own automaton, but all they share the same color and size settings;
  3. Background type – type of background; currently only one value that is equal to “solid color”;
  4. Color – background color of the main window and empty window.

The automaton

  1. Life model | Type – used life algorithm. It defines how many neighbors dead cell should has to born again (for example, “B3” – it will born if there is exactly 3 neighbors), and how many neighbors living cell should has to survive (for example, “S23” – living cell survives if it has 2 or 3 neighbors). There are the following options:
    • Conway’s Game of Life (B3/S23) – Conway’s Game of Life, highly complex behavior;
    • Edward Fredkin’s replicaton (B1357/S1357) – replicator Edward Fredkin’s replicating automaton: every pattern is eventually replaced by multiple copies of itself;
    • Seeds (B2/S) – all patterns are phoenixes, meaning that every live cell immediately dies, and many patterns lead to explosive chaotic growth. However, some engineered patterns with complex behavior are known;
    • Pseudorandom (B25/S4) – this rule supports a small self-replicating pattern which, when combined with a small glider pattern, causes the glider to bounce back and forth in a pseudorandom walk;
    • Life without death(B3/S012345678) – also known as Inkspot or Flakes. Cells that become alive never die. It combines chaotic growth with more structured ladder-like patterns that can be used to simulate arbitrary Boolean circuits;
    • Life 34 (B34/S34) – was initially thought to be a stable alternative to Life, until computer simulation found that larger patterns tend to explode. Has many small oscillators and spaceships;
    • Diamoeba (B35678/S5678) – forms large diamonds with chaotically fluctuating boundaries. First studied by Dean Hickerson, who in 1993 offered a $50 prize to find a pattern that fills space with live cells; the prize was won in 1999 by David Bell;
    • Pattern 2×2 (B36/S125) – if a pattern is composed of 2×2 blocks, it will continue to evolve in the same form; grouping these blocks into larger powers of two leads to the same behavior, but slower. Has complex oscillators of high periods as well as a small glider;
    • High life (B36/S23) – similar to Life but with a small self-replicating pattern;
    • Day and night (B3678/S34678) – symmetric under on-off reversal. Has engineered patterns with highly complex behavior;
    • Stephen Morley’s Move (B368/S245) – named after Stephen Morley; also called Move. Supports very high-period and slow spaceships;
    • Twisted majority rule (B4678/S35678) – symmetric under on-off reversal. Approximates the curve-shortening flow on the boundaries between live and dead cells;
  2. Automaton | Iteration – delay in ms between two automaton iterations;
  3. Automaton | Initial – type of initial automaton. There are the following values:
    • Previous state – automaton saves the last state, and at next launch continue with saved set of points;
    • Date & Time – initial automaton starts with set of points that looks like current date and time;
    • UTC Date & Time – initial automaton starts with set of points that looks like current UTC date and time;
    • Random – automaton starts from random set of points.
  4. Cell size | Width – width in pixels of a cell;
  5. Cell size | Height – height in pixels of a cell;
  6. Cell animation | Type – visual type of how cells are died/born. There are the following values:
    • No automation – cell is hided and shown immediately;
    • Fade – cell changes opacity from 0 to 1 or backward.
  7. Cell animation | Delay – delay in ms for animation with “Fade” type.

Automaton colors

  1. Cell colors | Start – start color for gradient for the inside of the circle; could be darker than Finish in order to make cells looks “negative”;
  2. Cell colors | Finish – finish color for gradient for the inside of the circle;
  3. Cell colors | Inner – color of the inside of square;
  4. Cell colors | Age – Boolean value that defines additional “age” colorization of cells when depends on its age circle become darker;
  5. Border | Color – color of borders around squares;
  6. Border | Show – Boolean value that defines show or hide cell border.

Code background

Solution uses C#6, .Net 4.5.1, Wpf with Prism pattern, OxyPlot chart control, and Ikc5.* NuGet packages. Features are described in the following posts:

The application uses the following software and NuGet packages:

  1. Prism is a fully open source version of the Prism guidance originally produced by Microsoft Patterns & Practices. Prism provides an implementation of a collection of design patterns that are helpful in writing well structured and maintainable XAML applications, including MVVM, dependency injection, commanding, event aggregation, and more. There are related links:
  2. Unity (the Unity Application Block) is a lightweight extensible dependency injection container with support for constructor, property, and method call injection. There are related links:
  3. Extended WPF Toolkit is the collection of WPF controls, components and utilities for creating next generation Windows applications. There are related links:
  4. OxyPlot is a cross-platform plotting library for .NET. There are related links:
  5. log4net is a tool to help the programmer output log statements to a variety of output targets. There are related links:
  6. Ikc5.TypeLibrary – the library contains the extension class with methods that manipulate properties with DefaultValue attribute and copy values of properties between objects, the service that provides lite object with public properties from parent object, base class for INotifyPropertyChanged interface, logging interfaces and extensions methods. There are related links:
  7. Ikc5.Prism.Common – the library contains classes for Prism applications. Now it contains logging extensions. There are related links:
  8. Ikc5.Prism.Settings – there are three NuGet packages under the common title Ikc5.Prism.Settings. These packages allow manipulate user settings in Prism applications and serialize/deserialize them in xml files. All package contains the same library and last two packages add models, view models and views to the project. There are links for these packages:
  9. Ikc5.Math.CellularAutomata – the library contains classes to create and investigate 2D cellular automata. There are cellular automaton classes, life algorithms and neighbors’ algorithms, cells, different interfaces’ implementation. There are links for these packages:

Solution

Solution has the following structure:

  • Common class libraries – Common.Models contains enumerations, common classes and interfaces. Common.ViewModels contains attached properties, hierarchy of converters, and common styles;
  • Life module – Life.Models refers to NuGet package Ikc5.Math.CellularAutomata and contains additional models.
    Life.Views implements views for cellular automaton.
  • ScreenSaver – the main Wpf application.

It has the similar structure and it is described in the post Extendable screen saver with Prism mentioned above.

Next steps

Add modules with Mealy and Moore automata.


1. All used IP-addresses, names of servers, workstations, domains, are fictional and are used exclusively as a demonstration only.
2. Information is provided «AS IS».

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.