File: maeda.pl

package info (click to toggle)
libimage-imlib2-perl 2.02-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 196 kB
  • ctags: 40
  • sloc: perl: 294; ansic: 112; makefile: 75
file content (55 lines) | stat: -rw-r--r-- 1,173 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/local/bin/perl
#
# This is a program which attempts to produce a picture
# I once saw by John Maeda.
#
# Note: there appears to be a bug in fill_ellipse in some versions of
# imlib2. Change that to fill_rectange all if you get is a white
# screen.
#
# Leon Brocard

use strict;
use lib qw(../lib ../blib/lib ../blib/arch);
use Image::Imlib2;
use POSIX qw(floor);

my $image = Image::Imlib2->new(640, 480);

$image->set_colour(255, 255, 255, 255);
$image->fill_rectangle(0, 0, 640, 480);

foreach my $x (0..640) {

  next if ($x + 16) % 32;

  $x += rand(16) - 8;

  my $h = $x / 2;
  $h = 320 - $h if $h > 160;
  $h *= 2;

  foreach my $c (1..$h/4) {

    my $rand = floor(rand(4));
    
    if ($rand == 0) {
      $image->set_colour(255, 255,   0, 255);
    } elsif ($rand == 1) {
      $image->set_colour(255,   0, 255, 255);
    } elsif ($rand == 2) {
      $image->set_colour(  0, 255, 255, 255);
    } elsif ($rand == 3) {
      $image->set_colour(  0,   0,   0, 255);
    }

    my $y = 240 + rand($h) - ($h / 2) + rand(80) - 40;
    
    my $radius = int(rand(10)) + 1;
    $image->fill_ellipse($x, $y, $radius, $radius);

  }

}

$image->save("maeda.png");