It is currently Sun Sep 27, 2026 3:02 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Identical images generated with the random function ???
PostPosted: Thu May 28, 2015 1:47 pm  (#1) 
Offline
GimpChat Member
User avatar

Joined: Dec 26, 2014
Posts: 205
GIMP Version: 2.6
Operating System: Windows
GIMP Experience: Intermediate Level



My script operates left to right across the image, moving each column in turn up or down randomly (by the inputted amount) relative to the previous column

The first image below is pre script
Attachment:
red-blue.jpg
red-blue.jpg [ 86.79 KiB | Viewed 2401 times ]

The second image is post script
Attachment:
red-blue 4pixel shift.jpg
red-blue 4pixel shift.jpg [ 212.07 KiB | Viewed 2401 times ]

Though it works the strange thing is, every time I close gimp and then reopen and run the script again (keeping the default value 4 pixels) the exact same image is generated, how can this be when its using the random function.

I assumed my script was at fault until I found I could get different image patterns, but to do so I needed to open the original image from within gimp

If anyone wishes to try it the script
Attachment:
move-columns.scm [1.13 KiB]
Downloaded 260 times
is placed on the menu bar, named Miscellaneous


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: Identical images generated with the random function ???
PostPosted: Thu May 28, 2015 1:53 pm  (#2) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
Steve,
before using the random function you better set the random seed with a statement like:
(srand (car (gettimeofday))) ; set randon seed
otherwise the random function returns always the same values

_________________
"Where am I ?"


Top
 Post subject: Re: Identical images generated with the random function ???
PostPosted: Thu May 28, 2015 2:06 pm  (#3) 
Offline
GimpChat Member
User avatar

Joined: Dec 26, 2014
Posts: 205
dinasset wrote:
Steve,
before using the random function you better set the random seed with a statement like:
(srand (car (gettimeofday))) ; set randon seed
otherwise the random function returns always the same values


That was quick :tyspin i've been mulling this over for a week :oops:

This looks like it will solve my problem, many thanks :)


Top
 Post subject: Re: Identical images generated with the random function ???
PostPosted: Thu May 28, 2015 2:14 pm  (#4) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
me too I learned that from another post, Gimpchat is spreading knowledge around!
It's like a ...Gimp-pedia!

_________________
"Where am I ?"


Top
 Post subject: Re: Identical images generated with the random function ???
PostPosted: Thu May 28, 2015 2:47 pm  (#5) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
@Steve
Since your script is modifying an existing image (rather than creating a new image from scratch) it would be more appropriate to use undo-group-start/end (rather than disable/enable).
Also the undo-group-end should be after the last command which changes the image contents - in this case that's the -flatten command.

ie:
(gimp-image-undo-group-start image)
  :
  :
(gimp-selection-none image)
(gimp-image-flatten image)
(gimp-image-undo-group-end image)
(gimp-displays-flush)


Top
 Post subject: Re: Identical images generated with the random function ???
PostPosted: Thu May 28, 2015 2:49 pm  (#6) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4557
Location: Canada
wow that's cool reminds me of northern lights the way the gradient mixed randomly.

_________________
Image
Visualize your and others dreams coming true.


Top
 Post subject: Re: Identical images generated with the random function ???
PostPosted: Thu May 28, 2015 3:41 pm  (#7) 
Offline
GimpChat Member
User avatar

Joined: Dec 26, 2014
Posts: 205
jontait2 wrote:
@Steve
Since your script is modifying an existing image (rather than creating a new image from scratch) it would be more appropriate to use undo-group-start/end (rather than disable/enable).
Also the undo-group-end should be after the last command which changes the image contents - in this case that's the -flatten command.

ie:
(gimp-image-undo-group-start image)
  :
  :
(gimp-selection-none image)
(gimp-image-flatten image)
(gimp-image-undo-group-end image)
(gimp-displays-flush)

Thanks for taking the time to explain and put me on the right track, much appreciated :)


Top
 Post subject: Re: Identical images generated with the random function ???
PostPosted: Thu May 28, 2015 3:46 pm  (#8) 
Offline
GimpChat Member
User avatar

Joined: Dec 26, 2014
Posts: 205
trandoductin wrote:
wow that's cool reminds me of northern lights the way the gradient mixed randomly.


Thanks :) northern lights, i'll have to have a try at those


Top
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group