|
|
@ -46,33 +46,72 @@ Download the minified js file in dist folder and include it in your html. |
|
|
|
Generate LeonSans and draw it in the Canvas element of HTML5. |
|
|
|
Generate LeonSans and draw it in the Canvas element of HTML5. |
|
|
|
```javascript |
|
|
|
```javascript |
|
|
|
|
|
|
|
|
|
|
|
this.canvas = document.createElement('canvas'); |
|
|
|
let leon, controll, canvas, ctx; |
|
|
|
document.body.appendChild(this.canvas); |
|
|
|
|
|
|
|
this.ctx = this.canvas.getContext("2d"); |
|
|
|
const sw = 800; |
|
|
|
|
|
|
|
const sh = 600; |
|
|
|
|
|
|
|
const pixelRatio = 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function init() { |
|
|
|
|
|
|
|
canvas = document.createElement('canvas'); |
|
|
|
|
|
|
|
document.body.appendChild(canvas); |
|
|
|
|
|
|
|
ctx = canvas.getContext("2d"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
canvas.width = sw * pixelRatio; |
|
|
|
|
|
|
|
canvas.height = sh * pixelRatio; |
|
|
|
|
|
|
|
canvas.style.width = sw + 'px'; |
|
|
|
|
|
|
|
canvas.style.height = sh + 'px'; |
|
|
|
|
|
|
|
ctx.scale(pixelRatio, pixelRatio); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
leon = new LeonSans({ |
|
|
|
|
|
|
|
text: 'The quick brown\nfox jumps over\nthe lazy dog', |
|
|
|
|
|
|
|
color: ['#000000'], |
|
|
|
|
|
|
|
size: 80, |
|
|
|
|
|
|
|
weight: 200 |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requestAnimationFrame(animate); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.leon = new LeonSans({ |
|
|
|
function animate(t) { |
|
|
|
text: 'The quick brown\nfox jumps over\nthe lazy dog', |
|
|
|
requestAnimationFrame(animate); |
|
|
|
color: ['#000000'], |
|
|
|
|
|
|
|
size: 160, |
|
|
|
|
|
|
|
weight: 200 |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requestAnimationFrame(animate); |
|
|
|
ctx.clearRect(0, 0, sw, sh); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const x = (sw - leon.rect.w) / 2; |
|
|
|
|
|
|
|
const y = (sh - leon.rect.h) / 2; |
|
|
|
|
|
|
|
leon.position(x, y); |
|
|
|
|
|
|
|
|
|
|
|
function animate(t) { |
|
|
|
leon.draw(ctx); |
|
|
|
requestAnimationFrame(animate); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.ctx.clearRect(0, 0, document.body.clientWidth, document.body.clientHeight); |
|
|
|
window.onload = () => { |
|
|
|
|
|
|
|
init(); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
const x = (document.body.clientWidth - this.leon.rect.w) / 2; |
|
|
|
For the drawing animation, include TweenMax (JS animation library) in your html. |
|
|
|
const y = (document.body.clientHeight - this.leon.rect.h) / 2; |
|
|
|
```html |
|
|
|
this.leon.position(x, y); |
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.3/TweenMax.min.js"></script> |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
this.leon.draw(this.ctx); |
|
|
|
And update all the drawing valuse from 0 to 1 |
|
|
|
|
|
|
|
```javascript |
|
|
|
|
|
|
|
let i, total = leon.drawing.length; |
|
|
|
|
|
|
|
for (i = 0; i < total; i++) { |
|
|
|
|
|
|
|
TweenMax.fromTo(leon.drawing[i], 1.6, { |
|
|
|
|
|
|
|
value: 0 |
|
|
|
|
|
|
|
}, { |
|
|
|
|
|
|
|
delay: i * 0.05, |
|
|
|
|
|
|
|
value: 1, |
|
|
|
|
|
|
|
ease: Power4.easeOut |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Option list |
|
|
|
### Option list |
|
|
|
|
|
|
|
|
|
|
|
| Name | Type | Description | |
|
|
|
| Name | Type | Description | |
|
|
|