save and restore code

PerPer
edited October 2013 in How To...

Hi!

Not sure this is possible. guess not but say I got this simple sketch below. Is it possible to make a snapshot and save the sketch in some way so next time I runs the sketch it starts upp at the same position as it was stored. To store the coordinates in some way? So for example save the lines position and correct random backgroundcolor. As if I would save a image but instead of the image saving the coordinates and positions of the code for painting the image.

what I really want to do is to do this in javascriptmode, and then email the stored code to my mail. any hints or ideas?

void setup()
{
  size(800, 600);
  frameRate(2);
}

void draw()
{
  background(random(0, 255), 0, 0);
  stroke(255);
  line(random(width), random(height), random(width), random(height));
}

Answers

  • See saveStrings() and loadStrings(), for example.

    Not sure if it works in JS mode. Sending e-mail in JS mode is probably even less feasible.

  • There are three things here

    (1) Saving a file in JS mode

    (2) Creating the file content - in this case the line co-ordinates and colour data

    (3) Attaching the file to an email

    AFAIK - since the JavaScript will come from a web server you will not be able to access the local file system and that any file would have to be saved on the host web server. It is unlikely that you can send the email directly from JS but it would be possible to send an http request to the web server to run a PHP script to send the email.

    Try posting a question regarding (1) and (3) in JavaScript Mode category.

  • okej. thanks. ill try that. I know it works with "postToWeb" but I want the same thing from online javascript

Sign In or Register to comment.