Q
加工間距
0
A
回答
1
因爲你不提供任何代碼或例子,我只會告訴你如何放置圓草圖的中間。
爲了簡單起見想象此設置:
void setup(){
size(400, 400);
}
1)非常基本的方法將是該圓到橢圓繪製函數的硬碼位置。
ellipse(200, 200, 50, 50);
其中前兩個參數是圓心的座標。從400x400
大小簡單找出,中間座標爲200x200
。這是不好的方法,你應該避免使用它。
2)更好的辦法是使用全局變量來計算中心座標width
和height
ellipse(width/2, height/2, 50, 50);
3)當要繪製或移動更復雜的對象,優選的是使用一些函數來在我們的示例中總是以相同的固定位置繪製此對象
void draw_circle(){
ellipse(0, 0, 50, 50);
}
而只是移動中心使用transformations繪製所以我們draw
函數將看起來像這樣
void draw(){
pushMatrix();
translate(width/2, height/2);
draw_circle();
popMatrix();
}
使用這個你可以能夠得出熊等距隔開,並從側面。
1
這聽起來像你想要一個等間距的圓形網格。爲此,你只需要將你的空間分成x和y方向的網格。做到這一點的最簡單方法是將Majlik在雙循環內顯示的內容包裝在「虛擬」網格中,從單元格移動到單元格。爲了更清楚地看到這一點,在下面的代碼中有一個額外的一點點,所以如果你按下'g'鍵(對於網格),你會看到網格單元格,每個單元格都有一個圓心。您可以按其他任何鍵使網格消失。
你可以看到,每路提供了相同的結果:平局內()取消註釋您想要的並註釋掉其它2.
int nx = 4; // number of circles horizontally
int ny = 5; // number of circles vertically
int divx;
int divy;
int diameter = 40;
void setup() {
size(600, 600);
// calculate width and hegith of each cell of the grid
divx = width/nx;
divy = height/ny;
}
// 3 ways to draw a regular grid of circles
void draw() {
background(200);
// show the cell layout if the g key was typed, otherwise don't
if(key == 'g')
drawGrid();
// 1 way
for(int i = 0; i < nx; i++) {
for(int j = 0; j < ny; j++) {
ellipse(i * divx + divx/2, j * divy + divy/2, diameter, diameter);
}
}
// another way
// for(int i = divx/2; i < width; i += divx) {
// for(int j = divy/2; j < height; j += divy) {
// ellipse(i, j, diameter, diameter);
// }
// }
// yet another way
// for(int i = divx/2; i < width; i += divx) {
// for(int j = divy/2; j < height; j += divy) {
// pushMatrix();
// translate(i, j);
// ellipse(0, 0, diameter, diameter);
// popMatrix();
// }
// }
}
void drawGrid() {
// draw vertical lines
for(int i = 1; i < nx; i++) {
line(i * divx, 0, i * divx, height);
}
// draw horizontal lines
for(int j = 1; j < ny; j++) {
line(0, j * divy, width, j * divy);
}
}
相關問題
- 1. 間距不工作
- 2. 行間距不工作
- 3. 邊框間距不工作
- 4. wxFormBuilder工具欄間距
- 5. Android工作室間距
- 6. 如何添加間距在
- 7. Android增加單詞間距
- 8. NSTextField添加行間距
- 9. Bootstrap:在列之間添加間距
- 10. 增加表格行之間的間距
- 11. 在ggplot2中添加條間間距
- 12. 如何在listview.items之間添加間距?
- 13. SSCollectionView邊距/間距
- 14. 間距
- 15. 間距
- 16. 表格邊框間距不工作
- 17. iPhone工具欄按鈕間距
- 18. 工具欄菜單項間距問題
- 19. CSS鏈接間距和段落間距
- 20. divs之間的間距(邊距?)
- 21. Divs:等距水平間距
- 22. 邊距或填充間距?
- 23. JQplot間的間距?
- 24. 如何在razor @if中添加間距邊距?
- 25. 如何增加vim中行號邊距的間距?
- 26. 菜單切換添加間距(邊距)如果點擊
- 27. 添加間距文本框導致
- 28. 在div之間添加邊距
- 29. 添加位數間距與jQuery
- 30. 如何在NSAttributedString中添加行間距