How to create images by dragging mouse?

edited October 2013 in How To...

I need to make something like this: rednoise.org/sketches/ImageViewer/ The code needs to have arrays and functions. I have no idea where to start please help.

Answers

  • Since you didn't make any questions I will assume your question is "Where should I start?".

    These may be good places to start:

    http://processing.org/tutorials/ (text) http://funprogramming.org (video)

  • My question is how can I draw images by dragging my mouse?

    lets say rect is a image, I want the image to stay there after I release my mouse. How to I do this?

    void setup(){
      size (500,500);
      background (255);
    }
    void draw() {
      background(255);
      if (mousePressed == true) {
        rect (mouseX,mouseY,mouseX,mouseY);
      }
      fill (245,20,20);
    }
    
  • edited October 2013

    I've got an example of it in this following post: http://forum.processing.org/two/discussion/comment/375#Comment_375

  • It is often a good idea to explore the examples coming with Processing, too.

  • edited October 2013

    Maybe something like this?

    
    color cline;
    float lastX,lastY;
    
    void setup () {
      size (640, 480);
      background (200);
      cline = color (0);
    }
    
    void draw () {
     
     float interpolatedX = lerp (lastX,mouseX, 0.5f);
     float interpolatedY = lerp (lastY,mouseY, 0.5f);
     
     if (mousePressed) {
      stroke(cline);
      strokeWeight (3);
      line (lastX,lastY,interpolatedX,interpolatedY);
      lastX=interpolatedX;
      lastY=interpolatedY;
     }
     else {
       lastX=pmouseX;
       lastY=pmouseY;
     }
     
    }
    
    void keyPressed () {
      
     println ("key: "+key); 
     if (key == 'r')  cline = color (255,0,0);
     if (key == 'g')  cline = color (0,255,0);
     if (key == 'b')  cline = color (0,0,255);
     if (key == 'n')  cline = color (0);
      
    }
     
Sign In or Register to comment.