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 › No go in 91
Page Index Toggle Pages: 1
No go in 91 (Read 971 times)
No go in 91
Jul 19th, 2005, 3:56pm
 
I'm porting this across from 68 to 91. I've done the obvious things (I hope), but am getting a no show from the drawing function.

Replicate is now copy, but the syntax is the same I think. I'm I missing something obvious here?

Ignore the unoptimized bits like smoothLine, which are no longer necessary in beta.

Code:

PGraphics buf;
color pen;

int backSize = 20;

void setup() {

 size(300,300);
 buf = new PGraphics(600,600,null);  // This can be any size screen+
 buf.defaults();
 
 buf.background(255,255,255);
 background(255);

 pen = color(100,100,100,10);

 bx = buf.width/2-width;
 by = buf.height/2-height;

 ellipseMode(CENTER);
 strokeWeight(2);
 blitX = width/2-backSize/2;
 blitY = height/2-backSize/2;
 
 noSmooth();

 setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
}

void draw() {

 updatePos();

 // Blit buffer to screen, draw line and blit back modified section to buffer

 drawscn();

 if(mousePressed) {
 smoothLine(g,width/2,height/2,width/2+(int)xmag,height/2+(int)ymag,pen);
 backBlit();
 }
 stroke(0,255,0);
 ellipse(width/2, height/2, 2,2);
}

int blitX,blitY;

void backBlit() {

 x3=(((int)bx%buf.width)+buf.width+blitX)%buf.width;
 y3=(((int)by%buf.height)+buf.height+blitX)%buf.height;

 x1 = abs(buf.width-x3);
 x2 = abs(x1-backSize);
 y1 = abs(buf.height-y3);
 y2 = abs(y1-backSize);

 // blit X wrap around
 if(x3>=buf.width-backSize) {
   buf.copy(g,blitX+x1,blitY,blitX+x2+x1,blitY+backSize, 0,y3,x2,y3+backSize);

   // blit X and Y wrap
   if(y3>=buf.height-backSize) {
     buf.copy(g,blitX+x1,blitY+y1,blitX+x2+x1,blitY+y2+y1, 0,0,x2,y2);
   }
 }

 if(y3>=buf.height-backSize) {
   buf.copy(g,blitX,blitY+y1,blitX+backSize,blitY+y1+y2, x3,0,x3+backSize,y2);
 }

 buf.copy(g,blitX,blitY,blitX+backSize,blitY+backSize, x3,y3,x3+backSize,y3+backSize);
}

// draw large Bimage to screen as a continuous surface.
int x1,y1,x2,y2,x3,y3;

void drawscn() {

 x3=(((int)bx%buf.width)+buf.width)%buf.width;
 y3=(((int)by%buf.height)+buf.height)%buf.height;

 x1=abs(buf.width-x3);
 x2=abs(width-x1);
 y1=abs(buf.height-y3);
 y2=abs(height-y1);

 // blit X wrap around
 if(x3>=buf.width-width) {
   copy(buf,0,y3,x2,y3+y1, x1,0,x1+x2,y1);

   // blit X and Y wrap
   if(y3>=buf.height-height) {
     copy(buf,0,0,x2,y2,x1, y1,x1+x2,y1+y2);
   }
 }

 if(y3>=buf.height-height) {
   copy(buf,x3,0,x3+x1,y2, 0,y1,x1,y1+y2);
 }

 copy(buf,x3,y3,x3+x1,y3+y1, 0,0,x1,y1);
}

float bx,by;
float xmag, ymag = 0;

void updatePos() {
 xmag = (pmouseX-width/2)*0.050;
 ymag = (pmouseY-height/2)*0.050;
 bx = (bx+xmag)%buf.width;
 by = (by+ymag)%buf.height;
}

public void smoothLine(PGraphics g, int x1, int y1, int x2, int y2, color penCol) {
 g.stroke(penCol);      // Stroke on @ set weight
 g.line(x1,y1,x2,y2);     // draw the line
/*
 if(g.strokeWeight>1) {
   g.fill(penCol);
   g.noStroke();  
   g.ellipse(x1, y1, g.strokeWeight*2,g.strokeWeight*2);  // cap previous line with rounded end
 }
 */
}
Re: No go in 91
Reply #1 - Jul 19th, 2005, 5:24pm
 
PGraphics is P2D which is not yet finished. so making your own PGraphics and drawing to that won't work.

you might try with a PGraphics2 or PGraphics3, but not realizing how many people were doing this, we didn't finalize/test this enough before beta. fixes for it are coming soon, prolly in the mid-90s..
Re: No go in 91
Reply #2 - Jul 19th, 2005, 8:57pm
 

No, tried those and it's a blow out.

Never mind, I was only really interested because window shade doesn't seem to work properly with 68 and I need the transparency.

I'll find another solution.
Page Index Toggle Pages: 1