Capital of Statistics » R Language

  1. yanlinlin82
    Key Master

    I feel it is too quiet here! So let me send some fire:

    Fire <- function(row = 100col = 100time = 500fade = 0.03) {

      fire <- matrix(0colrow);
      fire[,1] <- runif(col);

      for (t in 1:time) {
        image(firecol = rev(heat.colors(row)),
          axes = FALSEmain = "Welcome to COS Forum!");

        fire <- (
          fire +
          cbind(fire[,1], fire[c(col,1:(col-1)), 1:(row - 1)]) +
          cbind(fire[,1], fire[                , 1:(row - 1)]) +
          cbind(fire[,1], fire[c(2:col,1)      , 1:(row - 1)])
          ) / 4;
        fire <- cbind(fire[,1], (fire + fade / 5 - runif(1max = fade))[,-1]);
        fire[fire < 0] <- 0;

        r <- runif(1);
        if (r < .1fire[,1] <- fire[,1][c(2:col1)];
        if (r > .9fire[,1] <- fire[,1][c(col1:(col-1))];
      };
      NULL;
    }

    Fire()

    Posted 1 year ago #
  2. Taiyun
    Moderator

    Looks great. However, it can be more vivid.

    In addition, we can simulate some biological phenomena by cellular automaton(for example, the weed were destroyed by random-fire and come to life automatic with the certain probability, we can know whether the weed will become extinct, etc.)

    :)

    Posted 1 year ago #
  3. dao
    Member

    Ok, it's very shinning in my computer ...
    And i have a question, is it possible to combine R and flash together?

    Posted 1 year ago #
  4. yanlinlin82
    Key Master

    Yes. Since R can call C function easily, and flash is an ActiveX control, which can be easily called by C/C++ code, it is absolutely possible to combine them together by writing a media module.

    Posted 1 year ago #
  5. Taiyun
    Moderator

    See Yihui's animation package to combine R and flash together.

    Posted 1 year ago #
  6. yihui
    Key Master

    Theoretically you can generate the flash animation by

    library(animation)
    saveSWF(Fire(), interval = 0.05, dev = "pdf", outdir = getwd(),
    	para = list(mar = c(0, 0, 2, 0)))

    but it is actually impossible to get the SWF output due to the too complex structure of the PDF file (~180 Megabytes, too many shapes in the file that SWF Tools could not afford).

    However, you can use the png format to create the animation:

    library(animation)
    saveSWF(Fire(), interval = 0.05, dev = "png", outdir = getwd(),
    	para = list(mar = c(0, 0, 2, 0)))

    The above code will generate 500 png image frames (~3.2M) and they will be combined together to an SWF file.

    Posted 1 year ago #
  7. yihui
    Key Master

    For those who want to see the Flash animation, I've made one here: http://yihui.name/en/2009/06/simulation-of-burning-fire-in-r/

    Posted 1 year ago #
  8. dao
    Member

    I see, it's really cool, thank you very much :)

    Posted 1 year ago #
  9. yanlinlin82
    Key Master

    I am so glad that my first fire has burnt much wider than I thought before:
    http://blog.revolution-computing.com/2009/06/animate-r-graphics-with-flash.html
    Thanks to Yihui and David! And hope our forum be hotter and hotter in the future!

    Posted 1 year ago #
  10. yihui
    Key Master

    It's you whom we should thank :-)

    haha, I have an idea on making our forum more popular: we can write solutions for R-help list here, and it can surely attract more members to COS.

    Posted 1 year ago #
  11. yanlinlin82
    Key Master

    I agree. Some of the problems and solutions are very beautiful and worth collecting.

    Posted 1 year ago #
  12. achates
    Member

    Your guys are amazing! It seems R could do everything~~really? I can't help thinking it . Is it difficult to understand and apply to for a medical student? You know, in clinic there are many procedures like disease recurrence and wound recovery, and there are many influence and questions , need to solve. haha, was I too greedy? I am just a medical man knowing a little about math and computer.

    Posted 1 year ago #
  13. yanlinlin82
    Key Master

    Yes, with the very flexible interface, R can do almost everything in computer if you want. However, some of the things doing by R are not the best solutions. We were just trying to show off the tricks, which may attract people into R community.

    Everything in western sciences is learnable. R is not difficult to a medical student, since there are so many applications of statistical analysis in the field, and I think you may have already learned some of the methods in your course. That's enough to enter the R world.

    Posted 1 year ago #
  14. lovebluesky
    Member

    it's cool, i hope that i could reach your level some day

    Posted 7 months ago #

RSS feed for this topic

Reply

You must log in to post.