从点列表制作螺旋
Making a spiral from a list of points
我正在尝试让椭圆螺旋从 Processing 中的一个词中长出来。我无法理解如何遍历单词中的每个点(使用几何库提取)以确保每个点都是每个螺旋的开始。目前它要么形成一个螺旋,要么 translate()
函数(注释掉)将省略号放在各处。
这是我的代码:
import geomerative.*;
//Leaf myLeaf;
float pointCount;
int freq = 1;
float phi = 1;
RFont font;
RShape grp;
RPoint[] points;
String TextTyped = "wipe";
float r = 0;
float theta = 0;
float angle;
float y;
void setup(){
RG.init(this);
font = new RFont("/Users/sebastianzeki/rp_samples/samples/external_library/java_processing/geomerative/data/FreeSans.ttf",200,RFont.LEFT);
size(800,600);
smooth();
background(255);
}
void draw(){
stroke(0);
strokeWeight(2);
noFill();
RGroup textGrouped;
// When extracting the dots, the entered characters do not have to be processed individually.
// The entire text textTyped can be grouped. Then the getPoints () function provides a list
// of dots comprising the outline lines of the entire text
textGrouped = font.toGroup (TextTyped);
textGrouped = textGrouped.toPolygonGroup ();
RPoint[] thePoints = textGrouped.getPoints ();
stroke (0, 255, 255, 64);
strokeWeight (1);
//This draws the word outline in blue circles which is fine
for (int i = 0; i < thePoints.length; i++ ) {
ellipse(thePoints[i].x+100, thePoints[i].y+200, 3, 3);
}
//This is the part that I am trying to get to draw spirals from the word points
for (int i = 0; i < thePoints.length; i++ ) {
translate(thePoints[i].x,thePoints[i].y);
float x = r * cos(theta);
float y = r * sin(theta);
r +=0.1;
theta += 0.01;
ellipse(x, y, 5, 50);
}
}
看看这个 for 循环:
for (int i = 0; i < thePoints.length; i++ ) {
translate(thePoints[i].x,thePoints[i].y);
float x = r * cos(theta);
float y = r * sin(theta);
r +=0.1;
theta += 0.01;
ellipse(x, y, 5, 50);
}
在这里,您将遍历每个点,然后在该点绘制一个椭圆。我想你想做的是在这一点上画一个螺旋。因此,不是绘制单个椭圆,而是必须输入第二个 for 循环来创建螺旋线。
像这样:
for (int i = 0; i < thePoints.length; i++ ) {
//move to the point
translate(thePoints[i].x,thePoints[i].y);
//reset your spiral variables
float r = 0;
float theta = 0;
//draw 100 points in a spiral
for (int i = 0; i < 100; i++) {
float x = r * cos(theta);
float y = r * sin(theta);
r += 1;
theta += 0.1;
ellipse(x, y, 5, 5);
}
}
我正在尝试让椭圆螺旋从 Processing 中的一个词中长出来。我无法理解如何遍历单词中的每个点(使用几何库提取)以确保每个点都是每个螺旋的开始。目前它要么形成一个螺旋,要么 translate()
函数(注释掉)将省略号放在各处。
这是我的代码:
import geomerative.*;
//Leaf myLeaf;
float pointCount;
int freq = 1;
float phi = 1;
RFont font;
RShape grp;
RPoint[] points;
String TextTyped = "wipe";
float r = 0;
float theta = 0;
float angle;
float y;
void setup(){
RG.init(this);
font = new RFont("/Users/sebastianzeki/rp_samples/samples/external_library/java_processing/geomerative/data/FreeSans.ttf",200,RFont.LEFT);
size(800,600);
smooth();
background(255);
}
void draw(){
stroke(0);
strokeWeight(2);
noFill();
RGroup textGrouped;
// When extracting the dots, the entered characters do not have to be processed individually.
// The entire text textTyped can be grouped. Then the getPoints () function provides a list
// of dots comprising the outline lines of the entire text
textGrouped = font.toGroup (TextTyped);
textGrouped = textGrouped.toPolygonGroup ();
RPoint[] thePoints = textGrouped.getPoints ();
stroke (0, 255, 255, 64);
strokeWeight (1);
//This draws the word outline in blue circles which is fine
for (int i = 0; i < thePoints.length; i++ ) {
ellipse(thePoints[i].x+100, thePoints[i].y+200, 3, 3);
}
//This is the part that I am trying to get to draw spirals from the word points
for (int i = 0; i < thePoints.length; i++ ) {
translate(thePoints[i].x,thePoints[i].y);
float x = r * cos(theta);
float y = r * sin(theta);
r +=0.1;
theta += 0.01;
ellipse(x, y, 5, 50);
}
}
看看这个 for 循环:
for (int i = 0; i < thePoints.length; i++ ) {
translate(thePoints[i].x,thePoints[i].y);
float x = r * cos(theta);
float y = r * sin(theta);
r +=0.1;
theta += 0.01;
ellipse(x, y, 5, 50);
}
在这里,您将遍历每个点,然后在该点绘制一个椭圆。我想你想做的是在这一点上画一个螺旋。因此,不是绘制单个椭圆,而是必须输入第二个 for 循环来创建螺旋线。
像这样:
for (int i = 0; i < thePoints.length; i++ ) {
//move to the point
translate(thePoints[i].x,thePoints[i].y);
//reset your spiral variables
float r = 0;
float theta = 0;
//draw 100 points in a spiral
for (int i = 0; i < 100; i++) {
float x = r * cos(theta);
float y = r * sin(theta);
r += 1;
theta += 0.1;
ellipse(x, y, 5, 5);
}
}