,이 스레드에 따라 자신의 코드를 작성해야합니다 : 이상하게도있다
http://processing.org/discourse/beta/num_1202486379.html
, 아니 라이브러리에서 점선 함수. 해당 스레드의 기능 중 하나를 사용하여 다음을 수행 할 수 있습니다.
void setup() {
int len=100;
int startx =250;
int starty= 250;
float angle = PI;
size (500, 500);
spiral_triangle(len, startx, starty, angle);
}
void spiral_triangle(int len, int startx, int starty, float angle) {
if (len>1) {
float[] spacing = {2,2};
dashline(startx, starty, int(startx+len*cos(angle)), int(starty + len*sin(angle)), spacing);
int new_startx = int(startx+len*cos(angle));
int new_starty = int(starty+len*sin(angle));
int new_len = len -10;
float new_angle = angle + PI/1.5;
spiral_triangle(new_len, new_startx, new_starty, new_angle);
}
}
/*
* Draw a dashed line with given set of dashes and gap lengths.
* x0 starting x-coordinate of line.
* y0 starting y-coordinate of line.
* x1 ending x-coordinate of line.
* y1 ending y-coordinate of line.
* spacing array giving lengths of dashes and gaps in pixels;
* an array with values {5, 3, 9, 4} will draw a line with a
* 5-pixel dash, 3-pixel gap, 9-pixel dash, and 4-pixel gap.
* if the array has an odd number of entries, the values are
* recycled, so an array of {5, 3, 2} will draw a line with a
* 5-pixel dash, 3-pixel gap, 2-pixel dash, 5-pixel gap,
* 3-pixel dash, and 2-pixel gap, then repeat.
*/
void dashline(float x0, float y0, float x1, float y1, float[ ] spacing)
{
float distance = dist(x0, y0, x1, y1);
float [ ] xSpacing = new float[spacing.length];
float [ ] ySpacing = new float[spacing.length];
float drawn = 0.0; // amount of distance drawn
if (distance > 0)
{
int i;
boolean drawLine = true; // alternate between dashes and gaps
/*
Figure out x and y distances for each of the spacing values
I decided to trade memory for time; I'd rather allocate
a few dozen bytes than have to do a calculation every time
I draw.
*/
for (i = 0; i < spacing.length; i++)
{
xSpacing[i] = lerp(0, (x1 - x0), spacing[i]/distance);
ySpacing[i] = lerp(0, (y1 - y0), spacing[i]/distance);
}
i = 0;
while (drawn < distance)
{
if (drawLine)
{
line(x0, y0, x0 + xSpacing[i], y0 + ySpacing[i]);
}
x0 += xSpacing[i];
y0 += ySpacing[i];
/* Add distance "drawn" by this line or gap */
drawn = drawn + mag(xSpacing[i], ySpacing[i]);
i = (i + 1) % spacing.length; // cycle through array
drawLine = !drawLine; // switch between dash and gap
}
}
}
이 정보가 도움이되기를 바랍니다.
나는 혼란 스럽다. 게시 한 코드는 개별 선분을 만든다. spiral_triangle에 대한 호출은 재귀 적이며 각 호출 중에 별도의 행을 그립니다. 그것은 구부러진 하나의 선이 아니라 개별 선분을 그리는 것입니다. 귀하의 요청을 명확히하실 수 있습니까? – spex
나는 질문을 편집했다 :) – choloboy
나는 아직도 혼란 스럽다. 코드가 이미 직선 부분에서 나선형을 만듭니다. – spex