what is changing on shape (rect) drag in Canvas? - html5-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 :)

Related

Keep same scale while rotating

I want to keep scale when i rotate verticles. But it is getting smaller after rotation. Picture 3 and 4:
How can i keep it same size ?
Rotate is the wrong tool, if you look directly at the circular face after rotating it will remain circular, where the result you are after will become an oval.
The tool you want is called shear, which will move the top vertices the opposite way to the bottom vertices without altering the height. You can find shear in Mesh->Transform->Shear or the shortcut Ctrl-Alt-Shift-S. The shear tool transforms based on the view so you will want to be in side view when you use it.
Another option would be to use the knife tool to cut a line through your tube.
You can also position a plane over the tube and use intersect (Knife).

How to check whether a svg circle inside the svg path

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

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.

BitmapData pattern fill in actionscript 3.0

How do i fill some BitmapData image with other image pattern in as 3.0? For example, i have an white image with black square at the center which would be "square:BitmapData" and the other image with little(2x2) blue circle which i would call "circle:BitmapData". I want to fill that square with this blue circles, is there any way to do this?
UPDATE
Here i found the example of what i need to do:
This is two images (left is like my square, right is like the blue circle)
http://pix.samoucka.ru/img/content/graphics/thewebschedule/8/466.gif
And this is how it would look after filling
http://pix.samoucka.ru/img/content/graphics/thewebschedule/8/467.gif
You can try using copyPixels() and iterating though x and y to tile the whole thing, copyPixels() is very fast.
Or
It might be simpler to create a Sprite and use graphics.beginBitmapFill() then graphics.drawRect() with the correct size, then draw() to the BitmapData in the correct position.
If you need to determine the size and position of the black square, getColorBoundsRect() should do the job.

Does a given rect intersect a rotated view?

I have an NSView that is rotated using -setFrameRotation. (This is necessary because the view responds to mouse events, and you don't get correct behavior if you merely draw the view with a rotated NSAffineTransform.)
Given a rect in the rotated view's superview coordinates, how can I determine what portion of the rect intersects the rotated view's frame?
Use case: the Cocoa text system proposes to draw text in a line fragment rectangle. I need to determine how much of that rectangle may be filled with text without overlapping the rotated view.
Take the point, use an affine transform to rotate into the coordinate system of the bounds of the rect and then rect-test that.

Resources