File:CA rule110s.png

From formulasearchengine
Jump to navigation Jump to search

Original file(10,000 × 10,000 pixels, file size: 167 KB, MIME type: image/png)

This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

Summary

Description See below.
Date
Source Own work by the original uploader
Author Grondilu (talk) (Uploads)
Other versions

Made with the following Perl code:

use strict;
use warnings;
use GD;

package Automaton {
    sub new {
        my $class = shift;
        my $rule = [ reverse split //, sprintf "%08b", shift ];
        return bless { rule => $rule, cells => [ @_ ] }, $class;
    }
    sub next {
        my $this = shift;
        my @previous = @{$this->{cells}};
        $this->{cells} = [
            @{$this->{rule}}[
                map {
                    4 * $previous[($_ - 1) % @previous]
                    + 2 * $previous[$_]
                    + $previous[($_ + 1) % @previous]
                } 0 .. @previous - 1
            ]
        ];
        return $this;
    }
    use overload
        q{""} => sub {
            my $this = shift;
            join '', map { $_ ? '#' : ' ' } @{$this->{cells}}
        };

    sub to_image {
        my ($this, $width, $height) = @_;
        my $image = GD::Image->new($width, $height);
        my $black = $image->colorAllocate(0, 0, 0);
        my $white = $image->colorAllocate(255, 255, 255);

        my $x = 0;
        my $y = 0;
        foreach my $cell (@{$this->{cells}}) {
            if ($cell) {
                $image->setPixel($x, $y, $black);
            } else {
                $image->setPixel($x, $y, $white);
            }
            $x++;
            if ($x >= $width) {
                $x = 0;
                $y++;
                last if $y >= $height;
            }
        }
        return $image;
    }
}

my ($width, $height) = (10**4, 10**4);
my @a = map 0, 1 .. $width;
$a[$width - 1] = 1;
my $a = Automaton->new(110, @a);

# Save to file
open(my $out, '>', 'output.png') or die "Cannot open file: $!";
binmode $out;
print $out "P1\n$width $height\n";

for (1 .. $height) {
    print $out join(' ', @{$a->{cells}}) . "\n";
    $a->next;
}

close $out;


Licensing

Grondilu at English Wikipedia, the copyright holder of this work, hereby publishes it under the following license:
Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

Original upload log

The original description page was here. All following user names refer to en.wikipedia.
  • 2014-02-28 08:32 Grondilu 1000×1000× (10463 bytes) Made it myself with the following Perl code: <code>use strict; use warnings; package Automaton { sub new { my $class = shift; my $rule = [ reverse split //, sprintf "%08b", shift ]; return bless { rule => $rule, cells => [ @_ ] }, $class;...

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

28 February 2014

image/png

9b1b62f5bf9ee9a880d31358b7337a51c56c12d9

170,613 byte

10,000 pixel

10,000 pixel

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current19:14, 4 August 2023Thumbnail for version as of 19:14, 4 August 202310,000 × 10,000 (167 KB)wikimediacommons>Obscure2020Optimized with OxiPNG and ZopfliPNG.

There are no pages that use this file.