2013-08-02 70 views
-4

如何在C++上使用SDL做cie色度圖..我現在可以繪製像素,但我不知道如何繪製線條並連接它們並關閉它以形成馬蹄形,任何人都可以幫幫我? 我一直堅持,需要儘快完成這項儘可能​​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;  
} 
+1

你嘗試了哪些步驟?你卡在哪裏?這個社區不喜歡給你的功課解決方案... – Gnosophilon

回答

0

的X/Y座標你給是色度圖的輪廓,所以你基本上只需要移動到第一點, (X [0],Y [0]),該畫一條線到每個後續點(x [I],Y [1])繪製輪廓:

enter image description here

取決於你」重新使用它,你可能想要做背景的通常彩色填充。對於它的價值來說,人們在繪製方式上會出現很多變化(我並不是指方法,而是結果,您可能還想將最後一個點連接到第一個以獲得關閉曲線,繪製座標,原點/橫座標等

+0

好..所以我必須存儲這些座標在一個數組中,並繪製出來,但我該怎麼做呢? – user2640299

+0

問題是我不知道如何開始?我真的需要幫助。 – user2640299

+0

@ user2640299:我不使用SDL,所以我不能真的使用Win32 API,第一個點將成爲「MoveTo」的一個調用,然後是每個後續點的「LineTo」。 –