2016-05-07 4 views
1

Я пытаюсь воссоздать массив кругов увеличенного размера, каждый из которых разделяется на создание точек для создания пульсаций эллипсов. Я знаю, как разделить каждый круг на несколько точек и нарисовать эллипсы. И я знаю, как создать серию концентрических кругов, но я, похоже, не могу объединить свои мысли вокруг их объединения. Когда я делаю, я получаю результат, который выглядит следующим образом ..Концентрическое кольцо эллипсов

Circle Overlap

Этот результат происходит потому, что каждый отдельный Эллипс добавляет ряд эллипсов в увеличении расстояния от исходного эллипса. Тем не менее, я не уверен, как исправить исходный вопрос о том, что серия кругов делится на несколько точек для создания эллипсов.

Спасибо.

Blackhole b; 

void setup() { 
    size(750, 500); 
    smooth(); 
    b = new Blackhole(); 
} 

void draw() { 
    b.divide(); 
    b.display(); 

} 

class Blackhole { 
    PVector location; 
    PVector velocity; 
    PVector acceleration; 
    PVector center; 
    float speed = 0; 

    int [] eSize = {0, 25, 50, 75, 100, 125, 150, 175}; 
    float radius = 100; 
    int numPoints = 16; 
    float angle = TWO_PI/(float)numPoints; 
    float [] [] xyArray; 

    Blackhole() { 
    location = new PVector(width/2, height/2); 
    velocity = new PVector(0, 0); 
    acceleration = new PVector(.0, 0); 
    } 

    void divide() { 
    xyArray = new float [numPoints][3]; 
    for (int i=0; i<numPoints; i++) { 
     float x = radius*sin(angle*i)+width/2; 
     float y = radius*cos(angle*i)+height/2; 
     xyArray[i][0] = x; 
     xyArray[i][1] = y; 
    } 
    } 



    void display() { 
    background(#202020); 


    speed = speed + 0.05; 
    float pulse = noise(speed); 
    pulse = map(pulse, 0, 1, 150, 175); 

    noFill(); 
    stroke(255, 100); 
    for (int j = 0; j < eSize.length; j++) { 
     for (int i = 0; i < numPoints; i++) { 
     float x = xyArray[i][0]; 
     float y = xyArray[i][1]; 
     ellipse(width/2, height/2, pulse + eSize[j], pulse + eSize[j]); 
     ellipse(x, y, 5, 5); 
     } 
    } 
    } 
} 

ответ

1

рисуя круг кругов не должны быть сложными, и вы уже знаете, как полярная к декартовым преобразования координат системы. Что-то же просто, как это будет работать:

/* 
    draws a large circle with each vertex drawn as a smaller circle 
    sides = circle detail, the more sides, the more detaild the circle will be 
    largeRadius = large circle radius 
    smallRadius = radius of each small circle 
*/ 
void circleOfCircles(int sides,float largeRadius, float smallRadius){ 
    float angleIncrement = TWO_PI/sides; 
    for(int i = 0 ; i < sides; i++){ 
    float x = cos(angleIncrement * i) * largeRadius; 
    float y = sin(angleIncrement * i) * largeRadius; 
    ellipse(x,y,smallRadius,smallRadius); 
    } 
} 

Каких используя ваши ценности будет выглядеть следующим образом:

float speed = 0; 
int [] eSize = {0, 25, 50, 75, 100, 125, 150, 175}; 
float radius = 100; 
int numPoints = 16; 


void setup(){ 
    size(750,500); 
    smooth(); 
} 
void draw(){ 
    background(#202020); 
    translate(width * 0.5, height * 0.5); 

    speed = speed + 0.05; 
    float pulse = noise(speed); 
    pulse = map(pulse, 0.0, 1.0, 150, 175); 

    noFill(); 
    stroke(255, 100); 
    for (int j = 0; j < eSize.length; j++) { 
    circleOfCircles(numPoints,pulse + eSize[j], 5); 
    } 
} 
/* 
    draws a large circle with each vertex drawn as a smaller circle 
    sides = circle detail, the more sides, the more detaild the circle will be 
    largeRadius = large circle radius 
    smallRadius = radius of each small circle 
*/ 
void circleOfCircles(int sides,float largeRadius, float smallRadius){ 
    float angleIncrement = TWO_PI/sides; 
    for(int i = 0 ; i < sides; i++){ 
    float x = cos(angleIncrement * i) * largeRadius; 
    float y = sin(angleIncrement * i) * largeRadius; 
    ellipse(x,y,smallRadius,smallRadius); 
    } 
} 

Если полярный к декартову преобразованию сбивает с толком, вы можете просто isolate transformations using pushMatrix() and popMatrix():

void circleOfCircles(int sides,float largeRadius, float smallRadius){ 
    float angleIncrement = TWO_PI/sides; 
    for(int i = 0 ; i < sides; i++){ 
    pushMatrix(); 
     rotate(angleIncrement * i); 
     translate(largeRadius,0); 
     ellipse(0,0,smallRadius,smallRadius); 
    popMatrix(); 
    } 
} 

Как правило, лучше всего держать вещи как можно проще. Вы используете класс, и это здорово! Хорошо инкапсулировать функциональность. Это облегчит подключение к другим эскизам в будущем.

Однако, я есть некоторые неиспользуемые переменные в вашем классе:

PVector location; 
    PVector velocity; 
    PVector acceleration; 
    PVector center; 

Некоторые из них инициализируются в конструкторе, но опять же никогда не использовали.

Основная проблема с точки зрения кругов кругов вокруг divide() и xyArray. В divide() вы вычисляете точки вокруг круга с одним радиусом, хотя в display() похоже, что вы хотите использовать разные радиусы. Я удалил функцию divide(), которая устранила необходимость использования xyArray и перевернула ее дважды (один раз, чтобы установить позиции, а затем прочитать). Вместо этого используется уведомление вместо radius, pulseRadius, которое учитывает pulse и eSize.

Вот упрощенная версия кода с использованием radius, но и pulse и eSize, которые, вероятно, что вы пытаетесь сделать:

Blackhole b; 

void setup() { 
    size(750, 500); 
    smooth(); 
    b = new Blackhole(); 
} 

void draw() { 
    background(#202020); 
    b.display(); 
} 

class Blackhole { 
    float speed = 0; 

    int [] eSize = {0, 25, 50, 75, 100, 125, 150, 175}; 
    float radius = 100; 
    int numPoints = 16; 
    float angle = TWO_PI/(float)numPoints; 

    Blackhole() { 

    } 

    void display() { 

    speed = speed + 0.05; 
    float pulse = noise(speed); 
    pulse = map(pulse, 0, 1, 150, 175); 

    noFill(); 
    stroke(255, 100); 
    for (int j = 0; j < eSize.length; j++) { 
     for (int i = 0; i < numPoints; i++) { 

     float pulseRadius = radius + pulse + eSize[j]; 
     float x = pulseRadius * sin(angle*i)+width/2; 
     float y = pulseRadius * cos(angle*i)+height/2; 
     ellipse(x, y, 5, 5); 
     } 
    } 
    } 
} 

Так как исследование, here является Java-демонстрационная кода используя функцию и синус-вызовы для изменения количества точек в большом круге и двух радиусах.

int numPoints = 16; 


void setup(){ 
    size(750,500); 
    smooth(); 
    noFill(); 
} 
void draw(){ 
    background(#202020); 
    translate(width * 0.5, height * 0.5); 

    for(int i = 0 ; i < numPoints; i++){ 
    stroke(255, (i+1) * 10); 
    circleOfCircles((int)map(sin(frameCount * .001 + i),-1.0,1.0,12 , 64),//number of sides 
         map(sin(frameCount * .010 + i),-1.0,1.0,100,225),//large radius 
         map(sin(frameCount * .100 + i),-1.0,1.0, 1, 30));//small radius 
    } 
} 
/* 
    draws a large circle with each vertex drawn as a smaller circle 
    sides = circle detail, the more sides, the more detaild the circle will be 
    largeRadius = large circle radius 
    smallRadius = radius of each small circle 
*/ 
void circleOfCircles(int sides,float largeRadius, float smallRadius){ 
    float angleIncrement = TWO_PI/sides; 
    for(int i = 0 ; i < sides; i++){ 
    pushMatrix(); 
     rotate(angleIncrement * i); 
     translate(largeRadius,0); 
     ellipse(0,0,smallRadius,smallRadius); 
    popMatrix(); 
    } 
} 

circles animation preview

Удачи!

+0

Wow спасибо, что сломал все, очень ценили. –

+0

Рад, что это помогает и благодарит вас за принятие. Не стесняйтесь голосовать, а также;) Это было интересно изучить. Проверьте [эту цветную версию] (http://lifesine.eu/so/CirclesOfCirclesFilled/) Я закончил с помощью drag mouseX и mouseY для изменения параметров). Мне бы хотелось увидеть, какие сумасшедшие модели вы придумаете :) –

Смежные вопросы