Download presentation
Presentation is loading. Please wait.
Published byBeatrice Floyd Modified over 8 years ago
1
Doing the Canvas the "easy way"! Learning & Development http://academy.telerik.com Telerik Software Academy
2
KineticJS overview and setup Working with KineticJS Initializing canvas Drawing shapes Rects, circles, paths, blobs Event handlers Attaching click, drag&drop
3
Overview and Setup
4
KineticJS is a JavaScript framework to work with the Canvas Introduces a refined API for canvas functionality Has stages and layers for better canvas performance
5
To use KineticJS: Download the kinetic.js framework from the site At http://kineticjs.com/ http://kineticjs.com/ Include the framework into your HTML page: Create a div with ID, where you want the canvas to be initialized:
6
To use KineticJS (cont.): Do the following in the script var stage = new Kinetic.Stage({ container: 'canvas-container', container: 'canvas-container', width: 450, width: 450, height: 350 height: 350}); var layer = new Kinetic.Layer(); var rect = new Kinetic.Rect(options); var circle = new Kinetic.Circle(options); layer.add (rect); layer.add (circle); stage.add(layer);
7
To use KineticJS (cont.): Do the following in the script var stage = new Kinetic.Stage({ container: 'canvas-container', container: 'canvas-container', width: 450, width: 450, height: 350 height: 350}); var layer = new Kinetic.Layer(); var rect = new Kinetic.Rect(options); var circle = new Kinetic.Circle(options); layer.add (rect); layer.add (circle); stage.add(layer); Create a stage using the div id
8
To use KineticJS (cont.): Do the following in the script var stage = new Kinetic.Stage({ container: 'canvas-container', container: 'canvas-container', width: 450, width: 450, height: 350 height: 350}); var layer = new Kinetic.Layer(); var rect = new Kinetic.Rect(options); var circle = new Kinetic.Circle(options); layer.add (rect); layer.add (circle); stage.add(layer); Create a stage using the div id Create a layer to add shapes
9
To use KineticJS (cont.): Do the following in the script var stage = new Kinetic.Stage({ container: 'canvas-container', container: 'canvas-container', width: 450, width: 450, height: 350 height: 350}); var layer = new Kinetic.Layer(); var rect = new Kinetic.Rect(options); var circle = new Kinetic.Circle(options); layer.add (rect); layer.add (circle); stage.add(layer); Create a stage using the div id Create a layer to add shapes Create shapes
10
Add the shapes to the layer To use KineticJS (cont.): Do the following in the script var stage = new Kinetic.Stage({ container: 'canvas-container', container: 'canvas-container', width: 450, width: 450, height: 350 height: 350}); var layer = new Kinetic.Layer(); var rect = new Kinetic.Rect(options); var circle = new Kinetic.Circle(options); layer.add (rect); layer.add (circle); stage.add(layer); Create a stage using the div id Create a layer to add shapes Create shapes Add the shapes to the layer
11
To use KineticJS (cont.): Do the following in the script var stage = new Kinetic.Stage({ container: 'canvas-container', container: 'canvas-container', width: 450, width: 450, height: 350 height: 350}); var layer = new Kinetic.Layer(); var rect = new Kinetic.Rect(options); var circle = new Kinetic.Circle(options); layer.add (rect); layer.add (circle); stage.add(layer); Create a stage using the div id Create a layer to add shapes Create shapes Add the layer to the stage Create shapes Add the shapes to the layer
12
Live Demo
14
KineticJS has all the default shapes from Canvas, and some more: Rectangular rect = new Kinetic.Rect({ fill: 'yellowgreen', fill: 'yellowgreen', stroke: '#CCCCCC', stroke: '#CCCCCC', x: 250, x: 250, y: 350, y: 350, width: 57, width: 57, height: 93 height: 93}); circle = new Kinetic.Circle({ radius: 45, radius: 45, fill: 'purple', fill: 'purple', stroke: 'blue', stroke: 'blue', strokeWidth: 3, strokeWidth: 3, x: 450, x: 450, y: 350, y: 350,}); Circle
15
KineticJS has all the default shapes from Canvas, and some more: Rectangular rect = new Kinetic.Rect({ fill: 'yellowgreen', fill: 'yellowgreen', stroke: '#CCCCCC', stroke: '#CCCCCC', x: 250, x: 250, y: 350, y: 350, width: 57, width: 57, height: 93 height: 93}); circle = new Kinetic.Circle({ radius: 45, radius: 45, fill: 'purple', fill: 'purple', stroke: 'blue', stroke: 'blue', strokeWidth: 3, strokeWidth: 3, x: 450, x: 450, y: 350, y: 350,}); Circle
16
KineticJS has all the default shapes from Canvas, and some more: Straight line Curved line straight = new Kinetic.Line({ points: [x1, y1, x2, y2], points: [x1, y1, x2, y2], stroke: 'green', stroke: 'green', strokeWidth: 2, strokeWidth: 2, lineJoin: 'round' lineJoin: 'round'}); curved = new Kinetic.Line({ points: [x1, y1, x2, y2], points: [x1, y1, x2, y2], stroke: 'green', stroke: 'green', strokeWidth: 2, strokeWidth: 2, tension: 1 tension: 1});
17
KineticJS has all the default shapes from Canvas, and some more: Straight line Curved line straight = new Kinetic.Line({ points: [x1, y1, x2, y2], points: [x1, y1, x2, y2], stroke: 'green', stroke: 'green', strokeWidth: 2, strokeWidth: 2, lineJoin: 'round' lineJoin: 'round'}); curved = new Kinetic.Line({ points: [x1, y1, x2, y2], points: [x1, y1, x2, y2], stroke: 'green', stroke: 'green', strokeWidth: 2, strokeWidth: 2, tension: 1 tension: 1});
18
KineticJS has all the default shapes from Canvas, and some more: Polygon Blob polygon = new Kinetic.Line({ points: [ … ] points: [ … ] stroke: 'green', stroke: 'green', fill: 'yellowgreen' fill: 'yellowgreen' strokeWidth: 2, strokeWidth: 2, closed: true closed: true}); blob = new Kinetic.Line({ points: [ … ], points: [ … ], stroke: 'green', stroke: 'green', fill: 'purple', fill: 'purple', closed: true, closed: true, tension: 0.5 tension: 0.5});
19
KineticJS has all the default shapes from Canvas, and some more: Polygon Blob polygon = new Kinetic.Line({ points: [ … ] points: [ … ] stroke: 'green', stroke: 'green', fill: 'yellowgreen' fill: 'yellowgreen' strokeWidth: 2, strokeWidth: 2, closed: true closed: true}); blob = new Kinetic.Line({ points: [ … ], points: [ … ], stroke: 'green', stroke: 'green', fill: 'purple', fill: 'purple', closed: true, closed: true, tension: 0.5 tension: 0.5});
20
Live Demo
21
форум програмиране, форум уеб дизайн курсове и уроци по програмиране, уеб дизайн – безплатно програмиране за деца – безплатни курсове и уроци безплатен SEO курс - оптимизация за търсачки уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop уроци по програмиране и уеб дизайн за ученици ASP.NET MVC курс – HTML, SQL, C#,.NET, ASP.NET MVC безплатен курс "Разработка на софтуер в cloud среда" BG Coder - онлайн състезателна система - online judge курсове и уроци по програмиране, книги – безплатно от Наков безплатен курс "Качествен програмен код" алго академия – състезателно програмиране, състезания ASP.NET курс - уеб програмиране, бази данни, C#,.NET, ASP.NET курсове и уроци по програмиране – Телерик академия курс мобилни приложения с iPhone, Android, WP7, PhoneGap free C# book, безплатна книга C#, книга Java, книга C# Николай Костов - блог за програмиране http://academy.telerik.com
22
1. Read the tutorial on KineticJS: At http://www.html5canvastutorials.com/kineticjs/html5- canvas-events-tutorials-introduction-with-kineticjs/ http://www.html5canvastutorials.com/kineticjs/html5- canvas-events-tutorials-introduction-with-kineticjs/http://www.html5canvastutorials.com/kineticjs/html5- canvas-events-tutorials-introduction-with-kineticjs/ Read about custom shapes and text 2. Using Kinetic create a family tree var familyMembers = [{ mother: 'Maria Petrova', mother: 'Maria Petrova', father: 'Georgi Petrov', father: 'Georgi Petrov', children: ['Teodora Petrova', 'Peter Petrov'] children: ['Teodora Petrova', 'Peter Petrov'] }, { mother: 'Petra Stamatova', mother: 'Petra Stamatova', father: Todor Stamatov', father: Todor Stamatov', children: ['Maria Petrova'] children: ['Maria Petrova']}]
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.