第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Paper.js - 如何設(shè)置繪制矢量或線段的持續(xù)時(shí)間?

Paper.js - 如何設(shè)置繪制矢量或線段的持續(xù)時(shí)間?

繁花不似錦 2023-08-18 17:39:14
我需要設(shè)置與某些路線相關(guān)的向量(或線段),在一定時(shí)間內(nèi)從A點(diǎn)開(kāi)始到B點(diǎn)結(jié)束。比如說(shuō)一次旅行。不幸的是,我找不到如何設(shè)置傳遞值的繪圖時(shí)間:<script src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.12.7/paper-core.js"></script>var point1 = new Point(0, 0);var point2 = new Point(110, 200);var x = point2.x - point1.x;// = 110 - 50 = 60var y = point2.y - point1.y;// = 200 - 50 = 150;var vector = point2 - point1;// Create a Paper.js Path to draw a line into it:var path = new Path();// Give the stroke a colorpath.strokeColor = 'red';var start = vector;function onFrame(event) {    if (event.count < 101) {        path.add(start);        start += new Point(1, 1);    }}
查看完整描述

1 回答

?
眼眸繁星

TA貢獻(xiàn)1873條經(jīng)驗(yàn) 獲得超9個(gè)贊

如果我很好地理解你的情況,這里有一個(gè)演示可能實(shí)現(xiàn)的草圖。

這個(gè)想法是保留一個(gè)參考路徑,我們根據(jù)該參考路徑計(jì)算每個(gè)幀的臨時(shí)路徑,以生成動(dòng)畫(huà)。

該解決方案的優(yōu)點(diǎn)是您可以將其應(yīng)用于任何類型的路徑。


// Create a path to animate.

const path = new Path.Circle({

? ? center: view.center,

? ? radius: 50,

? ? selected: true,

? ? closed: false

});


// Initialize the time variable that will control the animation.

let time = 0;


// On each frame...

function onFrame() {

? ? // ...if the animation is not finished yet...

? ? if (time <= 1) {

? ? ? ? // ...animate.

? ? ? ? time += 0.01;

? ? ? ? drawTmpPath(time);

? ? }

}


// Initialize the temporary path that will display our animation.

let tmpPath;


function drawTmpPath(t) {

? ? // Make sure that t is never over 1.

? ? t = Math.min(t, 1);

? ? // Remove the previously drawn temporary path.

? ? if (tmpPath) {

? ? ? ? tmpPath.remove();

? ? }

? ? // Draw the new temporary path from the reference one.

? ? tmpPath = path.clone().set({

? ? ? ? selected: false,

? ? ? ? strokeColor: 'orange',

? ? ? ? strokeWidth: 5

? ? });

? ? // Split it at the appropriate location.

? ? const remainingPath = tmpPath.splitAt(tmpPath.length * t);

? ? // Remove the eventual remaining part.

? ? if (remainingPath) {

? ? ? ? remainingPath.remove();

? ? }

}


// Scale things up.

project.activeLayer.fitBounds(view.bounds.scale(0.8));

編輯

為了回答您的評(píng)論,為了控制動(dòng)畫(huà)時(shí)間,您可以存儲(chǔ)動(dòng)畫(huà)開(kāi)始時(shí)間,并在每一幀上計(jì)算更新函數(shù)從當(dāng)前時(shí)間開(kāi)始所需的相對(duì)時(shí)間。
請(qǐng)注意,您還可以依賴GreenSock等外部動(dòng)畫(huà)庫(kù)來(lái)更輕松地處理計(jì)時(shí)。

// Total animation time in milliseconds.

const totalTime = 10000;


// Create a path to animate.

const path = new Path.Circle({

? ? center: view.center,

? ? radius: 50,

? ? selected: true,

? ? closed: false

});


// Initialize the time variable that will control the animation.

const startTime = Date.now();

let animationDone = false;


// On each frame...

function onFrame() {

? ? // ...if the animation is not finished yet...

? ? if (!animationDone) {

? ? ? ? // ...calculate the relative time needed to draw the tmp path.

? ? ? ? const relativeTime = (Date.now() - startTime) / totalTime;

? ? ? ? // ...animate.

? ? ? ? if (relativeTime < 1) {

? ? ? ? ? ? drawTmpPath(relativeTime);

? ? ? ? } else {

? ? ? ? ? ? drawTmpPath(1);

? ? ? ? ? ? animationDone = true;

? ? ? ? }

? ? }

}


// Initialize the temporary path that will display our animation.

let tmpPath;


function drawTmpPath(t) {

? ? // Make sure that t is never over 1.

? ? t = Math.min(t, 1);

? ? // Remove the previously drawn temporary path.

? ? if (tmpPath) {

? ? ? ? tmpPath.remove();

? ? }

? ? // Draw the new temporary path from the reference one.

? ? tmpPath = path.clone().set({

? ? ? ? selected: false,

? ? ? ? strokeColor: 'orange',

? ? ? ? strokeWidth: 5

? ? });

? ? // Split it at the appropriate location.

? ? const remainingPath = tmpPath.splitAt(tmpPath.length * t);

? ? // Remove the eventual remaining part.

? ? if (remainingPath) {

? ? ? ? remainingPath.remove();

? ? }

}


// Scale things up.

project.activeLayer.fitBounds(view.bounds.scale(0.8));


查看完整回答
反對(duì) 回復(fù) 2023-08-18
  • 1 回答
  • 0 關(guān)注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)