cutterkom / generativeart

Create Generative Art with R
GNU General Public License v3.0
916 stars 163 forks source link

Correct Syntax to use a seed again? with the same color and background? #15

Open data2700 opened 3 years ago

data2700 commented 3 years ago

The documentation mentions that you can use the seed to generate the same art, but I have not been able to get the set.seed() command to work. Can someone please post an example of code using the same seed - either with set.seed() or whatever you have done that worked.

Stramon1um commented 3 years ago

yes, same here. I've been trying different combinations but seed it's still random, even with generate_seeds function.

EDIT:

I managed to regenerate the two images in the README.md with the two seeds provided by the author, but it was pretty tricky. Briefly:

regenerate_img(seed_to_recreate = 5451, filetype = "png", polar = FALSE)

and it will regenerate it in black and white as default (no chance apparently to set specific colors while regenereting it by seed). If you put a seed that doesn't appear in the logfile, you will get an error.

data2700 commented 3 years ago

Thanks for that :) I guess for the colors it will require changes to the function regenerate_img function itself. Another route is changes to the logging so that the log file capture the colors used along with the information that is currently captured. I haven't worked with R long enough to work out how to do this, but maybe someone here can help? :)

MikeKSmith commented 4 months ago

I suggest adding ellipses to the regenerate_img function and the generate_plot function within it so that colours can be passed through to the plotting function.

regenerate_img <- function (seed_to_recreate, filetype = "png", polar = FALSE, ...) { formula <- get_formula_from_logfile(seed_to_recreate, filetype) seeds <- get_seed_from_logfile(seed_to_recreate) purrr::map(seeds, function(seed) { set.seed(seed) file_name <- generate_filename(seed, filetype) logfile <- check_logfile_existence() logfile <- generate_logfile_entry(logfile, formula, seed, file_name) df <- generate_data(formula) plot <- generate_plot(df, file_name, polar, filetype, ...) }) }