【发布时间】:2020-01-12 17:49:09
【问题描述】:
我有一个用我制作的 Processing 编写的 Java 程序,它在处理过程中画出螺旋形,但我不确定某些代码行是如何工作的。我根据教程编写了它们。我在我不理解的行中添加了 大写字母的 cmets。小写的 cmets 是 我明白 的行。如果您了解这些行的工作原理,请用非常简单的术语解释!非常感谢。
void setup()
{
size(500,500);
frameRate(15);
}
void draw()
{
background(0); //fills background with black
noStroke(); //gets rid of stroke
int circlenumber = 999;// determines how many circles will be drawn
float radius = 5; //radius of each small circle
float area = (radius) * (radius) * PI; //area of each small circle
float total = 0; //total areas of circles already drawn
float offset = frameCount * 0.01; //HOW DOES IT WORK & WHAT DOES IT DO
for (int i = 1; i <= circlenumber; ++i) { // loops through all of the circles making up the pattern
float angle = i*19 + offset; //HOW DOES IT WORK & WHAT DOES IT DO
total += area; // adds up the areas of all the small circles that have already been drawn
float amplitude = sqrt( total / PI ); //amplitude of trigonometric spiral
float x = width/2 + cos(angle) * amplitude;//HOW DOES IT WORK & WHAT DOES IT DO
float hue = i;//determines circle color based on circle number
fill(hue, 44, 255);//fills circle with that color
ellipse(x, 1*i, radius*2, radius*2); //draws circle
}
}
【问题讨论】:
标签: java processing draw trigonometry