如何使用SDL在c ++上进行cie色度图...现在可以绘制像素,但我不知道如何画线并连接它们并关闭它以形成马蹄形,有人可以帮忙吗? 我被卡住了,需要尽快完成这件事
#include <stdlib.h>
#include <SDL.h>
#include <SDL_thread.h>
void DrawPixel(SDL_Surface *screen, Uint8 R, Uint8 G, Uint8 B, float x, float y)
{
y = 1 - y;
x *= 300;
y *= 300;
Uint32 color = SDL_MapRGB(screen->format, R, G, B);
Uint32 *bufp;
bufp = (Uint32 *)screen->pixels + (int)y*screen->pitch/4 + (int)x;
*bufp = color;
}
int main( int argc, char* args[] )
{
float x[95] = {
0.1756,0.1752,0.1748,0.1745,0.1741,0.1740,0.1738,0.1736,0.1733,
0.1730,0.1726,0.1721,
0.1714,0.1703,0.1689,0.1669,0.1644,0.1611,0.1566,0.1510,0.1440,0.1355,
0.1241,0.1096,0.0913,0.0687,0.0454,0.0235,0.0082,
0.0039,0.0139,0.0389,0.0743,0.1142,0.1547,0.1929,
0.2296,0.2658,0.3016,0.3374,0.3731,0.4087,0.4441,
0.4788,0.5125,0.5448,0.5752,0.6029,0.6270,0.6482,
0.6658,0.6801,0.6915,0.7006,0.7079,0.7140,0.7190,
0.7230,0.7260,0.7283,0.7300,0.7311,0.7320,0.7327,
0.7334,0.7340,0.7344,0.7346,0.7347,0.7347,0.7347,
0.7347,0.7347,0.7347,0.7347,0.7347,0.7347,0.7347,
0.7347,0.7347,0.7347,0.7347,0.7347,0.7347,0.7347,
0.7347,0.7347,0.7347,0.7347,0.7347,0.7347,0.7347,0.7347,0.7347,0.7347};
float y[95] = {0.0053,0.0053,0.0052,0.0052,0.0050,0.0050,0.0049,
0.0049,0.0048,0.0048,0.0048,0.0048,0.0051,0.0058,0.0069
,0.0086,0.0109,0.0138,0.0177,0.0227,0.0297,0.0399,0.0578
,0.0868,0.1327,0.2007,0.2950,0.4127,0.5384,
0.6548,0.7502,0.8120,0.8338,0.8262,0.8059,0.7816,
0.7543,0.7243,0.6923,0.6588,0.6245,0.5896,0.5547,
0.5202,0.4866,0.4544,0.4242,0.3965,0.3725,0.3514,
0.3340,0.3197,0.3083,0.2993 ,0.2920,0.2859,0.2809,0.2769,
0.2740,0.2717,0.2700,0.2689,0.2680
,0.2673,0.2666,0.2660,0.2656,0.2654,0.2653,0.2653,0.2653,
0.2653,0.2653,0.2653,0.2653,0.2653,0.2653,0.2653,0.2653,
0.2653,0.2653,0.2653,0.2653,0.2653,0.2653,0.2653,0.2653,
0.2653,0.2653,0.2653,0.2653,0.2653,0.2653,0.2653,0.2653};
SDL_Surface* screen = NULL;
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
//Set up screen
screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
for (int i=0; i < 95; i++)
{
DrawPixel (screen, 255, 0, 0, x[i], y[i]);
}
//Update Screen
SDL_Flip( screen );
//Pause
SDL_Delay( 5000 );
//Quit SDL
SDL_Quit();
return 0;
}
答案 0 :(得分:0)
你给出的X / Y坐标是用于色度图的轮廓,所以你基本上只需要移动到第一个点,(x [0],y [0]),画一条线到每个后续点(x [i],y [i])绘制轮廓:
根据您使用的内容,您可能还希望对背景进行常规的彩色填充。对于它的价值,我们看到人们如何绘制它的变化很大(我不仅仅意味着方法,而是结果。你可能还想将最后一点连接到第一点以获得关闭曲线,绘制坐标,原点/横坐标等。