2016-04-07 22 views
1

我正在嘗試在處理中獲得橢圓的螺旋形。我無法理解如何遍歷單詞中的每個點(使用幾何庫提取)以確保每個點都是每個螺旋的開始。目前它或者形成一個螺旋或者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); 
     } 



} 
+1

今後請儘量提供[MCVE],而不是發佈您的整個草圖。硬編碼的一組點可以很好地顯示你的問題,所以不需要發佈所有額外的代碼。這讓我們很難幫助你。 –

回答

1

在這看看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 (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); 
    } 
} 
+0

Ihmm。我得到一個空白屏幕。我必須刪除內部循環中的int,因爲它已經被聲明(獲取重複的變量錯誤) –

+0

而不是int我試過了(float x1 = 0; x1 <500; x1 ++),它給了我'堆棧'圖片,但沒有橢圓螺旋點:( –

+0

@ SebastianZeki你只在這個循環內使用'r'和'theta'變量,所以不需要在草圖的頂部聲明它們。我的例子有效,但這只是一個例子,你必須修改代碼以適應你的具體情況 –