问题描述
我已经尝试修复此问题已有一段时间了,但是它似乎没有用。 “无法运行草图(目标VM初始化失败)。”
我将在下面写下完整的代码。
在draw()中,有三个for循环。
for(int i = 0; i<objectAmount; i++) {
circles[i].drawObj();
}
第一个创建圆,而第二个嵌套圆负责碰撞并绘制线条;
for(int i = 0; i<rayAmount; i++) {
rays[i].update();
for(int j = 0; j<objectAmount; j++) {
rays[i].collide(circles[j]);
}
line(rays[i].xPos,rays[i].yPos,rays[i].xEnd,rays[i].yEnd);
}
.collide指向'ray'上的点并移近圆,直到达到某个值为止,在该处标记线条的末端,然后由line()函数使用该线条将其绘制到圆上。 / p>
由于某种原因,当我实现.collide函数时,一切都会停止工作,除非我将光线数量设置为一个,在这种情况下将不会出现光线,但是圆的生成会随之而来很好。
int rayAmount = 45;
int angleCorrect = 360/rayAmount;
int objectAmount = 10;
Ray[] rays = new Ray[rayAmount];
Object[] circles = new Object[objectAmount];
void setup() {
size(600,400,P2D);
for(int i = 0; i<rayAmount; i++) {
rays[i] = new Ray(i*angleCorrect);
}
for(int i = 0; i<objectAmount; i++) {
circles[i] = new Object(random(0,600),random(0,400),random(20,100));
}
}
void draw() {
background(255);
stroke(100);
for(int i = 0; i<objectAmount; i++) {
circles[i].drawObj();
}
for(int i = 0; i<rayAmount; i++) {
rays[i].update();
for(int j = 0; j<objectAmount; j++) {
rays[i].collide(circles[j]);
}
line(rays[i].xPos,rays[i].yEnd);
}
}
class Ray {
float xPos,yPos,Angle,xEnd,yEnd;
Ray(float angle) {
xPos = mouseX;
yPos = mouseY;
Angle = angle;
}
void update() {
xPos = mouseX;
yPos = mouseY;
//xEnd = xPos + 100 * cos(radians(Angle));
//yEnd = yPos + 100 * sin(radians(Angle));
}
void collide(Object other) {
float newXEnd = this.xEnd;
float newYEnd = this.yEnd;
float distToObject = sqrt(pow(other.xPos-this.xPos,2) + pow(other.yPos-this.yPos,2));
while(distToObject > 1) {
newXEnd = newXEnd + distToObject * cos(radians(Angle));
newYEnd = newYEnd + distToObject * sin(radians(Angle));
distToObject = sqrt(pow(other.xPos-newXEnd,2) + pow(other.yPos-newYEnd,2));
}
this.xEnd = newXEnd;
this.yEnd = newYEnd;
}
}
class Object {
float xPos,radius;
Object(float x,float y,float r) {
xPos = x;
yPos = y;
radius = r;
}
void drawObj() {
stroke(100);
circle(xPos,radius);
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)