/** * Circle class by subpixel (http://subpixels.com) *
Last modified: 2009-01-09 10:47
*/ class Circle extends Shape { public float r; public float r2; public Circle(Vector2D centre, float radius) { super(centre); r = radius; r2 = radius + 16; } public Circle(float ox, float oy, float radius) { super(ox, oy); r = radius; r2 = radius + 16; } public String str() { return "Circle{" + super.str() + ",r:" + r + "}"; } public void draw() { boolean wrapx = false; boolean wrapy = false; float x2 = 0; // alternate x value float y2 = 0; // alternate y value // Draw the location tracer super.draw(); // Draw the circle in its current location draw(p.x, p.y); // Wrap the drawing around window edges by redrawing // offset by the window width and/or height. if (p.x - r2 < 0) { wrapx = true; x2 = p.x + width; draw(x2, p.y); } else if (p.x + r2 >= width) { wrapx = true; x2 = p.x - width; draw(x2, p.y); } if (p.y - r2 < 0) { wrapy = true; y2 = p.y + height; draw(p.x, y2); } else if (p.y + r2 >= height) { wrapy = true; y2 = p.y - height; draw(p.x, y2); } if (wrapx && wrapy) draw(x2, y2); } // Private function to draw a copy at the specified coordinates private void draw(float x, float y) { PGraphics bg = layer[LAYER_BACKGROUND]; PGraphics fg = layer[LAYER_DRAW]; float d1 = r * 2; float d2 = r2 * 2; // Draw the basic circle useBasicColor(); fg.ellipse(x, y, d1, d1); // Draw the background circle (larger) bg.noStroke(); bg.fill(bgColor); bg.ellipse(x, y, d2, d2); if (showConstructionLines) { PGraphics cOver = layer[LAYER_CNSTR_OVER]; cOver.stroke(constructionLinesColor); cOver.strokeWeight(constructionLinesWeight); cOver.noFill(); // Only show construction edge if drawn edge not displayed if (!showEdge) { cOver.ellipse(x, y, d1, d1); } if (showConstructionLinesLevel >= 1) { // Small "+" for centre cOver.line(x, y - 5, x, y + 5); cOver.line(x - 5, y, x + 5, y); } } } }