2d doughnut
BlitzMax Forums/BlitzMax Programming/2d doughnut
| ||
Does anyone have an idea how to quickly draw a 2d doughnut(filled circle with a hole in the middle) I've already tried faking it by drawing another smaller circle on top of the first with the background color. But the problem is that the "hole" is not transparent |
| ||
Why are you not using a transparent background color? (not trying to be rude, just confused why you are not using a donut image and pasting it so the background color is transparent) |
| ||
Why are you not using a transparent background color? (not trying to be rude, just confused why you are not using a donut image and pasting it so the background color is transparent) The doughnut size needs to change dynamically. When I resize an image, Blixmax tends to blur the edges. |
| ||
You could draw this to a pixmap and then process pixels so that the ones colored like the background would be transparent. Not sure how fast this is though. A second suggestion would be to make the doughnut image the same size as your maximum size inside the application. Then it won't blur anymore, but it will get a bit sharper when you scale down |
| ||
Draw quite a big doughnut and shrink it? instead of enlarging a small one? |
| ||
I tried a doughnut with transparent psp7 background and it doesn't seem to blur when being enlarged. Have you got the code and image that has the problem? |
| ||
Blue donut :-)cairo.Arc(320, 240, 30, 0, 360) cairo.Arc(320, 240, 70, 0, 360) cairo.SetFillRule(CAIRO_FILL_RULE_EVEN_ODD) cairo.SetSourceRGB(0, 0, 1) cairo.FillPreserve() cairo.SetSourceRGB(0, 0, 0) cairo.Stroke() Inner radius 30, outer radius 70 pixels. |
| ||
If you felt like doing it in a less efficient way you could use the function,Function DrawDonut(x:Float,y:Float,ir:Float,er:Float,quads:Int = 20) Local xy:Float[] = New Float[6] For Local i:Int = 0 To (quads-1) Local angle:Float = i*360.0/quads Local angleTo:Float = (i+1)*360.0/quads xy[0] = x+er*Cos(angle) xy[1] = y+er*Sin(angle) xy[2] = x+ir*Cos(angle) xy[3] = y+ir*Sin(angle) xy[4] = x+ir*Cos(angleTo) xy[5] = y+ir*Sin(angleTo) DrawPoly(xy) xy[0] = x+er*Cos(angle) xy[1] = y+er*Sin(angle) xy[2] = x+er*Cos(angleTo) xy[3] = y+er*Sin(angleTo) xy[4] = x+ir*Cos(angleTo) xy[5] = y+ir*Sin(angleTo) DrawPoly(xy) Next End Function You could probably make it a good deal faster by precalculating the array and then upscaling it. |