how to let image to have a fixed rotation around the upper left corner - itext

image.setRotationAngle(Math.toRadians(-300));
This method doesn't seem to rotate around a fixed point and beyond the PDF size, which is not what I want?

Related

How to increase (animate) the width of the square on both ends?

I have created a square that is 40x40, as shown above. I have a 4x40 strip that I'd like to use to animate (increase) the width of my square till it takes the the width of the whole screen within a second, regardless of the square's position. Quite similar to that of a progress bar loading on both sides.
UPDATE
I forgot to mention that the square is a physics body, hence the physics body must also increase as the sprite increases.
What you want to do is use SKAction.scaleXTo to achieve what you are looking for:
SKAction.scaleXTo(sceneWidth / spriteWidth, duration: 1).
Now if you want the left and right side to not scale evenly, but instead reach both edges at the same time, what you can do is change the anchor point.
The math behind this assumes that your original anchor point is (0.5,0.5)
sprite.anchorPoint = CGPointMake(sprite.position.x / scene.width,sprite.anchorPoint.y)
E.G. Scene size width is 100, sprite is at x 75
What this is basically saying is that your sprite is at some percentage of the scene, in case of the example, 75%. so by changing the anchor point to .75, what is going to happen is the left side will fill faster than the right side when you are expanding your width since the left side of the anchor point has 75% of the width, and the right side has 25% of the width .
Lets say we set the scale to 2, that means the left side of the anchor point will now be at 150%, while the right side will be at 50%.
In general, assuming the origin of your objects are in the top-left (or at least the left, since we're only changing things on one axis) if you set start_x to the original x position of your square, start_width to its width, target_x to the x position of your strip, and target_width to its width, then:
x = start_x + (target_x - start_x) * a;
and
width = start_width + (target_width - start_width) * a;
And as a goes from 0.0 to 1.0, x and width will grow to match the strip.
Hope this helps.

Align the camera to make screen space origin at the bottom-left corner

I'm reading the book "Learn Unity for 2D game development", and I don't know how to do this:
"The camera has been aligned in the world so that the screen space origin is at the bottom-left corner; meaning positive X spans across the screen width, and positive Y across the screen height from bottom to top."
I'm new on Unity and the book doesn't talk how to do it.
By the way, I'm using Unity 4.3.3f1 on a Windows 7.
How can I align the camera to make screen space origin at the bottom-left corner?
In a 2D game, you have an X-axis and Y-axis. When increasing an object's X-value, you could say the object is going right. When increasing the Y-value, you could say the object is going up.
In a 3D game, there is another additional axis, the Z-axis. This makes it possible to gain 'depth' in games.
Example:
If you wanna create a 2D game in a 3D environment, you'll have to 'remove' one of the axis. The most common is to remove the Z-axis to keep the naming in line (X and Y remain, like in a 2D game).
To achieve 'removing' an axis in a 3D environment, your view has to be looking straight at it. In this case, X and Y rotation can be anything but your Z rotation has to be 0.
Example:
Consider the above picture to have a Z-axis as well. But because you are looking from Z=0 towards the origin, the line doesn't go to the right, left up or bottom. The axis will be like 1 pixel size.
When you do this using the camera, in such a way that the world origin is in front of you and higher X numbers are to your right and higher Y numbers are above you, you've achieved this. This also means that the screen's value of X=0 is totally left, and the screen's value of Y=0 is totally bottom. This concludes that space origin is at the bottom-left corner; meaning positive X spans across the screen width, and positive Y across the screen height from bottom to top.
By saying "camera has been aligned", he doesn't mean that you manually align it in the scene, he's saying how screen space origin is at the bottom-left corner by default.
Source: Unity Script Reference

iPhone iOS which CGAffineTransform does isometric transform [ _ ] to /_/

I need to make a rectangular view [ ] appear as if it's top is rotated back, while the bottom is pinned in place: / \ . The resulting image is isometric with the bottom being wider than the top.
Which CGAffineTransform do I need to accomplish this goal?
As others have pointed out, you can't do this with a CGAffineTransform.
However, it's relatively easy to do with a CATransform3D, as I describe in this answer. You'll need to adjust the m34 component of the CATransform3D to give the transform some degree of perspective, rotate the view about the X axis, and potentially scale it so that the bottom edge remains at the same width as for your original unrotated view.
Alternatively, you might be able to adjust the anchorPoint of your view's underlying layer to be at the bottom, rather than the center. Rotations will then be applied from that edge, which should keep the bottom edge length constant and give you a receding perspective effect for the view. I believe a value of (0.5, 1.0) will set the anchorPoint to the lower edge.
Brad, I found this example (by you!) on how to do a perspective transformation:
http://www.sunsetlakesoftware.com/2008/10/22/3-d-rotation-without-trackball
For some reason it does not work in my code. My buttons have the 3d transform applied, but not the scaling effect.

How do I get rid of these magic numbers in my rotation affine transform?

I have a view that is 320x460 (standard iPhone screen) that I want to draw as if it were in landscape mode, though the phone is not oriented that way. This seems like a simple task, which I tried to solve by creating a subview of size 460x320, and then rotating it 90 degrees through setting the view transformation. This worked, except that the rotated view was not centered correctly. To 'fix' this I added a translation transformation, which ended up looking like this:
CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI / 2.0);
[landscapeView setTransform: CGAffineTransformTranslate(rotate, 70.0, 70.0)];
I don't mind having some adjustment transformation, but I have no clue where the magic number 70 came in. I just played around with it until the edges matched up correctly. How can I get rid of them, either by eliminating the translation transformation, or by deriving the number from some meaningful math related to the height and width?
Just a hunch, but I'm guessing prior to the transform that you're setting (or defaulting) the center of landscapeView to (160, 230). When it rotates, it keeps the upper left position fixed.
(320 px screen width - 460 px width) = -140 px. Divide that in half since it's centered, and you get -70 px. Same idea with the vertical.
70 is the difference between the width and height, divided by two. (460 - 320) / 2. The division by two is what centers the view.

CoreGraphics rounded corner thickness

Whenever I stroke a path with rounded corners on iPhone, the rounded corners are thicker than the rest of the stroked path. See here for what I mean:
rounded corner thickness http://img181.imageshack.us/img181/6372/screenshot20100320at123.png
Not sure why this happens, any ideas?
I agree with Peter Hosey's analysis that the outer half of your lines is getting clipped off, but my recommendation would be to move all the coordinates .5 pixels inward instead. This way your straight lines will be crisper (not antialiased across 2 screen pixels) as well.
I suspect that you're drawing within a rectangular clipping path; the corners fall completely within the rectangle, but the sides get cut in half: half inside the clipping path and so drawn, half outside and so clipped out.
Try adding the path to the clipping path before stroking it.
To do this, you will need to add the CGPath to the context's current path twice:
Add CGPath to current path.
Add current path to clipping path (thereby emptying current path).
Add CGPath to current path.
Stroke current path.
It just looks thicker. If you zoom in on it you will see what looks like a couple extra pixels of black is actually some pixels of gray caused by antialiasing.
Try turning off antialiasing to see if the result looks better.
Edit: Also the bottom right corner seems to have a drop shadow effect.