#!/usr/bin/perl -w

#
# Rewritten for GIMP 1.2 and the Graphics Muse Tools CD
# by Michael J. Hammel (mjhammel@graphics-muse.org
# Jan 26, 2002
#
#####gear plugin version 0

use Gimp qw(:auto __ N_);
use Gimp::Fu;
use Math::Trig;

sub gear {
	my ($big_diameter,$little_circle_number,$little_diameter,$cut_depth,$interior_diameter) = @_;
	$little_circle_distance=($little_diameter/2)-$cut_depth;
	$img=gimp_image_new($big_diameter,$big_diameter,RGB);
	$layer=gimp_layer_new($img,$big_diameter,$big_diameter,RGBA_IMAGE,"Couche",100,NORMAL_MODE);
	gimp_image_add_layer($img,$layer,-1);
	gimp_palette_set_foreground([255,255,255]);
	gimp_edit_fill($layer,FG_IMAGE_FILL);
	gimp_undo_push_group_start($img);
	Gimp->ellipse_select($img,0,0,$big_diameter,$big_diameter,REPLACE,1,0,0);
	$couronneRayon=$big_diameter/2+$little_circle_distance;
	$xCenter=$big_diameter/2;
	$yCenter=$xCenter;
	$angleBetweenLittleCircle=(2*pi)/$little_circle_number;
	$nbc=1;
	while ($nbc<=$little_circle_number) {
		$ang=($nbc-1)*$angleBetweenLittleCircle;
		$ciXce=sin($ang)*$couronneRayon+$xCenter;
		$ciYce=cos($ang)*$couronneRayon+$yCenter;
		$ciX=$ciXce-($little_diameter/2);
		$ciY=$ciYce-($little_diameter/2);
		Gimp->ellipse_select($img,$ciX,$ciY,$little_diameter,$little_diameter,SUB,1,0,0);
		$nbc++;
	}
	if ($interior_diameter>0) {
		$x=($big_diameter/2)-($interior_diameter/2);
		$y=$x;
		Gimp->ellipse_select($img,$x,$y,$interior_diameter,$interior_diameter,SUB,1,0,0);
	}
	gimp_undo_push_group_end($img);
	return $img;
	
}

$help="This script create a gear.
You must provide:
	-the gear diameter (big diameter)
	-the number of little circles wich 'cut' this gear (little circles)
	-their diameter
	-the cut depth
	-and eventually the interior circle diameter (0 if no)";

register
	"gear",
	"Create a gear",
	$help,
	"COUTIER Eric",
	"(c) COUTIER Eric",
	"2001-04-04",
	"<Toolbox>/Xtns/Render/Gear",
	,"",
	[
		[PF_INT,"gear_diameter","The gear diameter",200],
		[PF_INT,"little_circle_number","Number of little circle for cut",10],
		[PF_INT,"little_diameter","Diameter of little circles",40],
		[PF_INT,"cut_depth","Depth of cut in gear",15],
		[PF_INT,"interior_diameter","Diameter of interior circle (0 if no)",150],
	],
	\&gear;

exit main();
