|
Author |
Topic: Wrap around BImage (Read 2341 times) |
|
Mark Hill
|
Wrap around BImage
« on: Mar 22nd, 2005, 3:05pm » |
|
If anyone's interested here's some code that takes a large BImage and displays it as a continous scrolling wrap around image. It runs pretty fast, too! I'm looking to add some draw functions that take into account the wrap and will post them up if successful! BGraphics buf; void setup() { size(200,200); background(0); buf = new BGraphics(800,800); for(int i=0; i<buf.pixels.length; i++) { buf.pixels[i] = 0; } bx = buf.width/2; by = buf.height/2; buf.rectMode(CENTER_DIAMETER); setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); } void loop() { buf.rect((random(20,buf.width-20)), (random(20,buf.height-20)), 10,10); updatePos(); drawscn(); } // draw large Bimage to screen as a continuous surface. int x1,y1,x2,y2,x3,y3; void drawscn() { x1=width; y1=height; x2=0; y2=0; x3=(int)bx; y3=(int)by; x1=abs(buf.width-(int)bx); x2=abs(width-x1); y1=abs(buf.height-(int)by); y2=abs(height-y1); if(bx>buf.width-width) { replicate(buf,0,y3,x2,y3+y1,x1,0,x1+x2,y1); if(by>buf.height-height) { replicate(buf,0,0,x2,y2,x1,y1,x1+x2,y1+y2); } } if(by>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; float diff; void updatePos() { float xlim = buf.width; float ylim = buf.height; xmag = (mouseX-width/2)*0.050; ymag = (mouseY-height/2)*0.050; if(xmag< 0) { bx= (bx-xmag)% xlim; } else if(xmag>0) { // decrement bx = xlim - bx; bx = (bx+xmag) % xlim; bx = xlim-bx; } if(ymag< 0) { by= (by-ymag)%ylim; } else if(ymag>0) { // decrement by = ylim - by; by = (by+ymag) % ylim; by = ylim - by; } }
|
|
|
|
|