Here's the whole code including Tom's wrapping line method.
I'm doing a wrap around scrolling number, which works fine. The problem is when writing out to the AIExport.
If anyone can see a solution, I'd appreciate it.
Sorry, but it's in 68 and not beta, due to PGraphics and just not getting around to it, so forgive the smoothLine function(), I'm not too arsed about it myself.
Code:
// Rather than snapshot each frame, just produce a vector with a list of points that can be dumped on exit
// as ai.run and snapshot are killer on the cpu
AIExport ai;
BGraphics buf;
color pen;
int backSize = 20;
void setup() {
size(400,400);
buf = new BGraphics(400,400); // This can be any size screen+
buf.background(255,255,255);
xoffsets = new float[] { -width, 0, width,
-width, 0, width,
-width, 0, width };
yoffsets = new float[] { -height, -height, -height,
0, 0, 0,
height, height, height };
ai = new AIExport(this, 1);
ai.setContinuousRecordingFrameRate(0);
ai.turnTransparencyOn();
pen = color(30,30,30,40);
bx = buf.width/2-width;
by = buf.height/2-height;
ellipseMode(CENTER_DIAMETER);
strokeWeight(2);
blitX = width/2-backSize/2;
blitY = height/2-backSize/2;
noSmooth();
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
}
void loop() {
ai.takeSnapShot();
ai.run();
if(pause) {
drawscn();
return;
}
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+xmag,height/2+ymag,pen);
backBlit();
ai.ai_line(bx, by, bx+xmag, by+ymag);
}
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.replicate(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.replicate(g,blitX+x1,blitY+y1,blitX+x2+x1,blitY+y2+y1, 0,0,x2,y2);
}
}
if(y3>=buf.height-backSize) {
buf.replicate(g,blitX,blitY+y1,blitX+backSize,blitY+y1+y2, x3,0,x3+backSize,y2);
}
buf.replicate(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) {
replicate(buf,0,y3,x2,y3+y1, x1,0,x1+x2,y1);
// blit X and Y wrap
if(y3>=buf.height-height) {
replicate(buf,0,0,x2,y2,x1, y1,x1+x2,y1+y2);
}
}
if(y3>=buf.height-height) {
replicate(buf,x3,0,x3+x1,y2, 0,y1,x1,y1+y2);
}
replicate(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.025;
ymag = (pmouseY-height/2)*0.025;
bx = (bx+xmag)%buf.width;
by = (by+ymag)%buf.height;
}
public void smoothLine(BGraphics g, float x1, float y1, float x2, float 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(); // strokeweight>1 causes strange behaviour, so noStroke to be safe, probably quicker, too.
g.ellipse(x1, y1, g.strokeWeight*2,g.strokeWeight*2); // cap previous line with rounded end
}
}
boolean pause = false;
boolean toggle = false;
int saved;
void keyPressed() {
if(key == ' ' && !toggle) {pause=!pause; toggle=true;}
if(key == 's') {
ai.setFileName("perfect.ai");
ai.dumpSnapShots();
// ai.beginWriting();
}
}
void keyReleased() {
if(key == ' ') {toggle=false;}
if(key == 's') {buf.save("ps-"+saved+++".tga");}
if(key == 'c') {buf.background(255);}
}
float xoffsets[];
float yoffsets[];
void wrappedLine(float x1, float y1, float x2, float y2) {
ai.ai_stroke(pen);
if (x1 < 0) {
while (x1 < 0) {
x1 += width;
x2 += width;
}
}
else if (x1 > width) {
while (x1 > width) {
x1 -= width;
x2 -= width;
}
}
if (y1 < 0) {
while (y1 < 0) {
y1 += height;
y2 += height;
}
}
else if (y1 > height) {
while (y1 > height) {
y1 -= height;
y2 -= height;
}
}
for (int i = 0; i < xoffsets.length; i++) {
ai.ai_line(x1+xoffsets[i],y1+yoffsets[i],x2+xoffsets[i],y2+yoffsets[i]);
}
}