We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › a little help please
Page Index Toggle Pages: 1
a little help please (Read 768 times)
a little help please
May 8th, 2010, 12:29pm
 
I'm trying to learn processing and it's driving me crazy.  I want to draw on a rectangle, exclude anything drawn outside (on the background) and save the result.  should be easy...it isn't.
I've tried to check the pixel color and change the stroke color, I've tried to draw to an image buffer and copy that to the canvas....I'm just stuck.  any help would be appreciated

Quote:
PImage img;
void setup(){
  size( 200, 250);
  background(125);
  smooth();
  strokeWeight(5);
   rectMode(CENTER);
    img = createImage(102, 150, ARGB);
  for(int i=0; i < img.pixels.length; i++) {
    img.pixels[i] = color(200, 90, 102);}
  
noStroke();
rect(width/2,height/2,100,150);
ellipseMode(CENTER);
stroke(0);
strokeWeight(4);
fill(125);
ellipse(width/2,height/5.25,15,15);
image(img,width/2-52,height/2-75);
}
void draw(){
  
  stroke(0);
  if(mousePressed) {
    line(mouseX, mouseY, pmouseX, pmouseY);
  }
}

void keyPressed() {
    save("line.tif");
  } 


Re: a little help please
Reply #1 - May 8th, 2010, 12:44pm
 
Code:
PGraphics img;
int imgPosX, imgPosY;

void setup(){
size( 200, 250);
background(125);
smooth();
strokeWeight(5);
rectMode(CENTER);
img = createGraphics(102, 150, JAVA2D);
img.beginDraw();
img.fill(200, 90, 102);
img.rect(0, 0, img.width, img.height);
img.endDraw();

noStroke();
rect(width/2,height/2,100,150);
ellipseMode(CENTER);
stroke(0);
strokeWeight(4);
fill(125);
ellipse(width/2,height/5.25,15,15);
imgPosX = width/2-52;
imgPosY = height/2-75;
image(img, imgPosX, imgPosY);
}
void draw(){

stroke(0);
if(mousePressed) {
img.beginDraw();
img.strokeWeight(4);
img.fill(125);
img.line(mouseX-imgPosX, mouseY-imgPosY, pmouseX-imgPosX, pmouseY-imgPosY);
img.endDraw();
image(img, imgPosX, imgPosY);
}
}

void keyPressed() {
img.save("line.tif");
}

Please, use more descriptive subject lines. Thanks.
Re: a little help please
Reply #2 - May 8th, 2010, 3:00pm
 
you rock....thank you very much
Page Index Toggle Pages: 1