How to check whether a svg circle inside the svg path - d3.js

There are many ways to check is point inside path, but i haven't found any algorhitm which can check if the circle(whole object, not center point) is inside svg path.
If you're wondering why I need this algorithm - i want to fill space with circles with different radii (http://bl.ocks.org/mbostock/1893974), and those circles that enters the shape i want to paint in another color. As a result, we get the test image for color-blind people, like Ishihara's pictures.
The expected result like on that picture.

This a collition detection algorithm or intersection.
Step 1
Fill with cirlcles you base shape
Step 2
Create the main shape
Step 3
Detect interserct and color the shape behind. And hide the main shape
Pros: You can add dynamically shapes, animate or change it on the fly.
For an implementation look here

Related

I need an algorithm to indentify created shapes on the ground and fill them(change the colors of the blocks within)

I am building a game where 8 players are spawned in an arena and each has their own color and they are suppose to roam around the arena(the blocks they walk on change to the player's color) with the purpose to fill as much of the arena's ground with their color.
When they create a shape they inside of the shape is also supposed to change to their color but I can't think of a way to actually implement this so I would really appreciate some help.
I broke down the process of implementing this into 2 steps:
Identify when a shape is created
Find all the blocks that are inside the perimeter of that shape an fill them
An example for shape that I would like to fill(The blue blocks are supposed to be the perimeter of the shape

How to achieve Custom Gradient Shapes/Patterns in Flutter

Out of the box we get LinearGradient, RadialGradient and SweepGradient. What I would like to do is something similar to the shown image below. Let's say we draw a custom shape with CustomPainter. When this customShapeGradient is applied on it, the gradient should start from the border of the custom shape and go towards the center. I realize that this might introduce wierd effects since our shape will mostly be not symmetric and a "border to center" approach is not as easy as a "center to border" approach(like the 3 out of the box methods). Here it will be the developer's responsibility to make sure the gradient fill do not overlap with itself, meaning it won't go all the way to the center.
Here is an image I found for an Elliptic shape which most closely describe what I want. Let's say our shape is the line with the yellow color. And I want to achieve the gradient which fills inside.
This is a similar image too:
The two examples I have provided are for ellipses however my question is for any type of shape that is created by a CustomPainter.
I am almost sure this is possible since a shadow(gradient in nature) is basically the inverse of this. We can apply a shadow to a CustomPainter shape. The only difference will be that the shadow will grow towards inside of the shape(maybe like a inner shadow).

How does one override "draw" in a CCNode?

I am creating a side scrolling game.
I compute all the points representing what a terrain should look like by doing the following:
The points representing the top of the hill are determined by using a sin function.
The bottom of the hill is just the bottom of the screen.
The left and right edges of the terrain, are the left and right edges of the screen, where the x coords are x=0, and x= screen width.
But I don't know how to draw it on screen, and "fill" it with some other texture. (A predetermined PNG image or something).
How does one override the draw method of a CCNode or CCSprite to accomplish this ?
In the example below I would use a square png image of stars, which I would like to repeat as I scroll the terrain from left to right.
Edit: In the tutorial below, they do all kinds of calculations and wrap a sprite around the hills. But I just want to do something simple, like fill the hills with a simple "noise" texture (no stripes etc), or a solid color. How can I do that?
: http://www.raywenderlich.com/32954/how-to-create-a-game-like-tiny-wings-with-cocos2d-2-x-part-1
EDIT: To clarify: I know one can override the draw method. But I don't know what code to put in it to accomplish the problem I described above.
Create a new class that subclasses CCNode or CCSprite, and add a draw method:
- (void) draw {
}
The draw method will automatically execute each frame. Put whatever "drawing" code you like within it.

what is changing on shape (rect) drag in Canvas?

How does it work?
a. The rectangle is changing place inside the layer?
or
b. The layer changes its place inside the stage?
I have drawn a rectangle, then I draged it to another place, and output the rect.getX() and rect.getY() . They allways remain (10,10).
If you draw a rectangle, then coded the rectangle to be dragged, the rectangle shape will move. The rectangles x and y values should change.
You're saying this isn't the case? Paste some code so we can check it out :)

How to get consistent gradient fill in GDI+ when using a rotated LinearGradientBrush?

I'm using GDI+ in my application, and I need to use a rotated LinearGradientBrush to paint several rects in the exact same way. However, although I'm calling the same code to fill each rect, the results aren't what I expect. Here's the code to create the gradient fill, where rcDraw is the rect containing the area to paint for each rect. These coordinates are in the parent window's coordinates, so they are not identical for the 2 rects.
g_hbrLinear = new LinearGradientBrush( Rect( 0, rcDraw.top, 0, rcDraw.bottom - rcDraw.top ),
clrStart, clrEnd, (REAL) 80, FALSE );
What I see on screen looks like this (http://www.nnanime.com/bugs/LinGradBrush-rotate10.png). You can see that it's as if the fill from the first rect continues into the second one. What I really want is to have the 2 rects look identical. I think I can do that if I paint each rect separately using its own client coordinates, but for the purposes of my app, I need to use the parent window's coordinates.
I guess what I'm asking is, how does GDI+ calculate the "origin" of a fill? Is it always based on 0,0 in the coordinate system you use? Is there a way to shift it? I tried TranslateTransform, but it doesn't seem to shift the fill in a way that I find predictable or understandable.
The rect passed to the linear gradient brush determines the where the left and right colors will sit, and the gradient will be painted within this rectangle.
So, I think you need to create a brush for each rectangle you are painting, where the rectangle you are painting is also passed to the constructor for the linear gradient brush.
My experience with the "transform" of linear gradient brushes matches yours; I haven't been able to understand what it's supposed to do.
You can think of a brush in GDI+ as a function mapping world co-ordinates to a color. What the brush looks like at a given point does not change based on the shape being filled.
It does change with the transform of the Graphics object you're drawing on. So, if you don't want to change the brush, you could temporarily change the transform of the Graphics object so that the rectangle you're drawing has a specific, known size and position in world coordinates. The BeginContainer and EndContainer methods should make this easy.
(There is also the RenderingOrigin property but it only affects hatch brushes, which oddly are unaffected by world transforms.)

Resources