Browse Source

Update README.md

pull/3/head
Jongmin Kim 5 years ago committed by GitHub
parent
commit
abec540f09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 69
      README.md

69
README.md

@ -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");
this.leon = new LeonSans({ const sw = 800;
text: 'The quick brown\nfox jumps over\nthe lazy dog', const sh = 600;
color: ['#000000'], const pixelRatio = 2;
size: 160,
weight: 200
});
requestAnimationFrame(animate); 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);
}
function animate(t) { function animate(t) {
requestAnimationFrame(animate); requestAnimationFrame(animate);
this.ctx.clearRect(0, 0, document.body.clientWidth, document.body.clientHeight); ctx.clearRect(0, 0, sw, sh);
const x = (document.body.clientWidth - this.leon.rect.w) / 2; const x = (sw - leon.rect.w) / 2;
const y = (document.body.clientHeight - this.leon.rect.h) / 2; const y = (sh - leon.rect.h) / 2;
this.leon.position(x, y); leon.position(x, y);
this.leon.draw(this.ctx); leon.draw(ctx);
} }
window.onload = () => {
init();
};
``` ```
For the drawing animation, include TweenMax (JS animation library) in your html.
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.3/TweenMax.min.js"></script>
```
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 |

Loading…
Cancel
Save