java - 改变落球速度...处理中

标签 java processing

这里是一个程序,在鼠标点击的任何地方都有一个球落下和反弹。谁知道如何改变球下落到重力的速度? 我试图找出正确的解决方案......但我遇到了一点麻烦。非常感谢所有帮助和/或输入。

  float x;
  float y;
  float yspeed = 0;
  float xspeed = 0;
  float balldiameter = 10;
  float ballradius = balldiameter/2;

  void setup() {
     size (400,400);
     background (255);
     fill (0);
     ellipseMode(CENTER);
     smooth();
     noStroke();
     x = width/2;
     y = height/2;
   }

   void draw() {
   mouseChecks();
   boundaryChecks();
   ballFunctions();
   keyFunctions();
   }

   void mouseChecks() {
      if (mousePressed == true) {
      x = mouseX;
      y = mouseY;
      yspeed = mouseY - pmouseY;
      xspeed = mouseX - pmouseX;
      }
    }

  void boundaryChecks() {
     if (y >= height - ballradius) {
     y = height - ballradius;
     yspeed = -yspeed/1.15;
   }
   if (y <= ballradius) {
   y = ballradius;
   yspeed = -yspeed/1.35;
   }
   if (x >= width -ballradius) {
     x = width -ballradius;
     xspeed = -xspeed/1.10;
   }
   if (x <= ballradius) {
     x = ballradius;
     xspeed = -xspeed/1.10;
     }
    }

 void ballFunctions() {
    if (balldiameter < 2) {
     balldiameter = 2;
    }
   if (balldiameter > 400) {
     balldiameter = 400;
    }
   ballradius = balldiameter/2;
   background(255); //should this be in here?
   ellipse (x,y,balldiameter,balldiameter);
   yspeed = yspeed += 0.2;
   xspeed = xspeed/1.005;
   y = y + yspeed;
   x = x + xspeed;
  }
 void keyFunctions() {
    if (keyPressed) {
    if(keyCode == UP) {
    balldiameter +=1;
   }
  if (keyCode == DOWN) {
   balldiameter -=1;
   }
  }
 }

最佳答案

地球上的重力加速度为 9.81 m/s^2。因此,如果在单击鼠标时球的速度为 0,则最终速度将是与时间相关的加速度积分。这将是 (9.81 * t)/2。其中 t 以秒为单位。结果单位为米/秒。您必须将米转换为一些屏幕空间单位才能进行绘图。

关于java - 改变落球速度...处理中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13205534/

相关文章:

java - 内部 http :inbound-gateway with pollable request channel

java - 比较 n 个对象的多个字段的共同值

javascript - 在processing中编写与在processing.js中编写javascript

function - 如何创建一个为该语言添加新函数的处理库?

java - 如何过滤FFT数据(用于音频可视化)?

java - 中间键值对流是否在 hadoop 中优化

java - 如何使用Log4j为jsp页面创建日志文件

java - 为什么常量池的索引在类文件格式中占用不同数量的字节

java - "Security settings have blocked a self-signed application from running"作为开发者

发送单个值的Arduino按钮问题