Selection only on visible part of a shape? - swing

I would like to have the JGraphX editor to be able to select a shape only if the user click on a visible part of the shape instead of the full bounding box of a shape. For instance, if you insert a Triangle in a graph, I want to be able to select it only by clicking inside the triangle.
This would also be usefull after a rotation because the "bounding box" can be totally different than the visible shape once rotated.
Both things are working really well in draw.io, so I just would like to know where to look at in the Javascript to be able to do it in the Java Swing version.
Thank you.

Related

two canvases with same GUI Controls

How do we link two canvases (one showing 2d drawing and other 3d) on a webpage using JavaScript and P5.js so that if one shape is modified then it also affects the other canvas shapes?
Yeah, thank you. How they can be linked/interactive? If we change drawing in first screen, other screen also show that change.
It sounds like you're looking for instance mode.
You can read more about instance mode here, but basically it allows you to have multiple sketches running on the same page.
Get something very simple working, such as showing a circle on one canvas and a rectangle on another canvas. Then build up from there.

AS3 How to make a shape appear over everything

I am creating a drawing application and it's going pretty well - besides the fact there's a little glitch allowing you to draw over the toolbar. It only happens when the size of the lines are thick, and the thing I want is to make all the lines drawn over the toolbar go under the toolbar (the toolbar is just a regular rectangle shape). For example Is there a piece of code to make it appear over everything? And I won't use drawRect because that would hide all the movieclips on top of it.
I want is to make all the lines drawn over the toolbar go under the toolbar
It's question about managing display list. First of all read about Display list
Place display object with your toolbar over display object where user draws.
addChild(myCanvasToDraw);
addChild(myToolbar);

AS3 Fisheye Effect

I'm having trouble understand how DisplacementMapFilter works. Basically, I'm trying to create a revolving planet through a combination of fisheye/masking.
Also, how do I go about doing this via timeline? I'm not too familiar with coding within it, but this is more of an animation project than anything else, so classes are out of the question. Sorry for the lack of code -- I'm simply stuck.
As noted in the comments above, this probably only answers half the problem;
Generating a displacement map image isn't too difficult with the right tools. I'll assume you're using Photoshop, GIMP, Fireworks, or similar.
It's probably best to work on a 128x128 image or smaller with this method. Some editors have more specialised tools which let you work on pretty much any size of image, but this is a generic process that needs no special tools. You can always enlarge the end result, but the quality will begin to go down.
Start with a gradient fill. It should go from pure black on the left to dark red on the right (specifically 128,0,0). Add a vertical fill from black at the top to dark green at the bottom (specifically 0,128,0), and combine them with a LIGHTEN or ADD filter. You should now have an image which has black, red, green and yellow corners. Flatten it.
Copy this image to another layer / whatever the term-of-choice is for your editor. Apply whatever displacement filter you want to it (maybe a fish eye, maybe a manual smudge, maybe a perspective transform, anything)
Add a third layer between the two. Flood-fill it with dark yellow (128,128,0) and set it to ADD / ADDITION blend mode. Set the top layer to SUBTRACT / SUBTRACTION blend mode.
That's it. You should get a mostly yellow image which will function as a displacement map.
Update:
To use this in the example program (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filters/DisplacementMapFilter.html#includeExamplesSummary), replace the createBitmapData function with this:
private function createBitmapData():BitmapData {
return myBitmapObject.bitmapData;
}
where myBitmapObject is the instance name (I think) of your displacement Bitmap. There are tidier ways of setting that up, but this is the easiest.

Custom shape and fill in HTML5 canvas

I have a small project I am working on HTML5 canvas and I wanted to get some ideas how to accomplish it. I have built an outline of a tree using all the canvas line functions. lineTo, bezierCurveTo, quadracticCurve, etc. I have attached a picture of the outline. Now, what I would like to do is have some code that fills a percent of this outline. Kind of like a progress bar starting from the bottom. Does anyone have ideas on how to accomplish this?
Thanks
Rather than thinking of the problem as having to fill a percentage of the inside of the tree, why not split the image into two layers, the tree and the "fill", and then draw one over the other. See my image below for a quick and dirty example.
Of course, you will need to obscure the rest of the "fill" layer, so you will need to fill the outside of the tree shape white, but this should be fairly easy as you already have the path worked out. In essence, your path would instead of being the outside edge of a a tree shape, become the inside edge of a tree shaped hole!

How could I reduce the complexity of an image map?

I'm using KImageMapEditor on Linux (Ubuntu) to create an image map. The shapes in the image are a little complex so I'm using the freehand tool to draw them. However, this is really the same as the polygon tool so the shapes have ended up with a lot of points, which has made the HTML pretty huge.
Does anyone know of a way to reduce the complexity of the shapes, like "smoothing out" the lines?
I should also mention the reason I want the shapes to be fairly accurate is because I'm intending to do something like this, where each shape is highlighted on mouseover: http://davidlynch.org/js/maphilight/docs/demo_usa.html
Since users aren't going to click to the pixel, give them some leeway and create a "sloppy" map which roughly outlines each shape instead of clinging to the actual pixel outline.
This is in the same way as you don't expect a click on a link to fail just because you click on the background which shines through the text. You expect the bounding box of the text to act as the click-able area instead of the "black pixels".
Algorithm: Given three consecutive points, eliminate the middle point if the angle created is less than some tolerated error e.
Polygonal path simplification with angle constraint