Paper.js
a nice vector graphics library


    江嘉诚
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>
基本概念
• Point
• Size
• Rectangle

•   多种构造函数
•   大量的语法糖
•   便捷的数学运算
•   运算符重载
基本概念
• 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 }
基本概念
•   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();
Vector
Vector
Path
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;
Path

• path.fullySelected = true;

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

• copy.smooth();
Path

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

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

• myCircle.removeSegment(0);
Path
Path
Event
• function onMouseDown(event) {
•   // event.point
• }

• function onMouseDrag(event) { }

• function onMouseUp(event) { }

• function onMouseMove(event) { }

• function onFrame(event) {
Event
• tool.minDistance = 10;
• tool.maxDistance = 10;
• tool.fixedDistance = 10;
Event
• event.point
• event.middlePoint
• event.delta
Item

Transform

 Layer
Project

Layer

Group
Bound
Symbol
Raster

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

• var raster = circle.rasterize();
HitTest

            CompoundPath

PointText

               Style
Paper.js的优点

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

More Related Content

PPTX
Paperjs presentation
KEY
【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽
PPTX
MongoDB
PPT
Raphael JavaScript Library
PDF
Shibuya.js Lightning Talks
PDF
玉転がしゲームで学ぶUnity入門
PDF
An Introduction to Tinkerpop
KEY
PostgreSQLからMongoDBへ
Paperjs presentation
【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽
MongoDB
Raphael JavaScript Library
Shibuya.js Lightning Talks
玉転がしゲームで学ぶUnity入門
An Introduction to Tinkerpop
PostgreSQLからMongoDBへ

What's hot (20)

PPTX
jQuery Foot-Gun Features
PDF
Empowering End-users to Find Point-of-interests with a Public Display
DOCX
PPTX
Testing Black Box
PPTX
D3.js - A picture is worth a thousand words
PPT
C questions
PDF
Webgl para JavaScripters
PDF
You will learn RxJS in 2017
PDF
Angular.js + Rails at WeWork or: The Accidental Feature
PDF
Web Components With Rails
PPTX
PDF
Dion Almaer & Ben Galbraith - Build Once, Deploy Everywhere
PDF
Exploring Canvas
PDF
Implementation of c string functions
PDF
In a galaxy far, far away - A procedural generation tale
PPTX
Pointer level 2
TXT
jQuery Foot-Gun Features
Empowering End-users to Find Point-of-interests with a Public Display
Testing Black Box
D3.js - A picture is worth a thousand words
C questions
Webgl para JavaScripters
You will learn RxJS in 2017
Angular.js + Rails at WeWork or: The Accidental Feature
Web Components With Rails
Dion Almaer & Ben Galbraith - Build Once, Deploy Everywhere
Exploring Canvas
Implementation of c string functions
In a galaxy far, far away - A procedural generation tale
Pointer level 2
Ad

Recently uploaded (20)

PDF
CloudStack 4.21: First Look Webinar slides
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
August Patch Tuesday
PDF
Five Habits of High-Impact Board Members
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Hybrid model detection and classification of lung cancer
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
Modernising the Digital Integration Hub
PDF
Getting Started with Data Integration: FME Form 101
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
The various Industrial Revolutions .pptx
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
CloudStack 4.21: First Look Webinar slides
Enhancing emotion recognition model for a student engagement use case through...
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
WOOl fibre morphology and structure.pdf for textiles
A comparative study of natural language inference in Swahili using monolingua...
August Patch Tuesday
Five Habits of High-Impact Board Members
A contest of sentiment analysis: k-nearest neighbor versus neural network
1 - Historical Antecedents, Social Consideration.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Hybrid model detection and classification of lung cancer
NewMind AI Weekly Chronicles – August ’25 Week III
A novel scalable deep ensemble learning framework for big data classification...
Assigned Numbers - 2025 - Bluetooth® Document
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Modernising the Digital Integration Hub
Getting Started with Data Integration: FME Form 101
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
The various Industrial Revolutions .pptx
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Ad

Paperjs presentation

  • 1. Paper.js a nice vector graphics library 江嘉诚
  • 2. 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>
  • 3. 基本概念 • Point • Size • Rectangle • 多种构造函数 • 大量的语法糖 • 便捷的数学运算 • 运算符重载
  • 4. 基本概念 • 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 }
  • 5. 基本概念 • 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();
  • 9. 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;
  • 10. Path • path.fullySelected = true; • var copy = path.clone(); • copy.fullySelected = true; • copy.position.x += 100; • copy.smooth();
  • 11. Path • var myCircle = new Path.Circle(new Point(100, 70), 50); • myCircle.strokeColor = 'black'; • myCircle.selected = true;
  • 12. Path
  • 13. Path • var myCircle = new Path.Circle(new Point(100, 70), 50); • myCircle.strokeColor = 'black'; • myCircle.selected = true; • myCircle.removeSegment(0);
  • 14. Path
  • 15. Path
  • 16. Event • function onMouseDown(event) { • // event.point • } • function onMouseDrag(event) { } • function onMouseUp(event) { } • function onMouseMove(event) { } • function onFrame(event) {
  • 17. Event • tool.minDistance = 10; • tool.maxDistance = 10; • tool.fixedDistance = 10;
  • 21. Bound
  • 23. Raster • var circle = new Path.Circle(new Point(80, 50), 5); • circle.fillColor = 'red'; • var raster = circle.rasterize();
  • 24. HitTest CompoundPath PointText Style
  • 25. Paper.js的优点 • 简单而清晰的概念 • 大量的语法糖 • 倡导基于矢量绘图 • 统一使用Path • 引人入胜的例子 • Processing的有力竞争者