A very simple draw and save program

A very simple draw and save program that I am sharing as an example.

// https://processing.org/tutorials/
// https://processing.org/reference/

// https://processing.org/reference/saveFrame_.html
// https://processing.org/reference/PImage.html
// https://processing.org/reference/image_.html
// https://processing.org/reference/get_.html
// https://processing.org/reference/loadImage_.html

// https://processing.org/reference/width.html
// https://processing.org/reference/height.html

// https://processing.org/tutorials/interactivity/
// https://processing.org/reference/mouseX.html
// https://processing.org/reference/mouseY.html
// https://processing.org/reference/keyPressed_.html
// https://processing.org/reference/mousePressed_.html

PImage img;

void setup()
  {
  size(200, 100);
  }

void draw()
  {
  //  background(204);
  stroke(0);
  strokeWeight(1);
  line(width/2, 0, width/2, height);
  
  stroke(100, 10, 128);
  strokeWeight(8);
  if (mousePressed && mouseX < width/2 && pmouseX < width/2)
    line(mouseX, mouseY, pmouseX, pmouseY);  
  }
  
void  keyPressed()
    {
    if (key == 's')  
//      saveFrame("chromosone.png");
      img = get(0, 0, 100, 100);
      img.save("chromosone.png");
    
    if (key == 'b')
      background(204);
    
    if (key == 'p')
      {
      img = loadImage("chromosone.png");
      image(img, 100, 0);
      }
    }

chromosone

chromosone

1 Like

You should allow ppl to provide the name to the file to save. Some ideas:

  • Create a 2nd sketch and design the input form there (hard way)
  • Use a Java widget, an input box (Easier way)

Kf

chromosone
made possible by GLV’s Photoshop++

1 Like

That made me laugh out loud!

I like the choice of colour!

:sunny:

1 Like