Pascal Triangle Image Generator

This project was developed in June, 2011 as result in my strong interests in the area of Image generation and Fractals. It is absolutely my own work.


Get it

General

This application builds at real-time images based on advanced mathematical models (“reduced” Pascal’s Triangle). Then these images are drawn on the screen.

Valuable feature is included – there are two modes of drawing – scaled and real-size. The scaled mode is good if we want to see the whole picture. The real-size mode offers to see more detailed view of bigger fractals. The separated options dialog helps the image displaying and makes the options setting more handful. Also the images could be saved to files.

Introduction

The Pascal’s triangle is a very important object that is used in the algebra and arithmetic. If we take this triangle and write instead the numbers the remainder when we divide the numbers by two we would receive a similar structure:
        1
        1 1
        1 0 1
        1 1 1 1
        1 0 0 0 1
        1 1 0 0 1 1
        1 0 1 0 1 0 1
        1 1 1 1 1 1 1 1
        


It is easy to see that the remainders triangle follows a similar principle as the building of the Pascal’s Triangle – when we sum the two numbers top left and top right we write down the remainder when dividing that sum by 2. This triangle we could name conditionally “reduced” by 2 Pascal’s triangle.

We can see how looks like and the “reduced” by 3 Pascal’s Triangle. The construction will follow analog principle as the triangle up, but we will use the remainder from division by 3.

        1
        1 1
        1 2 1
        1 0 0 1
        1 1 0 1 1
        1 2 1 1 2 1
        1 0 0 0 0 0 1
        1 1 0 0 0 0 1 1
        1 2 1 0 0 0 1 2 1
        1 0 0 1 0 0 1 0 0 1
        1 1 0 1 1 0 1 1 0 1 1
        1 2 1 1 2 1 1 2 1 1 2 1
        


It is more important when observing these objects to look at which positions the remainder from division by defined number is 0 or something else. It turns out, that all such “reduced” triangles have expressed degree of self similarity.

Process

The process of the image generation is quite straight forward:

  1. The pascal triangle mod number is build
  2. The information in the triangle is visualized

Architecture


In the architecture, that builds the fractal generator, are participating the following objects:

  • Pascal Triangle Generator – manages a “reduced” Pascal triangle as building it row by row for wach query about it.
  • Visualizator – creates and manages interactively images of “reduced” Pascal triangle by given parameters. Also contains logic for viewing the image on the screen and recording it as file.
  • User Interface – Manages the visualizator so that it displays the iamage on the screen or saves it as file. It also manages the options dialog and the communication between it and the visualizator.
  • Options dialog – Offers to the user an interface with which he or she can manage the options of the image generation and displaying.

Options


The options dialog grants the user direct control over the image generating process. With it could be set the following parameters of the generating and displaying processes:

  • Triangle Rows – the count of the triangle’s rows
  • Modulo Row by – which number is used to “reduce” the triangle
  • Align – where the triangle is aligned – left, right or center
  • Should Scale Generated Image – sets if the image is scaled or is left raw – every row maps to one pixel from the image height
  • Background – sets the color that is used for the triangle’s background
  • Zero Color – sets the color that is used for the elements in the triangle that give remainder zero.
  • Others Colorsets the color that is used for the elements in the triangle that give remainder other than zero.