Processing 加工间距
我试着在处理过程中画熊,(只是简单的圆圈),我怎样才能使熊的间距相等,并且从屏幕边缘到熊的两侧都有相同的空间?以及垂直Processing 加工间距,processing,spacing,Processing,Spacing,我试着在处理过程中画熊,(只是简单的圆圈),我怎样才能使熊的间距相等,并且从屏幕边缘到熊的两侧都有相同的空间?以及垂直 我知道这是模糊的,但是我很难解释事物因为你不提供任何代码或例子,我只会告诉你如何在草图中间放置圆圈。 为简单起见,请想象以下设置: void setup(){ size(400, 400); } 1)最基本的方法是将该圆的位置硬编码为椭圆绘制函数。 其中前两个参数是圆心的坐标。只需从尺寸400x400中查找mid是否在坐标200x200。这是一个糟糕的方法,你应该避免使
<>我知道这是模糊的,但是我很难解释事物因为你不提供任何代码或例子,我只会告诉你如何在草图中间放置圆圈。 为简单起见,请想象以下设置:
void setup(){
size(400, 400);
}
1)最基本的方法是将该圆的位置硬编码为椭圆绘制函数。
其中前两个参数是圆心的坐标。只需从尺寸400x400
中查找mid是否在坐标200x200
。这是一个糟糕的方法,你应该避免使用它
2)更好的方法是使用全局变量width
和height
ellipse(width/2, height/2, 50, 50);
3)当您绘制或移动更复杂的对象时,在我们的示例中,最好使用一些函数始终以相同的固定位置绘制这些对象
void draw_circle(){
ellipse(0, 0, 50, 50);
}
只需移动绘图中心,我们的draw
函数如下所示
void draw(){
pushMatrix();
translate(width/2, height/2);
draw_circle();
popMatrix();
}
使用此功能,您可以从侧面等距绘制熊。听起来您需要等距圆的网格。为此,您只需在x和y方向将空间划分为网格。最简单的方法是将Majlik展示的东西封装在一个双循环中,在“虚拟”网格中从一个单元移动到另一个单元。为了更清楚地看到这一点,在下面的代码中有一个额外的一点,这样,如果您按下“g”键(对于网格),您将看到网格单元,每个单元中都有一个圆心。您可以按任何其他键使网格消失 您可以看到,每种方法都会得到相同的结果:inside draw()取消对所需的方法的注释,并注释掉另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);
}
}
int nx=4;//水平圆数
int ny=5;//垂直圆数
int-divx;
int divy;
内径=40;
无效设置(){
大小(600600);
//计算网格每个单元的宽度和高度
divx=宽度/nx;
divy=高度/ny;
}
//绘制规则圆网格的3种方法
作废提款(){
背景(200);
//如果键入了g键,则显示单元格布局,否则不显示
如果(键=='g')
drawGrid();
//单向
对于(int i=0;i
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);
}
}