рисуя круг кругов не должны быть сложными, и вы уже знаете, как полярная к декартовым преобразования координат системы. Что-то же просто, как это будет работать:
/*
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();
}
}
Удачи!
Wow спасибо, что сломал все, очень ценили. –
Рад, что это помогает и благодарит вас за принятие. Не стесняйтесь голосовать, а также;) Это было интересно изучить. Проверьте [эту цветную версию] (http://lifesine.eu/so/CirclesOfCirclesFilled/) Я закончил с помощью drag mouseX и mouseY для изменения параметров). Мне бы хотелось увидеть, какие сумасшедшие модели вы придумаете :) –