update
This commit is contained in:
parent
1f1ad49427
commit
6f050a029e
2496 changed files with 37609 additions and 3031 deletions
|
|
@ -0,0 +1,48 @@
|
|||
/// <summary>
|
||||
/// Draws a circle.
|
||||
/// </summary>
|
||||
/// <param name="image">
|
||||
/// The destination image.
|
||||
/// </param>
|
||||
/// <param name="centerX">
|
||||
/// The x center position of the circle.
|
||||
/// </param>
|
||||
/// <param name="centerY">
|
||||
/// The y center position of the circle.
|
||||
/// </param>
|
||||
/// <param name="radius">
|
||||
/// The radius of the circle.
|
||||
/// </param>
|
||||
/// <param name="color">
|
||||
/// The color to use.
|
||||
/// </param>
|
||||
public static void DrawCircle(this GenericImage image, int centerX, int centerY, int radius, Color color)
|
||||
{
|
||||
int d = (5 - radius * 4) / 4;
|
||||
int x = 0;
|
||||
int y = radius;
|
||||
|
||||
do
|
||||
{
|
||||
// ensure index is in range before setting (depends on your image implementation)
|
||||
// in this case we check if the pixel location is within the bounds of the image before setting the pixel
|
||||
if (centerX + x >= 0 && centerX + x <= image.Width - 1 && centerY + y >= 0 && centerY + y <= image.Height - 1) image[centerX + x, centerY + y] = color;
|
||||
if (centerX + x >= 0 && centerX + x <= image.Width - 1 && centerY - y >= 0 && centerY - y <= image.Height - 1) image[centerX + x, centerY - y] = color;
|
||||
if (centerX - x >= 0 && centerX - x <= image.Width - 1 && centerY + y >= 0 && centerY + y <= image.Height - 1) image[centerX - x, centerY + y] = color;
|
||||
if (centerX - x >= 0 && centerX - x <= image.Width - 1 && centerY - y >= 0 && centerY - y <= image.Height - 1) image[centerX - x, centerY - y] = color;
|
||||
if (centerX + y >= 0 && centerX + y <= image.Width - 1 && centerY + x >= 0 && centerY + x <= image.Height - 1) image[centerX + y, centerY + x] = color;
|
||||
if (centerX + y >= 0 && centerX + y <= image.Width - 1 && centerY - x >= 0 && centerY - x <= image.Height - 1) image[centerX + y, centerY - x] = color;
|
||||
if (centerX - y >= 0 && centerX - y <= image.Width - 1 && centerY + x >= 0 && centerY + x <= image.Height - 1) image[centerX - y, centerY + x] = color;
|
||||
if (centerX - y >= 0 && centerX - y <= image.Width - 1 && centerY - x >= 0 && centerY - x <= image.Height - 1) image[centerX - y, centerY - x] = color;
|
||||
if (d < 0)
|
||||
{
|
||||
d += 2 * x + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
d += 2 * (x - y) + 1;
|
||||
y--;
|
||||
}
|
||||
x++;
|
||||
} while (x <= y);
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
#DEFINE WM_LBUTTONDOWN 513
|
||||
#DEFINE WM_CLOSE 16
|
||||
|
||||
FBSLSETTEXT(ME, "Bresenham Circle") ' Set form caption
|
||||
FBSLSETFORMCOLOR(ME, RGB(0, 255, 255)) ' Cyan: persistent background color
|
||||
FBSL.GETDC(ME) ' Use volatile FBSL.GETDC below to avoid extra assignments
|
||||
|
||||
RESIZE(ME, 0, 0, 220, 220)
|
||||
CENTER(ME)
|
||||
SHOW(ME)
|
||||
|
||||
DIM Breadth AS INTEGER, Height AS INTEGER
|
||||
FBSL.GETCLIENTRECT(ME, 0, 0, Breadth, Height)
|
||||
|
||||
BEGIN EVENTS ' Main message loop
|
||||
SELECT CASE CBMSG
|
||||
CASE WM_LBUTTONDOWN: MidpointCircle() ' Draw
|
||||
CASE WM_CLOSE: FBSL.RELEASEDC(ME, FBSL.GETDC) ' Clean up
|
||||
END SELECT
|
||||
END EVENTS
|
||||
|
||||
SUB MidpointCircle()
|
||||
BresenhamCircle(Breadth \ 2, Height \ 2, 80, &HFF) ' Red: Windows stores colors in BGR order
|
||||
BresenhamCircle(Breadth \ 2, Height \ 2, 40, 0) ' Black
|
||||
|
||||
SUB BresenhamCircle(cx, cy, radius, colour)
|
||||
DIM x = 0, y = radius, f = 1 - radius, dx = 0, dy = -2 * radius
|
||||
|
||||
PSET(FBSL.GETDC, cx, cy + radius, colour)(FBSL.GETDC, cx, cy - radius, colour)
|
||||
PSET(FBSL.GETDC, cx + radius, cy, colour)(FBSL.GETDC, cx - radius, cy, colour)
|
||||
|
||||
WHILE x < y
|
||||
IF f >= 0 THEN: DECR(y): INCR(dy, 2)(f, dy): END IF ' Try also "IF f THEN" :)
|
||||
INCR(x)(dx, 2)(f, dx + 1)
|
||||
PSET(FBSL.GETDC, cx + x, cy + y, colour)(FBSL.GETDC, cx - x, cy + y, colour)
|
||||
PSET(FBSL.GETDC, cx + x, cy - y, colour)(FBSL.GETDC, cx - x, cy - y, colour)
|
||||
PSET(FBSL.GETDC, cx + y, cy + x, colour)(FBSL.GETDC, cx - y, cy + x, colour)
|
||||
PSET(FBSL.GETDC, cx + y, cy - x, colour)(FBSL.GETDC, cx - y, cy - x, colour)
|
||||
WEND
|
||||
END SUB
|
||||
END SUB
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
#lang racket
|
||||
(require racket/draw)
|
||||
|
||||
(define-syntax ⊕ (syntax-rules () [(_ id e) (set! id (+ id e))]))
|
||||
|
||||
(define (draw-point dc x y)
|
||||
(send dc draw-point x y))
|
||||
|
||||
(define (draw-circle dc x0 y0 r)
|
||||
(define f (- 1 r))
|
||||
(define ddf_x 1)
|
||||
(define ddf_y (* -2 r))
|
||||
(define x 0)
|
||||
(define y r)
|
||||
(draw-point dc x0 (+ y0 r))
|
||||
(draw-point dc x0 (- y0 r))
|
||||
(draw-point dc (+ x0 r) y0)
|
||||
(draw-point dc (- x0 r) y0)
|
||||
(let loop ()
|
||||
(when (< x y)
|
||||
(when (>= f 0)
|
||||
(⊕ y -1)
|
||||
(⊕ ddf_y 2)
|
||||
(⊕ f ddf_y))
|
||||
(⊕ x 1)
|
||||
(⊕ ddf_x 2)
|
||||
(⊕ f ddf_x)
|
||||
(draw-point dc (+ x0 x) (+ y0 y))
|
||||
(draw-point dc (- x0 x) (+ y0 y))
|
||||
(draw-point dc (+ x0 x) (- y0 y))
|
||||
(draw-point dc (- x0 x) (- y0 y))
|
||||
(draw-point dc (+ x0 y) (+ y0 x))
|
||||
(draw-point dc (- x0 y) (+ y0 x))
|
||||
(draw-point dc (+ x0 y) (- y0 x))
|
||||
(draw-point dc (- x0 y) (- y0 x))
|
||||
(loop))))
|
||||
|
||||
(define bm (make-object bitmap% 25 25))
|
||||
(define dc (new bitmap-dc% [bitmap bm]))
|
||||
(send dc set-smoothing 'unsmoothed)
|
||||
(send dc set-pen "red" 1 'solid)
|
||||
(draw-circle dc 12 12 12)
|
||||
bm
|
||||
Loading…
Add table
Add a link
Reference in a new issue