如何从一个X动画,y坐标到另一个? (Jav​​a /处理) [英] How to animate from one x,y coordinate to another? (Java/Processing)

查看:274
本文介绍了如何从一个X动画,y坐标到另一个? (Jav​​a /处理)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在制作工艺简单的动画。我想从它的起点动画图像,以在屏幕上限定的x,y值。

I am making a simple animation in Processing. I want to animate an image from its starting point to a defined x,y value on the screen.

我有2个方法,更新()画(),这是每一个刻度运行。 更新()是code会去处理x / y坐标,提供给画()上的下一个刻度方法。

I have 2 methods, update() and draw(), which are run on every tick. update() is where the code will go to process the x/y coordinates to provide to the draw() method on the next tick.

画()方法,那么绘制图像,传递更新的X和Y值。

The draw() method then draws the image, passing in the updated x and y values.

小例子:

class ScrollingNote {
  float x;
  float y;
  float destX;
  float destY;
  PImage noteImg;

  ScrollingNote(){
    noteImg = loadImage("image-name.png");
    this.x = width/2;
    this.y = 100;
    this.destX = 100;
    this.destY = height;
  }

  void update(){
    // TODO: adjust this.x and this.y 
    // to draw the image slightly closer to
    // this.destX and this.destY on the redraw
    // ie in this example we are animating from x,y to destX, destY
  }

  void draw(){
    image( noteImg, this.x, this.y );
  }
}

我是否需要做出调整x / y坐标是什么样的计算,使图像绘制稍微接近目标?

What sort of calculation do I need to make to adjust the x/y coordinates to make the image draw slightly closer to the destination?

推荐答案

如果您使用的是处理2.0 这可以通过阿尼库来完成。要获得相同的输出像@MadProgrammer你刚才设置基本的素描与 Ani.init(本)然后在画()通过函数移动框翻译()并通过旋转旋转()功能。之后的第一个鼠标点击整个动画开始。

If you are using Processing 2.0 this can be done via Ani library. To get same output like @MadProgrammer you just setup basic sketch with Ani.init(this) then in draw() function move box via translate() and rotate it via rotate() functions. Whole animation begins after first mouse click.

import de.looksgood.ani.*;
import de.looksgood.ani.easing.*;

float posX = 25, posY = 25;
float angleRotation = 0;

void setup () {
 size (200, 200);
 background (99);  
 noFill ();
 stroke (0);
 Ani.init(this);
 frameRate (30);
 rectMode(CENTER); 
}

void draw () {
  background (225);  
  translate(posX, posY);
  rotate(radians(angleRotation));
  rect(0, 0, 50, 50);    
}

void mousePressed() {
  Ani.to(this, 5, "posX", 175, Ani.LINEAR);
  Ani.to(this, 5, "posY", 175, Ani.LINEAR);
  Ani.to(this, 5, "angleRotation", 360, Ani.LINEAR);
}

手动你可以仅仅通过增加 POSX POSY angleRotation <得到类似的结果/ code>平局循环中。

Manually you can get similar result just by increasing posX, posY and angleRotation within draw loop.

这篇关于如何从一个X动画,y坐标到另一个? (Jav​​a /处理)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆