peterm
Junior Member
Posts: 17
|
Circles
May 19, 2014 15:58:07 GMT -8
Post by peterm on May 19, 2014 15:58:07 GMT -8
Hi
How does one draw a Circle (not a coloured disc) the centre of the circle is transparent ?
|
|
|
Circles
May 20, 2014 12:10:23 GMT -8
Post by jamesbowman on May 20, 2014 12:10:23 GMT -8
Quick way, draw two discs, one smaller than the other: GD.ClearColorRGB(0x103000); GD.Clear();
GD.Begin(POINTS); GD.PointSize(16 * 80); GD.Vertex2ii(240, 136);
GD.ColorRGB(0x103000); GD.PointSize(16 * 75); GD.Vertex2ii(240, 136); GD.swap();
Longer, more fancy way: use compositing operators (chapter 14 of the book) to create the circle, again using two discs.
|
|
peterm
Junior Member
Posts: 17
|
Circles
May 21, 2014 0:58:15 GMT -8
Post by peterm on May 21, 2014 0:58:15 GMT -8
James
I was doing that but I could not get the centre of the circle drawn as transparent properly, I was trying GD.ColorA, I may try GD.BlendFunc instead.
I will go and read your Chapter 14.
Thank You God of FT800
|
|
|
Circles
May 21, 2014 6:55:03 GMT -8
Post by jamesbowman on May 21, 2014 6:55:03 GMT -8
Yes, using the "quick" way, the center of the circle is always covered up: Here is some code using the " chapter 14" approach. It paints the circles into the alpha channel: #include <EEPROM.h> #include <SPI.h> #include <GD2.h>
void setup() { GD.begin(); GD.cmd_loadimage(0, 0); GD.load("tree.jpg"); }
#define PAINT_ALPHA() GD.BlendFunc(ONE, ONE_MINUS_SRC_ALPHA) #define CLEAR_ALPHA() GD.BlendFunc(ZERO, ONE_MINUS_SRC_ALPHA)
static void circle(int x, int y, int r0, int r1) { GD.Begin(POINTS); PAINT_ALPHA(); GD.PointSize(16 * r1); GD.Vertex2ii(x, y);
CLEAR_ALPHA(); GD.PointSize(16 * r0); GD.Vertex2ii(x, y); }
void loop() { GD.Begin(BITMAPS); GD.ColorRGB(90, 90, 90); GD.Vertex2ii(0, 0);
// Now paint the circles into the alpha channel GD.SaveContext(); GD.ColorMask(0, 0, 0, 1); GD.Clear();
for (int i = 0; i < 10; i++) { int x = (480 * i) / 10; int y = (272 * i) / 10; int r = 20 + i * 5; circle(x, y, r, r + 5); } GD.RestoreContext();
// Paint the alpha mask pink GD.ColorRGB(255, 200, 255); GD.BlendFunc(DST_ALPHA, ONE_MINUS_DST_ALPHA); GD.Begin(RECTS); GD.Vertex2ii(0, 0); GD.Vertex2ii(480, 272);
GD.swap(); }
|
|
peterm
Junior Member
Posts: 17
|
Circles
May 22, 2014 0:55:42 GMT -8
Post by peterm on May 22, 2014 0:55:42 GMT -8
James
Thanks for that, its close to what I was looking for, but in that example each circle drawn covers the next circle. The rings are not fully shown.
|
|