|
Author |
Topic: draw to memory (Read 2283 times) |
|
Dimitre
|
draw to memory
« on: Dec 16th, 2002, 10:39pm » |
|
it could be very interesting if proce55ing allows me to use drawing commands in a pixel array without show on screen. ex: if I could draw in pixels2[] array, and so pass it to pixels[] array with blended pixels.
|
|
|
|
Glen Murphy
|
Re: draw to memory
« Reply #1 on: Dec 17th, 2002, 12:39am » |
|
I was thinking about this very thing this morning, but I figured that it would probably add another layer of complication where you could just arraycopy pixels[] to pixels2[], blank pixels[] out with another arraycopy and draw to it, then blend pixels2[] back in instead. I've found System.arraycopy to be blazingly fast (tip o' the hat to Casey for pointing it out) so I don't think it would slow things down much at all.
|
|
|
|
fry
|
Re: draw to memory
« Reply #2 on: Dec 17th, 2002, 2:48am » |
|
yeah, as mentioned elsewhere i believe, this will be possible in the future. right now, all of the drawing happens through an object called 'BGraphics'. it's not quite clean enough yet to be used separately, but once that's taken care of, you'll be able to create another BGraphics, and then copy its pixel array. actually, if you're feeling nutty, you might try using: [usual disclaimers regarding nuttiness apply: 1) this code may not work in the future 2) this code may not even work perfectly right now.] Code:// do this once BGraphics bg = new BGraphics(100, 100); // do these each time you need a fresh set of image bg.beginFrame(); bg.rect(10, 10, 80, 80); // or other drawing commands here bg.endFrame(); |
| and then use use arraycopy to grab pixels from bg.pixels. most of the commands (line, beginShape, etc) should work if you just put "bg." in front of them. a better future implementation of this will provide an accessible BImage object that can be drawn. for instance, to draw your offscreen image at the mouse location: Code:// this doesn't work yet, and will break p5 image(bg.image, mouseX, mouseY); // although this version may BImage offscreenImage = new BImage(bg.pixels, bg.width, bg.height, RGB); // do once image(offscreenImage, mouseX, mouseY); // do each time |
| better support for this will coincide with a version of the image() function that lets you select subsections of the source image to be drawn, as recommended elsewhere by another p5 user.
|
|
|
|
Dimitre
|
Re: draw to memory
« Reply #3 on: Dec 17th, 2002, 1:11pm » |
|
Thanks guys, I will try one of these solutions!
|
|
|
|
|