carol.gimp.org

gimp2

Python:Py Yin Yang

I don't know what I was doing that evening on the computer and on the internet, but a nice ircer dropped in, dropped off this script and took off for where ever.

Today, in my gimp-2.3 I installed it.

pyyinyang

It produces this image:

yinyang

And these easily fixed complaints:

yinyangyuck

Read it on the stylish web page below. Download it and install it.

py-yinyang.py

File   Edit   Search   Preferences




#!/usr/bin/env python

# Gimp yin/yang symbol plugin for The Gimp (Python-Fu Version).

# Written by Werner Hartnagel based on Perl Plugin from Aaron Sherman

# Main function. Takes width, height, do_eyes (toggle), eye_images (toggle),
# white_eye_image (filename) and black_eye_image (filename).
# Creates a stand-alone image with a yin-yang symbol in black and white.

from gimpfu import *
import time

def py_yinyang(width, height, do_eyes, eye_images, white_eye_image, black_eye_image, aa):
	# Create new image
	img = gimp.Image(width, height, RGB)
	layer = gimp.Layer(img, "Yin/Yang", width, height, RGBA_IMAGE, 100, NORMAL_MODE)
	img.add_layer(layer, 0)
	pdb.gimp_image_set_active_layer(img, layer)

	draw = pdb.gimp_image_active_drawable(img)
	oldcolor = gimp.get_foreground()
	gimp.set_foreground([0,0,0])
	pdb.gimp_selection_all(img)
	pdb.gimp_bucket_fill(draw,0,0,100,0,0,0,0)

	# Create the yin-yang shape
	#gimp_selection_invert($img)
	pdb.gimp_selection_none(img)
	pdb.gimp_rect_select(img, 0, 0, width/2, height, 0, 0, 0)
	pdb.gimp_ellipse_select(img, width/2-width/4, 0, width/2, int(height/2), 0, aa, 0, 0)
	pdb.gimp_ellipse_select(img, width/2-width/4, height/2, width/2, height/2, 1, aa, 0, 0)
	pdb.gimp_palette_set_foreground([255,255,255])
	pdb.gimp_bucket_fill(draw,0,0,100,0,0,0,0)

	# Cut away all but the central circle
	pdb.gimp_ellipse_select(img, 0, 0, width, height, 2, aa, 0, 0)
	pdb.gimp_selection_invert(img)
	pdb.gimp_edit_clear(draw)

	# Create the "eyes"
	if (do_eyes):
		x1 = width/2-width/16
		y1 = height/2-height/4-height/16
		x2 = x1
		y2 = height/2+height/4-height/16
		eyewidth = width/8
		eyeheight = height/8
		insert_eye(img, eye_images, white_eye_image, [0,0,0], x1, y1, eyewidth, eyeheight, draw, aa)
		insert_eye(img, eye_images, black_eye_image, [255,255,255], x2, y2, eyewidth, eyeheight, draw, aa)


	# Finish up
	gimp.set_foreground(oldcolor)
	pdb.gimp_selection_none(img)

	disp1 = gimp.Display(img)

# This subroutine inserts an "eye" (a dot in the center of the cicular
# part of each of the halves of the yin-yang). The eye is either
# a solid dot of the opposite color from that half of the yin-yang or
# an image, which is loaded and scaled to fit.
def insert_eye(img, do_image, file, color, x, y, width, height, draw, aa):
	pdb.gimp_ellipse_select(img, x, y, width, height, 2, aa, 0, 0)
	pdb.gimp_palette_set_foreground(color)
	#do_image = 0
	if (do_image):
		eye = pdb.gimp_file_load(file, file)   # dosn't load images pygimp bug??, file)
		pdb.gimp_image_scale(eye, width, height)
		pdb.gimp_selection_all(eye)
		eyedraw = pdb.gimp_image_active_drawable(eye)
		pdb.gimp_edit_copy(eyedraw)
		float = pdb.gimp_edit_paste(draw, 1)
		pdb.gimp_floating_sel_anchor(float)
		pdb.gimp_image_delete(eye)
	else:
		pdb.gimp_bucket_fill(draw,0,0,100,0,0,0,0)

# Register with The Gimp
register(
	"py_yinyang",
	"Render a stand-alone Yin/Yang image",
	"Renders a black-and-white Yin/Yang symbol optionally with \"eyes\" that may optionally be images.",
	"Werner Hartnagel",
	"(c) 2003, Werner Hartnagel",
	"2003",
	"<Toolbox>/Xtns/Python-Fu/Misc/Yin-Yang...",
	"RGB*, GRAY*",
	[
		[PF_INT32, "width", "Width", 256],
		[PF_INT32, "height", "Height", 256],
		[PF_TOGGLE, "insert_eyes", "", 1],
		[PF_TOGGLE, "eyes_are_images", "", 0],
		[PF_STRING, "top_eye_filename", "eye 1", ""],
		[PF_STRING, "bottom_eye_filename", "eye 2", ""],
		[PF_TOGGLE, "anti_aliasing", "", 1]
	],
	[],
	py_yinyang)

main()





  

another-gnu-type

Most all of my software is gnu. thanks!

Valid XHTML 1.1!

CC-GNU GPL
This software is licensed under the CC-GNU GPL.