Created
November 13, 2022 22:10
-
-
Save funbaker/ac98c17259f3a2e46e29937f6fa9f339 to your computer and use it in GitHub Desktop.
GIMP RetroSun
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from gimpfu import * | |
def retrosun(img, layer, gradient): | |
gimp.progress_init("Rendering RetroSun to " + layer.name + "...") | |
# Set up an undo group, so the operation will be undone in one step. | |
pdb.gimp_undo_push_group_start(img) | |
# Do stuff here. | |
try: | |
exists, x1, y1, x2, y2 = pdb.gimp_selection_bounds(img) | |
w, h = x2 - x1, y2 - y1 | |
assert exists | |
pdb.gimp_image_select_ellipse(img, CHANNEL_OP_REPLACE, x1, y1, x2 - x1, y2 - y1) | |
pdb.gimp_drawable_edit_gradient_fill( | |
layer, | |
GRADIENT_LINEAR, | |
0, | |
0, | |
0, | |
0, | |
0, | |
(x1 + (x2 / 2)), | |
y1, | |
(x1 + (x2 / 2)), | |
y2, | |
) | |
pdb.gimp_selection_clear(img) | |
cut_at = round(h / 3) # start at 1/3 of the circle | |
i = h - cut_at # subtract that 1/3 from the full circle's height | |
size = round(h / 30) # the size of the cutout | |
size_step = round(size / 5) # cutout size step for every step | |
distance = size * 2 # distance is double the original cutout size | |
distance_step = size_step # distance step size increase is the same as for the size | |
while i >= 0: | |
pdb.gimp_image_select_rectangle(img, CHANNEL_OP_ADD, 0, cut_at, img.width, size) | |
size += size_step | |
distance -= distance_step | |
cut_at += (size + distance) | |
i -= (size + distance) | |
pdb.gimp_edit_fill(layer, FILL_TRANSPARENT) | |
pdb.gimp_selection_clear(img) | |
except AssertionError: | |
pass | |
finally: | |
# Close the undo group. | |
pdb.gimp_undo_push_group_end(img) | |
register( | |
"RetroSun", | |
"Create a Retrowave Sun at Selection", | |
"Create a Retrowave Sun at Selection", | |
"Synthehol FM", | |
"funbaker", | |
"2022", | |
"<Image>/Filters/Render/RetroSun", | |
"*", # Alternately use RGB, RGB*, GRAY*, INDEXED etc. | |
[ | |
(PF_GRADIENT, "gradient", "Gradient", None) | |
], | |
[], | |
retrosun | |
) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment