It is currently Thu Mar 28, 2024 8:03 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Create a starfield plugin (Faster than "starry sky.scm")
PostPosted: Sat May 07, 2022 8:31 pm  (#1) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1195
This was a challenge to myself trying to translate a GIMP scheme lisp scm to GIMP python. I finally did it looking at, T. Demand & GnuTux "starry sky.scm", thank you guys!
I managed to make the plugin render faster than the old scm mention above.
*** In this newer version py, I included an option to create "Distant planets". I hope the space lovers can make the best of it. Please leave comments!

Image


Attachments:
pm_create_stars_in_the_night.zip [2.67 KiB]
Downloaded 82 times

_________________
https://www.deviantart.com/pocholo17
Image
Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Create a starfield plugin (Faster than "starry sky.scm")
PostPosted: Sat May 07, 2022 9:42 pm  (#2) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4039
Planets didn't render, when yes was selected.

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: Create a starfield plugin (Faster than "starry sky.scm")
PostPosted: Sat May 07, 2022 10:07 pm  (#3) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1195
mahvin wrote:
Planets didn't render, when yes was selected.

Hi Mahvin! You should have something like those small distant planet like in my image:
Image

The more you increase the amount of planet the more you can have in your render:
Image

_________________
https://www.deviantart.com/pocholo17
Image


Top
 Post subject: Re: Create a starfield plugin (Faster than "starry sky.scm")
PostPosted: Sat May 07, 2022 10:19 pm  (#4) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4039
I see. I was expecting large planets. My bad.

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: Create a starfield plugin (Faster than "starry sky.scm")
PostPosted: Sun May 08, 2022 3:12 am  (#5) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4726
Hmmm. Looking at the code it seems to want to randomize the color a bit:

        pixw = [255, 255, 255]   
        [...]
        pixw_0 = random.randrange(lum + 32)
        pixw_1 = random.randrange(lum + 32)
        pixw_2 = random.randrange(lum + 32)
        [...]
        pdb.gimp_drawable_set_pixel(starsLayer, xsm, ysm, 4, pixw)

But pixw_{0|1|2} are never used, and it look like it should have been:
        pixw[0] = random.randrange(lum + 64)
        pixw[1] = random.randrange(lum + 64)
        pixw[2] = random.randrange(lum + 64)

However, as the resident physics nazi, I want to point out that star colors are not completely random, they have the color of the radiating black body at a given temperature, in other words their hue is constrained to what is known as the "Plankian locus" (for instance you will never see a pink or green star). There are several ways to do that, from sampling an adequate color gradient to computing the approximate RGB of a random temperature(*).

In addition the script can likely be made faster by removing either lines 83 or 84 because these are duplicates.

Speaking of which, using set_pixel() is slow; in Python you can use "pixel regions" to get an array that represents the drawable, update the array, and then update the layer from the array at the end.

Adapting code from first reference below gives something like this:

Attachment:
Stars.png
Stars.png [ 18.82 KiB | Viewed 1128 times ]


Of course this isn't perfect because the temperatures are drawn linearly at random in the 3000K-15000K range and the actual distribution isn't linear.


(*) See:
https://www.codetd.com/en/article/9132898
https://forum.arduino.cc/t/kelvin-to-rg ... ion/883498

_________________
Image


Top
 Post subject: Re: Create a starfield plugin (Faster than "starry sky.scm")
PostPosted: Mon May 16, 2022 9:55 am  (#6) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2231
Location: Poland
Hi Pocholo.

Very good job. :hi5
What would you say if I put this code in our P&M Cosmos - instead based on plug_in_sparkle (also creates nice stars but is slower and freezes at times)?
This change would give more control over the quantity and introduce randomness to the position.

_________________
Image

Slava
Ukraini!


Top
 Post subject: Re: Create a starfield plugin (Faster than "starry sky.scm")
PostPosted: Mon May 16, 2022 1:55 pm  (#7) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1195
MareroQ wrote:
Hi Pocholo.

Very good job. :hi5
What would you say if I put this code in our P&M Cosmos - instead based on plug_in_sparkle (also creates nice stars but is slower and freezes at times)?
This change would give more control over the quantity and introduce randomness to the position.

Yes, Marrek. Go ahead, "do it" :coolthup

_________________
https://www.deviantart.com/pocholo17
Image


Top
 Post subject: Re: Create a starfield plugin (Faster than "starry sky.scm")
PostPosted: Mon May 16, 2022 2:30 pm  (#8) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2231
Location: Poland
:hi5
Ready.
My favorite toy is updated. :yes


Attachments:
P&M Cosmos-1.4.jpg
P&M Cosmos-1.4.jpg [ 259.22 KiB | Viewed 995 times ]

_________________
Image

Slava
Ukraini!
Top
 Post subject: Re: Create a starfield plugin (Faster than "starry sky.scm")
PostPosted: Thu May 19, 2022 1:50 am  (#9) 
Offline
GimpChat Member
User avatar

Joined: Jul 06, 2013
Posts: 2605
Location: California
Where is the update?


Top
 Post subject: Re: Create a starfield plugin (Faster than "starry sky.scm")
PostPosted: Thu May 19, 2022 8:57 am  (#10) 
Offline
GimpChat Member
User avatar

Joined: Sep 27, 2016
Posts: 345
Location: Germany, BW
You can find it here:
https://www.gimpscripts.net/2022/04/p-cosmos.html

_________________
Regards
nelo

(Gimp 2.10 on Linux Mint MATE 20.1)


Top
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) How to make plugin run faster

13

No new posts Attachment(s) Create a Notebook plugin

9

No new posts Attachment(s) Create an Orange plugin

7

No new posts Attachment(s) Create a pillow plugin updated to Ver 2

15

No new posts Attachment(s) create a web and spiderman text plugin

2



* Login  



Powered by phpBB3 © phpBB Group