3
# Gimp-Python - allows the writing of Gimp plugins in Python.
4
# Copyright (C) 1997 James Henstridge <james@daa.com.au>
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
def python_sphere(radius, light, shadow, bg_colour, sphere_colour):
26
width = int(radius * 3.75)
27
height = int(radius * 2.5)
28
img = gimp.Image(width, height, RGB)
29
drawable = gimp.Layer(img, "Sphere Layer", width, height,
30
RGB_IMAGE, 100, NORMAL_MODE)
31
radians = light * math.pi / 180
34
light_x = cx + radius * 0.6 * math.cos(radians)
35
light_y = cy - radius * 0.6 * math.sin(radians)
36
light_end_x = cx + radius * math.cos(math.pi + radians)
37
light_end_y = cy - radius * math.sin(math.pi + radians)
39
old_fg = gimp.get_foreground()
40
old_bg = gimp.get_background()
42
img.add_layer(drawable, 0)
43
gimp.set_foreground(sphere_colour)
44
gimp.set_background(bg_colour)
45
pdb.gimp_edit_fill(drawable, BACKGROUND_FILL)
46
gimp.set_background(20, 20, 20)
47
if (light >= 45 and light <= 75 or light <= 135 and
48
light >= 105) and shadow:
49
shadow_w = radius * 2.5 * math.cos(math.pi + radians)
50
shadow_h = radius * 0.5
52
shadow_y = cy + radius * 0.65
54
shadow_x = cx + shadow_w
56
pdb.gimp_ellipse_select(img, shadow_x, shadow_y, shadow_w, shadow_h,
57
CHANNEL_OP_REPLACE, TRUE, TRUE, 7.5)
58
pdb.gimp_edit_bucket_fill(drawable, BG_BUCKET_FILL,
59
MULTIPLY_MODE, 100, 0, FALSE, 0, 0)
60
pdb.gimp_ellipse_select(img, cx - radius, cy - radius, 2 * radius,
61
2 * radius, CHANNEL_OP_REPLACE, TRUE, FALSE, 0)
62
pdb.gimp_edit_blend(drawable, FG_BG_RGB_MODE, NORMAL_MODE, GRADIENT_RADIAL,
63
100, offset, REPEAT_NONE, FALSE, FALSE, 0, 0, TRUE,
64
light_x, light_y, light_end_x, light_end_y)
65
pdb.gimp_selection_none(img)
66
gimp.set_background(old_bg)
67
gimp.set_foreground(old_fg)
69
disp = gimp.Display(img)
73
"Simple spheres with drop shadows",
74
"Simple spheres with drop shadows (based on script-fu version)",
78
"<Toolbox>/Xtns/Python-Fu/Test/_Sphere",
79
"RGB*, GRAY*, INDEXED*",
81
(PF_INT, "radius", "Radius for sphere", 100),
82
(PF_SLIDER, "light", "light angle", 45, (0,360,1)),
83
(PF_TOGGLE, "shadow", "shadow?", 1),
84
(PF_COLOR, "bg_colour", "background", (255,255,255)),
85
(PF_COLOR, "sphere_colour", "sphere", (255,0,0))