你不會通過手動繪製像素到屏幕上做圖形,這樣的瘋狂謊言。
你想使用的是DirectX或OpenGL。我建議你打開谷歌並閱讀,這裏有很多東西要讀。
一旦你下載了庫,有很多示例項目可以看一看,它們會幫助你開始。
這裏有兩種方法:計算向量的數學方法,描述具有非常多邊的形狀(即它看起來像一個圓)。或者有一種「欺騙」的方法,即用alpha通道在屏幕上繪製一個圓的紋理(即圖片),以使紋理的其餘部分透明。 (作弊方法更容易編碼,執行速度更快,產生更好的結果,儘管它不太靈活)。
如果你想做數學運算,那麼這兩個庫都允許你畫線,因此你需要從每一行的起點和終點開始,而不是單個像素。我,你想要矢量圖形。
我不能做繁重的數學權利,但該向量方法看起來有點像這樣(須藤代碼):
in-param: num_of_sides, length_of_side;
float angle = 360/num_of_sides;
float start_x = 0;
float start_y = 0;
x = startX;
y = startX;
for(int i(0); i < num_of_sides; ++i)
{
float endX, endY;
rotateOffsetByAngle(x, y, x + lenth_of_side, y, angle * i, endX, endY);
drawline(x, y, endX, endY);
x = endX;
y = endY;
}
drawline(float startX, startY, endX, endY)
{
//does code that draws line between the start and end coordinates;
}
rotateOffsetByAngle(float startX, startY, endX, endY, angle, &outX, &outY)
{
//the in-parameters startX, startY and endX, endY describe a line
//we treat this line as the offset from the starting point
//do code that rotates this line around the point startX, startY, by the angle.
//after this rotation is done endX and endY are now at the same
//distance from startX and startY that they were, but rotated.
outX = endX;
outY = endY; //pass these new coordinates back out by reference;
}
在上面的代碼中,我們繞了一圈的移動之外一個一個畫出外面的每條線。對於每條線我們都有一個起始點和一個偏移量,然後我們將偏移量旋轉一個角度(這個角度隨着我們在圓周上移動而增加)。然後我們畫出從起點到偏移點的直線。在我們開始下一次迭代之前,我們將起點移動到偏移點,以便下一行從最後一行開始。
我希望這是可以理解的。
來源
2012-10-29 11:41:08
Ian
[中點圓算法](http://en.wikipedia.org/wiki/Midpoint_circle_algorithm) – Andrey