0
我開始使用paper.js,並在添加和定位新點時遇到一些問題。我想在左下角和右下角添加2個新點,以獲得更多高度。現在我玩了演示代碼,我有這個:(見下圖)我想用它作爲移動的背景。
1.我如何增加2點以增加空間和高度?
2.當我達到此目的時,我如何控制它使其響應(平板電腦,手機等)?
這是example code working。Paper.js爲更高的高度添加2個角點
<script type="text/paperscript" canvas="myCanvas">
var width, height, center;
var points = 4;
var smooth = true;
var path = new Path();
var mousePos = view.center/2;
var pathHeight = mousePos.y;
var topLeft = view.center - [80, 80];
var bottomRight = view.center + [80, 80];
path.fillColor = {
gradient: {
stops: ['#532e8e', '#662e8f']
},
origin: topLeft,
destination: bottomRight
}
initializePath();
function initializePath() {
center = view.center;
width = view.size.width;
height = view.size.height/4;
path.segments = [];
path.add(view.bounds.bottomLeft);
for (var i = 1; i < points; i++) {
var point = new Point(width/points * i, center.y);
path.add(point);
}
path.add(view.bounds.bottomRight);
// path.fullySelected = true;
console.log(path.segments);
}
function onFrame(event) {
pathHeight += (center.y - mousePos.y - pathHeight)/2;
for (var i = 1; i < points; i++) {
var sinSeed = event.count + (i + i % 10) * 100 /2;
var sinHeight = Math.sin(sinSeed/200) * pathHeight /2;
var yPos = Math.sin(sinSeed/100) * sinHeight + height/1;
path.segments[i].point.y = yPos;
}
if (smooth)
path.smooth({ type: 'continuous' });
}
// Reposition the path whenever the window is resized:
function onResize(event) {
initializePath();
}
</script>
好吧,我做了soem改變,我越來越接近。現在,我如何使矢量不觸及畫布的邊緣?繼承人的代碼:https://codepen.io/G-ROS/pen/yXwzBE –