as3: draw circle with a hole in it using only actionscript - actionscript-3

Okay so basically I want to draw a circle in as3 that has a 'hole' in it (like a donut). Something like this, but without the outlines:
http://www.steel.ie/DugganSteel/Pictures/Hollow-circle.gif
This doesn't work:
SPRITE.graphics.beginFill(0xFFFFFF);
SPRITE.graphics.drawCircle(0,0,10);
SPRITE.graphics.endFill();
SPRITE.graphics.drawCircle(0,0,5);
I mean this seems like it'd be simple but I can't find any information on it. I should also mention that I'm trying to only draw 3/4 of the circle, like 3/4 of donut. So I was planning on drawing a transparent circle and square over the original circle, I know this seems kinda of weird since you'd expect something transparent to show whats underneath it.

Its actually really simple. See the following code:
var p:Point = new Point(100, 100);
graphics.beginFill(0xFF0000);
graphics.drawCircle(p.x, p.y, 100);
graphics.drawCircle(p.x, p.y, 50);
Intersections cancel each other out until you call endFill
Goodluck!

You can just make the line thickness the desired donut width and avoid using beginFill
set graphics.lineStyle
To make it only go 3/4 of the way around you could use curveTo to draw the 3 quarters.

The above method by Tyler works, however if an easier way to do it is to simply begin drawing the inner circle first. Basically Flash doesn't actually fill in the color until you call endFill() (again as mentioned by Tyler), so you start drawing on the inner circle, then the outer circle then on endFill() Flash fills in the gap.
SPRITE.graphics.beginFill(0xFFFFFF);
SPRITE.graphics.drawCircle(0,0,5);
SPRITE.graphics.drawCircle(0,0,10);
SPRITE.graphics.endFill();
Hope this clears things up for you.

Introduction to Flash drawing API, will help you understand a bit more :
http://www.senocular.com/flash/tutorials/flash10drawingapi/

Related

How to make fill Rectangle without color in ActionScript 3.0 to see behind it

I just started working on as3. I want to create a Rectangle but without color fill, so I can see what is behind it on stage. I love to draw on that Rectangle, but it never works without color fill.
var Canvas_sp:Sprite = new Sprite();
this.addChild(Canvas_sp);
//here i love Rectangle be without collor fill not whit(FFFFFF)e color
//i love see what behind the Rectangle and draw over it
Canvas_sp.graphics.beginFill(0xFFFFFF);
Canvas_sp.graphics.drawRect(0,0,550,400);
thx for all
If you don't want a fill, don't begin one.
Omit this line:
Canvas_sp.graphics.beginFill(0xFFFFFF);
To achieve the goal you want, you need to set the alpha parameter to 0, and maybe, to draw just a border of a Rectangle. You can see an example here: example
In your case, you can try something like this:
Canvas_sp.graphics.beginFill(0xffffff, 0);
Canvas_sp.graphics.lineStyle(0x000000, 0.1);
Canvas_sp.graphics.drawRect(0, 0, 550, 400);
Canvas_sp.graphics.endFill();

How to implement rotating rectangle around circle in libGDX Box2D?

I want to implement rotating rectangle around cicrle in such way, that circle has no rotation, and rectangle has. All object's are Box2D Body objects. Here is picture, what I want to have:
In my case rectangle touches circle, but I think it doesn't matter.
At first I tried to do it with two Fictures for same Body, but there was a problem with rotation: I couldn't have one ficture with rotation and another without.
I think, it should be somehow connected with joints, but I don't know what exactly Joint I should use. Maybe are there another solutions?
I think DistanceJointDef will do the tricks
you could put the radius if the circle as the distance with a little margin if you want
you also have to reduce the friction of bodies so the rectangle can move smoothly
DistanceJointDef djd = new DistanceJointDef();
djd.bodyA = bodyRactangle;
djd.bodyB = bodyCirlce;
djd.length = radius + margin;
world.createJoint(djd);
bodyRactangle is a dynamic body
bodyCirlce is a static body
try that for a start, hope it is helpful
Good luck !!

Check collision between 2 shapes

I'm writing a little game in as3, and I need to check collision between 2 boats.
I don't need the pixel perfect collision, but bounds collision is not enough too.
The boat look more or less like this:
https://www.dropbox.com/s/197yqvzf2jaugtm/boats.JPG
I was thinking about create one square on the back of the boat and a triangle on the front, than for each boat, check if the square collide with the other boat square or triangle, and the same for the triangle.
I just don't know how to do that, I don't know if it's possible with the Shape.hitTest, or if it's the best way to do that.
What can I do?
Try this,
var isTouched:Boolean = item1.bounds.intersects(item2.bounds);
when both touches, it will return true;

HTML5 / Canvas "Glass" Circle

I need to render a simple chart and I want the points to be glassy looking circles/orbs in the chart area. I can find tons of examples of drawing these with Photoshop, but I don't want to use stock images; I'd prefer to draw them in my HTML5 canvas. I am no artist, though!
There are many HTML5 canvas questions, but I don't see anything that leads me to this solution.
A point in the right direction would be most appreciated.
All you have to do is create one or more radial gradients to fit the properties of the glassy object that you want. It's easy to do!
Just one gradient:
// Create some gradient
var gradient = ctx.createRadialGradient(105, 105, 20, 120, 120, 50);
gradient.addColorStop(0, 'rgba(250,250,255,0)');
gradient.addColorStop(0.75, 'rgba(230,250,255,1.0)');
gradient.addColorStop(1, 'rgba(0,0,255,0)');
// draw the gradient (note that we dont bother drawing a circle, this is more efficient and less work!)
// but make sure it covers the entire gradient
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 300, 300);​
Can make this:
Live example:
http://jsfiddle.net/GTbjk/
Maybe you want to reign in that fuzzy edge:
gradient.addColorStop(0.8, 'rgba(0,0,255,0)');
gradient.addColorStop(1, 'rgba(0,0,255,0)');
http://jsfiddle.net/GTbjk/1/
I'm not going to make one to your specification, since you didn't provide one and thats not what we're here for anyway. Making these will almost exclusively be the work of well-placed radial gradients, so go experiment!
As j08691 points out this is a really inefficent way of making these unless you want them to be dynamic or scalable, you are better off just making images and use ctx.drawImage

ActionScript drawRoundRect rendering inconsistent corner radii

I'm trying to draw a shape with quite precise rounded corners, I'd settle for anything around 3px. Unfortunately Flash has other ideas, and is creating a rounded rectangle with four seemingly different radii. My code is below:
var sq:Shape = new Shape();
sq.graphics.beginFill(0x000000,1);
sq.graphics.drawRoundRect(20,20,20,20,4,4);
sq.graphics.endFill();
addChild(drop);
I removed the line as apparently fills render better, and changed to an even number radius as apparently that helps, but it's still the same. The code above gives me a square like so:
The corners are noticeably different. If I were using a bigger radius it might not be so much of a problem, but because of the small radius of the corners the square just looks odd.
Have I missed the drawRoundRectEvenly function or am I asking too much here? Any help is appreciated! Thanks!
Darren
Try setting pixelHinting to true.
sq.graphics.lineStyle(1, 0x000000, 1.0, true);
Even if you're not using strokes, try it with an alpha 0 and see if it helps smooth things a bit. It will most likely still not be perfect, but it should snap to pixels a bit better and clean up dramatically.