📄 draw.c
字号:
/*************************************************************************** * draw.c * * Thu May 24 11:49:06 2007 * Copyright 2007 kf701 * Email <kf701.ye AT gmail.com> ****************************************************************************//* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <math.h>#include "kf701.h"void draw_line(m3d_point p1, m3d_point p2, m3d_color color, draw_dot_func func){ m3d_point p; int32_t x,y; for( x=MIN(p1.x,p2.x); x<=MAX(p1.x,p2.x); x++ ) { y = (p2.y-p1.y)*(x-p1.x)/(p2.x-p1.x) + p1.y; p.x = x; p.y = y; func( p, color); }}void draw_triangle(m3d_point p1, m3d_point p2, m3d_point p3, m3d_color color, draw_dot_func func){ m3d_point p[3]; p[0] = p1; p[1] = p2; p[2] = p3; draw_polygon(3, p, color, func);}void draw_polygon(uint32_t num, m3d_point *array, m3d_color color, draw_dot_func func){ int i; for(i=0; i<num; i++) { draw_line(array[i], array[(i+1)%num], color, func); }}void draw_circle(m3d_point center, uint32_t radius, m3d_color color, draw_dot_func func){ m3d_point p; int32_t x,y,tmp; for(x=center.x-radius; x<=center.x+radius; x++) { p.x = x; tmp = sqrt(radius*radius -(x-center.x)*(x-center.x)); p.y = center.y + tmp; func( p, color); p.y = center.y - tmp; func( p, color); } for(y=center.y-radius; y<=center.y+radius; y++) { p.y = y; tmp = sqrt(radius*radius - (y-center.y)*(y-center.y)); p.x = center.x + tmp; func( p, color); p.x = center.x - tmp; func( p, color); }}void draw_parabola_x(m3d_point center, int32_t a, m3d_color color, draw_dot_func func){ int32_t x; m3d_point p; for(x=center.x-100; x<center.x+100; x++) { p.x = x; p.y = (x-center.x)*(x-center.x)/a + center.y; func( p, color); }}void draw_parabola_y(m3d_point center, int32_t a, m3d_color color, draw_dot_func func){ int32_t y; m3d_point p; for(y=center.y-100; y<center.y+100; y++) { p.y = y; p.x = (y-center.y)*(y-center.y)/a + center.x; func( p, color); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -