我试图在处理中使用椭圆形的螺旋线来生长。我无法理解如何遍历单词中的每个点(使用几何库提取),以确保每个点都是每个螺旋的起点。目前它要么形成一个螺旋,要么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);
}
}
答案 0 :(得分:1)
看看这个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);
}
}
在这里,您循环遍历每个点,然后在该点绘制一个椭圆。我认为你想要做的就是在那一点上画出一个螺旋线。因此,不必绘制单个椭圆,而是必须输入第二个for循环来创建螺旋。
这样的事情:
var startingArray = [
{name: 'thingy',
order: 1}
{name: 'thinger',
order: 3},
{name: 'thang',
order: 2}
}
]
new superArray(startingArray, 'order');
console.log(superArray[2])// {name: 'thang', order: 2}
superArray.push({name:'thangeroo', order:34})
console.log(superArray[34])// {name: 'thangeroo', order: 34}
superArray.forEach((thing) =>{
console.log(thing) // this would always iterate in order based on 'order'
})
superArray.pop()//removes {name: 'thangeroo', order: 34}
for(var k in superArray){
var thing = superArray[k] // this seems less important but still useful
}