~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/pygimp/plug-ins/sphere.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: james.westby@ubuntu.com-20070502163303-6wchheivjxgjtlna
Tags: upstream-2.3.16
ImportĀ upstreamĀ versionĀ 2.3.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import math
21
21
from gimpfu import *
22
22
 
23
 
def python_sphere(radius, light, shadow, bg_colour, sphere_colour):
 
23
def sphere(radius, light, shadow, bg_colour, sphere_colour):
24
24
    if radius < 1:
25
25
        radius = 1
 
26
 
26
27
    width = int(radius * 3.75)
27
28
    height = int(radius * 2.5)
 
29
 
 
30
    gimp.context_push()
 
31
 
28
32
    img = gimp.Image(width, height, RGB)
 
33
 
29
34
    drawable = gimp.Layer(img, "Sphere Layer", width, height,
30
35
                          RGB_IMAGE, 100, NORMAL_MODE)
 
36
 
31
37
    radians = light * math.pi / 180
 
38
 
32
39
    cx = width / 2
33
40
    cy = height / 2
 
41
 
34
42
    light_x = cx + radius * 0.6 * math.cos(radians)
35
43
    light_y = cy - radius * 0.6 * math.sin(radians)
 
44
 
36
45
    light_end_x = cx + radius * math.cos(math.pi + radians)
37
46
    light_end_y = cy - radius * math.sin(math.pi + radians)
 
47
 
38
48
    offset = radius * 0.1
39
 
    old_fg = gimp.get_foreground()
40
 
    old_bg = gimp.get_background()
 
49
 
41
50
    img.disable_undo()
42
51
    img.add_layer(drawable, 0)
 
52
 
43
53
    gimp.set_foreground(sphere_colour)
 
54
 
44
55
    gimp.set_background(bg_colour)
45
56
    pdb.gimp_edit_fill(drawable, BACKGROUND_FILL)
 
57
 
46
58
    gimp.set_background(20, 20, 20)
 
59
 
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
51
64
        shadow_x = cx
52
65
        shadow_y = cy + radius * 0.65
 
66
 
53
67
        if shadow_w < 0:
54
68
            shadow_x = cx + shadow_w
55
69
            shadow_w = -shadow_w
 
70
 
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)
 
75
 
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)
 
81
 
65
82
    pdb.gimp_selection_none(img)
66
 
    gimp.set_background(old_bg)
67
 
    gimp.set_foreground(old_fg)
 
83
 
68
84
    img.enable_undo()
 
85
 
69
86
    disp = gimp.Display(img)
70
87
 
 
88
    gimp.context_pop()
 
89
 
 
90
 
71
91
register(
72
 
    "python_fu_sphere",
 
92
    "python-fu-sphere",
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",
77
97
    "1997-1999",
78
 
    "<Toolbox>/Xtns/Python-Fu/Test/_Sphere",
 
98
    "<Toolbox>/Xtns/Languages/Python-Fu/Test/_Sphere",
79
99
    "",
80
100
    [
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))
86
106
    ],
87
107
    [],
88
 
    python_sphere)
 
108
    sphere)
89
109
 
90
110
main()