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
}
*/
}