首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >三个椭圆的旋转木马加工

三个椭圆的旋转木马加工
EN

Stack Overflow用户
提问于 2021-01-17 05:12:50
回答 1查看 32关注 0票数 2

我试图在处理过程中创建一个带有三个椭圆的垂直轮播。我可以用两个椭圆来完成这件事--旋转木马一遍又一遍地重复自己。到目前为止还不错-它认为我可以对三个使用相同的逻辑,但我错了。我开始认为它适用于更多的变量,但又错了…我在逻辑中遗漏了什么?我真的想不出如何设置这些值来使其无缝地重复自身…

下面是两个例子(这个是“无缝”的):

代码语言:javascript
复制
float yspeed = 5;
float circleY;
int d = 720;
void setup() {
  
 size(1080, 1620 );
 circleY = 0;
 
 }
 
 void draw() {
   background(255);
   fill(0);
   noStroke();
   ellipse(width/2, circleY+height/2, d,d);
   ellipse(width/2, circleY-height/2, d,d );
   circleY = circleY + yspeed;
   
if (circleY > height) {
 circleY=0;}

 }

这是我的三个…的在制品(顺便说一句,颜色只是为了看得更好):

代码语言:javascript
复制
float yspeed1 = 5;
float yspeed2 = 5;
float yspeed3 = 5;
float circleY1;
float circleY2;
float circleY3;
int d = 720;
void setup() {

  size(1080, 1620);
  circleY1 = 0;
  circleY2 = 0;
  circleY3 = 0;
}

void draw() {
  background(255);
  noStroke();

  fill(255, 0, 0);
  ellipse(width/2, circleY1, d, d);
  circleY1= circleY1 + yspeed1;
  if (circleY1 > height+d/2  ) {
    circleY1=0;
  }

  fill(0, 255, 0);
  ellipse(width/2, circleY2-810, d, d);
  circleY2= circleY2 + yspeed2;
  if (circleY2 > height+d/2  ) {
    circleY2=0  ;
  }


  fill(0, 0, 255);
  ellipse(width/2, circleY2-1620, d, d);
  circleY3= circleY3 + yspeed3;
  if (circleY3 > height+d/2  ) {
    circleY3=0  ;
  }
}

有三个变量的第一个总是从所有变量的初始点开始-但我认为使用单独的变量会改变它?

感谢您的任何帮助!

EN

Stack Overflow用户

发布于 2021-01-17 06:23:15

我自己找到了一个解决方案!我使用了一个技巧--我使用了一个循环,并且使用了四个而不是三个--最后你只能看到三个!

代码语言:javascript
复制
float yspeed = 1;
float circleY;
int d = 360;
void setup() {

  size(540, 810 );
  circleY = 0;
}

void draw() {
  background(255);
  fill(0);
  noStroke();
  //  fill(255,0,0);
  translate(0, - height/2);

  for (int i = 0; i< 5; i++) {    
    ellipse(width/2, circleY+height/2*i, d, d);
  }
  circleY = circleY + yspeed;  


  if (circleY > 405) {
    circleY= 0;
  }
}
票数 2
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65754784

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档