Git Product home page Git Product logo

Comments (3)

zmcode avatar zmcode commented on July 20, 2024

这个只能通过改变group的matrix来实现的
const group = item.getContainer(); group.animate( { matrix: [ 1, 0, 0, 0, 1, 0, 180, 30, 1 ] }, { duration: 1000, }, ); }

from g6.

longsfreedom avatar longsfreedom commented on July 20, 2024
image.animate(
  (ratio) => {
    每一帧的操作,入参 ratio:这一帧的比例值(Number)返回值:这一帧需要变化的参数集(Object)
    const toMatrix = Util.transform(
      [1, 0, 0, 0, 1, 0, 0, 0, 1],// 当前矩阵
      [['t', 0, 0], // 平移到左上角]
    );
    return {
      matrix: toMatrix,
    };
  },
  {
    repeat: true,
    duration: 3000,
    easing: 'easeCubic',
  },
);
g6的transform本质上也是转化成矩阵形式:
matrix = transform(matrix, [
      ['t', minX, minY], // 平移到左上角
      ['s', ratio, ratio], // 缩放到正好撑着 minimap
      ['t', dx, dy], // 移动到画布中心
    ]);
t代表translate平移
s代表scale缩放
r代表rotate旋转

源码中的transform
/**
 * 根据 actions 来做 transform
 * @param m
 * @param actions
 */
export function transform(m: number[], actions: any[][]) {
  const matrix = m ? [].concat(m) : [1, 0, 0, 0, 1, 0, 0, 0, 1];


  for (let i = 0, len = actions.length; i < len; i++) {
    const action = actions[i];
    switch (action[0]) {
      case 't':
        leftTranslate(matrix, matrix, [action[1], action[2]]);
        break;
      case 's':
        leftScale(matrix, matrix, [action[1], action[2]]);
        break;
      case 'r':
        leftRotate(matrix, matrix, action[1]);
        break;
      case 'm':
        leftMultiply(matrix, matrix, action[1]);
        break;
      default:
        break;
    }
  }


  return matrix;
}
如s代表的缩放:
export function fromScaling(out, v) {
  out[0] = v[0];
  out[1] = 0;
  out[2] = 0;


  out[3] = 0;
  out[4] = v[1];
  out[5] = 0;


  out[6] = 0;
  out[7] = 0;
  out[8] = 1;
  return out;
}

from g6.

zmcode avatar zmcode commented on July 20, 2024

from g6.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.