[PLUGIN] Canvas

Forum Home Forum Home > Construct 2 Development > Plugins for Construct 2
 Post Reply Post Reply Page  <12345 17>
Author
11,882 Rep
Post Options Post Options   Quote Yann Quote  Post ReplyReply Direct Link To This Post Posted: 15 Nov 2011 at 7:59pm
Oh yeah you're completely right
I just tested with your idea

But! mine works too, I modified the acts.pasteObject function this way :

ctx.save();
ctx.scale(this.canvas.width/this.width, this.canvas.height/this.height);
ctx.rotate(-this.angle);
ctx.translate(-this.bquad.tlx, -this.bquad.tly);
ctx.globalCompositeOperation = "destination-out";
instances[x].draw(ctx);
ctx.globalCompositeOperation = "source-out";
ctx.restore();


And it erase perfectly, even if it's a bit weird now that I think about it.

But yeah I'll stick with your idea... it's simpler

Edited by Yann - 15 Nov 2011 at 8:00pm
Back to Top
5,315 Rep
Post Options Post Options   Quote Pode Quote  Post ReplyReply Direct Link To This Post Posted: 18 Nov 2011 at 8:43pm
@R0J0hound: is it possible to add a function to you Canvas plugin to retrieve the canvas' image as data (I think the best is to retrieve a base64 text string) ?
I'm trying to add a property inside the canvas object, but it doesn't works...
(In fact, I'm trying to implement a floodfill like there http://www.williammalone.com/articles/html5-canvas-javascript-paint-bucket-tool/, but perhaps I'm trying to climb a too high mountain...
Back to Top
16,863 Rep
Post Options Post Options   Quote newt Quote  Post ReplyReply Direct Link To This Post Posted: 18 Nov 2011 at 8:54pm
Originally posted by Pode Pode wrote:

@R0J0hound: is it possible to add a function to you Canvas plugin to retrieve the canvas' image as data (I think the best is to retrieve a base64 text string) ?
I'm trying to add a property inside the canvas object, but it doesn't works...
(In fact, I'm trying to implement a floodfill like there http://www.williammalone.com/articles/html5-canvas-javascript-paint-bucket-tool/, but perhaps I'm trying to climb a too high mountain...


rgbaAt gets the color of the pixel at xy in the canvas.
So you could to a nested loop like:
for x=0 to canvas.width
->for y=0 to canvas.height
-->system compare rgbaAt(loopindex("x"),loopindex("y"))= n do stuff

Very slow though, and recursion will slow it a bit as well.
Back to Top
5,315 Rep
Post Options Post Options   Quote Pode Quote  Post ReplyReply Direct Link To This Post Posted: 18 Nov 2011 at 10:46pm
newt: yes that could emulate the behavior. The problem is that a true floodfill needs to start in a spiral, starting from the clicked pixel. It needs a structure to hold all that, it's a headache to implement it outside the core of the script ;)...
Back to Top
16,863 Rep
Post Options Post Options   Quote newt Quote  Post ReplyReply Direct Link To This Post Posted: 18 Nov 2011 at 10:57pm
For that you could use x+1, x-1, y+1, y-1, or sin, and cos.
Then there's the datastructures plug('s) to store things.
Back to Top
5,315 Rep
Post Options Post Options   Quote Pode Quote  Post ReplyReply Direct Link To This Post Posted: 19 Nov 2011 at 11:08am
@newt: something that annoys me, is that the original floodfill implementation works only with recursion. And I don't think you can build something like that with events in C2...
Back to Top
7,112 Rep
Post Options Post Options   Quote R0J0hound Quote  Post ReplyReply Direct Link To This Post Posted: 19 Nov 2011 at 7:53pm
Doesn't the "rgbaAt" expression do the trick?

There are other implementations of flood fill that don't use recursion:
http://en.wikipedia.org/wiki/Flood_fill

Here I used the array object to implement a queue to keep track of what points to fill next.
http://dl.dropbox.com/u/5426011/examples%208/floodfill.capx
Back to Top
5,315 Rep
Post Options Post Options   Quote Pode Quote  Post ReplyReply Direct Link To This Post Posted: 19 Nov 2011 at 9:27pm
@R0J0hound: it's slow as hell, but it's really, really, really impressive ! You're the best !
Back to Top
4,250 Rep
Post Options Post Options   Quote Ize Quote  Post ReplyReply Direct Link To This Post Posted: 24 Nov 2011 at 10:06am
HAHA Awesome Guys!

@R0j0hound you should really integrate the PasteDelete stuff officially...

I've made this using the modified Canvas plugin from Yann in a few Minutes:

CLICK ME!!!

The black color is actually the layouts background color. The holes in the Canvas are made at start using PasteDelete :D

EDIT:
Updated with some more lemmings :D

Runs pretty decent imo:
http://dl.dropbox.com/u/45711709/LemTest2/index.html

Edited by Ize - 24 Nov 2011 at 10:43am
Back to Top
7,112 Rep
Post Options Post Options   Quote R0J0hound Quote  Post ReplyReply Direct Link To This Post Posted: 25 Nov 2011 at 5:47am
Originally posted by Ize Ize wrote:


@R0j0hound you should really integrate the PasteDelete stuff officially...


I won't integrate it, because it will only work with the Sprite object if it's effect is set to "none". If the sprite uses any other effect PasteDelete won't work right. It also won't work with TiledBackground or Canvas objects either.

Just give whatever object you want to delete from the canvas a "destination out" effect before pasting it.
Back to Top
 Post Reply Post Reply Page  <12345 17>

Forum Jump Forum Permissions View Drop Down