25
Paper.js 江江江 a nice vector graphics library

Paperjs presentation

Embed Size (px)

Citation preview

Page 1: Paperjs presentation

Paper.js

江嘉诚

a nice vector graphics library

Page 2: Paperjs presentation

PaperScript• <head>• <script type="text/javascript" src="js/paper.js">• </script>• <script type="text/paperscript" canvas=“canvas"> …………..• </script>• </head>• <body>• <canvas id=“canvas" resize></canvas>• </body>

Page 3: Paperjs presentation

基本概念

• Point• Size • Rectangle

• 多种构造函数• 大量的语法糖• 便捷的数学运算• 运算符重载

Page 4: Paperjs presentation

基本概念

• var point = new Point(20, 40);• console.log(point); // { x: 20, y: 40 }

• var size = new Size();• console.log(size); // { width: 0, height: 0 }

• var rect = new Rectangle(point, size);• console.log(rect); • // { x: 10, y: 20, width: 200, height: 100 }

Page 5: Paperjs presentation

基本概念

• var point1 = new Point(10, 20);• var point2 = point1 * 4;• var point3 = point2 - point1;• var point4 = point3 + 30;• var point6 = point5 * new Point(3, 2);

• vector.angle += 90;

• Point.random();

Page 6: Paperjs presentation

Vector

Page 7: Paperjs presentation

Vector

Page 8: Paperjs presentation

Path

Page 9: Paperjs presentation

Path

• var path = new Path();• path.strokeColor = 'black';• path.add(new Point(30, 75)); • path.add(new Point(30, 25)); • path.add(new Point(80, 25));• path.add(new Point(80, 75));• path.closed = true;

Page 10: Paperjs presentation

Path

• path.fullySelected = true;

• var copy = path.clone();• copy.fullySelected = true;• copy.position.x += 100;

• copy.smooth();

Page 11: Paperjs presentation

Path

• var myCircle = new Path.Circle(new Point(100, 70), 50);

• myCircle.strokeColor = 'black';• myCircle.selected = true;

Page 12: Paperjs presentation

Path

Page 13: Paperjs presentation

Path

• var myCircle = new Path.Circle(new Point(100, 70), 50);• myCircle.strokeColor = 'black';• myCircle.selected = true;

• myCircle.removeSegment(0);

Page 14: Paperjs presentation

Path

Page 15: Paperjs presentation

Path

Page 16: Paperjs presentation

Event

• function onMouseDown(event) {• // event.point• }

• function onMouseDrag(event) { }

• function onMouseUp(event) { }

• function onMouseMove(event) { }

• function onFrame(event) {

Page 17: Paperjs presentation

Event

• tool.minDistance = 10;• tool.maxDistance = 10;• tool.fixedDistance = 10;

Page 18: Paperjs presentation

Event

• event.point• event.middlePoint• event.delta

Page 19: Paperjs presentation

Item

Transform

Layer

Page 20: Paperjs presentation

Layer

Group

Project

Page 21: Paperjs presentation

Bound

Page 22: Paperjs presentation

Symbol

Page 23: Paperjs presentation

Raster

• var circle = new Path.Circle(new Point(80, 50), 5);• circle.fillColor = 'red';

• var raster = circle.rasterize();

Page 24: Paperjs presentation

CompoundPath

PointText

HitTest

Style

Page 25: Paperjs presentation

Paper.js的优点

• 简单而清晰的概念• 大量的语法糖• 倡导基于矢量绘图• 统一使用 Path• 引人入胜的例子• Processing的有力竞争者