How to draw a thick arc (20 pixels)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ExpertAlmost
Forum Commoner
Posts: 41
Joined: Mon Oct 20, 2008 12:26 am

How to draw a thick arc (20 pixels)

Post by ExpertAlmost »

Good morning experts one and all!

I am trying to draw an arc 20 pixels wide. Unfortunately, imagearc() only draws a one pixel line while imagefilledarc() does not fill the arc to a specified depth (just various "pie" fillings).

So I tried a loop to draw 20 one-pixel lines. For some reason however, it appears that some pixels are dropped. This makes for a messy fill leaving black spots (or any background color) in the line. Attached is an example and the code is below.

What is the best way to draw a "thick" arc?

Thank you in advance for your kindness :)
PS. How do you insert an image into messages on this board using the img tags?

Code: Select all

$img = imagecreatetruecolor(214, 345);
$white = imagecolorallocate($img, 255, 255, 255);
$red   = imagecolorallocate($img, 255,   0,   0);
for ($Cnt = 1; $Cnt <= 20; $Cnt++) {
    $Measure = 300 + $Cnt;
    imagearc($img, 20, 172, $Measure, $Measure, 315, 45, $white);
}
Attachments
image1.png
image1.png (1.52 KiB) Viewed 91 times
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to draw a thick arc (20 pixels)

Post by requinix »

If you know the background color (what you're drawing on top of), use imagefilledarc to draw the far edge of the arc in whatever color you want, then again using the background color for the inside of the arc.

Thus you draw a pie slice in one color, then "erase" the part you don't want. Subtraction with shapes.

If you don't know the background, draw the arc on a new, transparent image. Then copy the arc onto the destination image.


Oh, and the [img] tag will insert an offsite image into your post. Otherwise you can just attach it.
Post Reply