📄 circle.c
字号:
/* */#include "device.h"#include "osd.h"#if !defined(_PalmOS)#include <math.h>#else#define M_PI 3.14159265358979323846#endifvoid Set4Pixels(int x,int y,int xc,int yc) SEC(BIO);void Set4Line(int x,int y,int xc,int yc) SEC(BIO);void simple_ellipse(int xc, int yc, int rx, int ry, int fill) SEC(BIO);void Set4Pixels(int x,int y,int xc,int yc){ osd_setpixel(xc+x, yc+y); osd_setpixel(xc-x, yc+y); osd_setpixel(xc+x, yc-y); osd_setpixel(xc-x, yc-y);}void Set4Line(int x,int y,int xc,int yc){ osd_line(xc-x, yc+y, xc+x, yc+y); osd_line(xc-x, yc-y, xc+x, yc-y);}/**/void simple_ellipse(int xc, int yc, int rx, int ry, int fill){ int x = 0; int y = ry; long a = rx; /* use 32-bit precision */ long b = ry; long Asquared = a * a; /* initialize values outside */ long TwoAsquared = 2 * Asquared; /* of loops */ long Bsquared = b * b; long TwoBsquared = 2 * Bsquared; long d; long dx,dy; d = Bsquared - Asquared*b + Asquared/4L; dx = 0; dy = TwoAsquared * b; while ( dx < dy ) { if ( fill ) Set4Line(x, y, xc, yc); else Set4Pixels(x, y, xc, yc); if ( d > 0L ) { -- y; dy -= TwoAsquared; d -= dy; } ++ x; dx += TwoBsquared; d += Bsquared + dx; } d += (3L*(Asquared-Bsquared)/2L - (dx+dy)) / 2L; while ( y >= 0 ) { if ( fill ) Set4Line(x, y, xc, yc); else Set4Pixels(x, y, xc, yc); if ( d < 0L ) { ++ x; dx += TwoBsquared; d += dx; } -- y; dy -= TwoAsquared; d += Asquared - dy; }}/**/void dev_ellipse(int xc, int yc, int xr, int yr, double aspect, int fill){ if ( os_graphics == 0 ) return; simple_ellipse(xc, yc, xr, yr * aspect, fill);}/**/void dev_arc(int xc, int yc, double r, double start, double end, double aspect){ double th, ph, xs, ys, xe, ye, x, y; int i; if ( os_graphics == 0 ) return; if ( r < 1 ) r = 1; while ( end < start ) end += M_PI * 2.0; th = (end - start) / r; xs = xc + r * cos(start); ys = yc + r * aspect * sin(start); xe = xc + r * cos(end); ye = yc + r * aspect * sin(end); x = xs; y = ys; for ( i = 1; i < r; i ++ ) { ph = start + i * th; xs = xc + r * cos(ph); ys = yc + r * aspect * sin(ph); osd_line(x, y, xs, ys); x = xs; y = ys; } osd_line(x, y, xe, ye);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -