![]() |
|
Gimp 3.0 - How to draw stuff with python scripts (pixel by pixel) - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP) +---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions) +---- Thread: Gimp 3.0 - How to draw stuff with python scripts (pixel by pixel) (/Thread-Gimp-3-0-How-to-draw-stuff-with-python-scripts-pixel-by-pixel) |
Gimp 3.0 - How to draw stuff with python scripts (pixel by pixel) - krokots - 03-04-2026 I need help writing some basic script that will draw, for example, a circle, or a rectangle of randomly colored pixels, at a specified X and Y on the selected layer. For now I got this : Code: #!/usr/bin/env python3I see that Drawable class have a method SetPixel, but in the docs it says that undo doesn't work on that. So, how to modify drawable pixels so that undo works ? RE: Gimp 3.0 - How to draw stuff with python scripts (pixel by pixel) - programmer_ceds - 03-05-2026 [attachment=14289][attachment=14290] (03-04-2026, 05:15 PM)krokots Wrote: I see that Drawable class have a method SetPixel, but in the docs it says that undo doesn't work on that. So, how to modify drawable pixels so that undo works ? The attached scripts are in Script-fu but would be easily convertible to Python - they draw a filled circle and a hollow circle by filling or stroking a selection (an ellipse with the foci at the same position. For drawing other shapes it would probably be best to define paths and then stroke them. Alternatively define a selection and stroke that. Avoid using set_pixel() RE: Gimp 3.0 - How to draw stuff with python scripts (pixel by pixel) - krokots - 03-06-2026 I see that the scripts use selection as a way to paint pixels. But what if I wanted to paint something else, for example, a diagonal line ? From X1, Y1 to X2, Y2 ? RE: Gimp 3.0 - How to draw stuff with python scripts (pixel by pixel) - MrsP-from-C - 03-07-2026 Maybe these help you? https://developer.gimp.org/api/3.0/libgimp/func.paintbrush.html https://developer.gimp.org/api/3.0/libgimp/func.paintbrush_default.html Basically you define which brush to use, define its settings and define start and end point. RE: Gimp 3.0 - How to draw stuff with python scripts (pixel by pixel) - krokots - 03-07-2026 That is a really nice suggestion! That could work for drawing straight lines. BUT...what I really want to achieve, is a mix of things. I want to create a script that creates "random" pixelated trees. For this, I also would like to be able to modify pixels on a canvas. So, for example, I create a circle, fill it with a color (or use a gradient). Nice - that I can do in python. But for next thing - I need to modify slightly some random pixels in the filled circle (to create a noise-like texture). That would need some kind of function for changing pixels on the active layer.
|