21
21
from gimpfu import *
23
def python_sphere(radius, light, shadow, bg_colour, sphere_colour):
23
def sphere(radius, light, shadow, bg_colour, sphere_colour):
26
27
width = int(radius * 3.75)
27
28
height = int(radius * 2.5)
28
32
img = gimp.Image(width, height, RGB)
29
34
drawable = gimp.Layer(img, "Sphere Layer", width, height,
30
35
RGB_IMAGE, 100, NORMAL_MODE)
31
37
radians = light * math.pi / 180
34
42
light_x = cx + radius * 0.6 * math.cos(radians)
35
43
light_y = cy - radius * 0.6 * math.sin(radians)
36
45
light_end_x = cx + radius * math.cos(math.pi + radians)
37
46
light_end_y = cy - radius * math.sin(math.pi + radians)
38
48
offset = radius * 0.1
39
old_fg = gimp.get_foreground()
40
old_bg = gimp.get_background()
42
51
img.add_layer(drawable, 0)
43
53
gimp.set_foreground(sphere_colour)
44
55
gimp.set_background(bg_colour)
45
56
pdb.gimp_edit_fill(drawable, BACKGROUND_FILL)
46
58
gimp.set_background(20, 20, 20)
47
60
if (light >= 45 and light <= 75 or light <= 135 and
48
61
light >= 105) and shadow:
49
62
shadow_w = radius * 2.5 * math.cos(math.pi + radians)
50
63
shadow_h = radius * 0.5
52
65
shadow_y = cy + radius * 0.65
54
68
shadow_x = cx + shadow_w
55
69
shadow_w = -shadow_w
56
71
pdb.gimp_ellipse_select(img, shadow_x, shadow_y, shadow_w, shadow_h,
57
CHANNEL_OP_REPLACE, TRUE, TRUE, 7.5)
72
CHANNEL_OP_REPLACE, True, True, 7.5)
58
73
pdb.gimp_edit_bucket_fill(drawable, BG_BUCKET_FILL,
59
MULTIPLY_MODE, 100, 0, FALSE, 0, 0)
74
MULTIPLY_MODE, 100, 0, False, 0, 0)
60
76
pdb.gimp_ellipse_select(img, cx - radius, cy - radius, 2 * radius,
61
2 * radius, CHANNEL_OP_REPLACE, TRUE, FALSE, 0)
77
2 * radius, CHANNEL_OP_REPLACE, True, False, 0)
62
78
pdb.gimp_edit_blend(drawable, FG_BG_RGB_MODE, NORMAL_MODE, GRADIENT_RADIAL,
63
100, offset, REPEAT_NONE, FALSE, FALSE, 0, 0, TRUE,
79
100, offset, REPEAT_NONE, False, False, 0, 0, True,
64
80
light_x, light_y, light_end_x, light_end_y)
65
82
pdb.gimp_selection_none(img)
66
gimp.set_background(old_bg)
67
gimp.set_foreground(old_fg)
69
86
disp = gimp.Display(img)
73
93
"Simple spheres with drop shadows",
74
94
"Simple spheres with drop shadows (based on script-fu version)",
75
95
"James Henstridge",
76
96
"James Henstridge",
78
"<Toolbox>/Xtns/Python-Fu/Test/_Sphere",
98
"<Toolbox>/Xtns/Languages/Python-Fu/Test/_Sphere",
81
101
(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))
102
(PF_SLIDER, "light", "Light angle", 45, (0,360,1)),
103
(PF_TOGGLE, "shadow", "Shadow?", 1),
104
(PF_COLOR, "bg-color", "Background", (255,255,255)),
105
(PF_COLOR, "sphere-color", "Sphere", (255,0,0))