• processing bounce ball


    When the shape hits the edge of the window, it reverses its direction.

    int rad = 60;        // Width of the shape
    float xpos, ypos;    // Starting position of shape    
    
    float xspeed = 2.8;  // Speed of the shape
    float yspeed = 2.2;  // Speed of the shape
    
    int xdirection = 1;  // Left or Right
    int ydirection = 1;  // Top to Bottom
    
    
    void setup() 
    {
      size(640, 360);
      noStroke();
      frameRate(30);
      ellipseMode(RADIUS);
      // Set the starting position of the shape
      xpos = width/2;
      ypos = height/2;
    }
    
    void draw() 
    {
      background(102);
      
      // Update the position of the shape
      xpos = xpos + ( xspeed * xdirection );
      ypos = ypos + ( yspeed * ydirection );
      
      // Test to see if the shape exceeds the boundaries of the screen
      // If it does, reverse its direction by multiplying by -1
      if (xpos > width-rad || xpos < rad) {
        xdirection *= -1;
      }
      if (ypos > height-rad || ypos < rad) {
        ydirection *= -1;
      }
    
      // Draw the shape
      ellipse(xpos, ypos, rad, rad);
    }

    该运动时匀速直线运动。

  • 相关阅读:
    CAS简介
    Volatile的3大特性
    dsf对矩阵进行搜索
    JVM
    REST风格
    自定义Starters(自动配置Bean)
    反射和注解的原理
    mybatis的注解开发
    Java的多线程安全
    mybatis(3)
  • 原文地址:https://www.cnblogs.com/youxin/p/2996391.html
Copyright © 2020-2023  润新知