#!/usr/bin/perl

use Gimp qw(:auto __ N_);
use Gimp::Fu;
use Gimp::Util;

sub randint {
    my ($int) = @_;
    return int(rand()*$int +0.5);
}

podregister {
    eval { $image->undo_group_start };
    Gimp::Context->push();
    my $sel;
    ($sel,$x1,$y1,$x2,$y2) = $image->gimp_selection_bounds;
    srand();
    @gradientlist = gimp_gradients_get_list("");
    Gimp->progress_init("Random blends...");
    for ($i=0; $i<$numgradients; $i++) {
        Gimp::Context->set_gradient(@gradientlist[randint($#gradientlist)]);
	$drawable->edit_blend(CUSTOM_MODE,
                       DIFFERENCE_MODE,
                       randint(10),      # gradient type
                       randint(100),     # opacity
                       0,                # offset
                       randint(2),       # repeat
		       0,                # reverse
                       0,                # disable supersampling..
		       1,
		       0.1,
		       0,                # no dithering
                       randint($x2-$x1)+$x1, # x1
                       randint($y2-$y1)+$y1, # y1
                       randint($x2-$x1)+$x1, # x2
                       randint($y2-$y1)+$y1, # y2
                       );
        Gimp->progress_update($i/(1.0*$numgradients));
    }
    eval { $image->undo_group_end };
    Gimp::Context->pop();
    return();
};
exit main;
__END__

=head1 NAME

random_blends - Perform N random blends

=head1 SYNOPSIS

<Image>/Filters/Render/Random Blends...

=head1 DESCRIPTION

A random approach to art, using the blend tool with DIFFERENCE_MODE.  Alpha is not affected; best used on opaque background.  Just try it. It might be good.

=head1 PARAMETERS

 [PF_SPINNER, "numgradients", "How many gradients to apply", 7, [1,255,1]],

=head1 IMAGE TYPES

RGB*, GRAY*

=head1 HISTORY

 <sjburges@gimp.org>
 This is adrian's idea - take random blends and difference them.  You're
 bound to come up w/ something cool eventually.

=head1 AUTHOR

Seth Burgess <sjburges@gimp.org>

=head1 DATE

1999-03-18

=head1 LICENSE

Distributed under the same terms as Gimp-Perl.
