Skip to content

Commit

Permalink
Update 12/01/2014 (Version 0.8.3)
Browse files Browse the repository at this point in the history
* Tagging version 0.8.3
  • Loading branch information
Venerons committed Jan 12, 2014
0 parents commit 25c64f3
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.DS_Store
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Palette.js Changelog

_Copyright (c) 2013-2014 Daniele Veneroni._
_Released under MIT License. See [LICENSE.md](LICENSE.md) for further information._

### Update 12/01/2014 (Version 0.8.3)

* Tagging version 0.8.3
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2013-2014 Daniele Veneroni

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Palette.js

_Copyright (c) 2013-2014 Daniele Veneroni._
_Released under MIT License (X11 License). See [LICENSE.md](LICENSE.md) for further information._

Palette.js is a new full-standard HTML5 Canvas framework. With Palette.js you can easily create canvas graphics and animation in seconds!

## Usage

Just add the script to your HTML page to import Palette.js

```html
<script src="js/palette.min.js"></script>
```

Then use the Palette.js APIs to manipulate your canvas

```js
var paper = new Palette("myCanvas");
```

## Licensing

Palette.js is released under MIT License (X11 License). [Read the full license](LICENSE.md).

## Credits

Created and maintained by Daniele Veneroni ([@Venerons](http://twitter.com/Venerons)).
157 changes: 157 additions & 0 deletions palette.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// ┌───────────────────────────────────────────────────────────────────────┐
// │ Palette.js │
// ├───────────────────────────────────────────────────────────────────────┤
// │ Version 0.8.3 - 11/01/2014 │
// ├───────────────────────────────────────────────────────────────────────┤
// │ Copyright (c) 2013-2014 Daniele Veneroni (http://venerons.github.io) │
// ├───────────────────────────────────────────────────────────────────────┤
// │ Licensed under the MIT License (X11 License). │
// └───────────────────────────────────────────────────────────────────────┘

"use strict";

function Palette(canvas) {
this.canvas = document.getElementById(canvas);
this.context = this.canvas.getContext("2d");
}

// change canvas size (warning: this will clear the canvas!)
Palette.prototype.size = function (w, h) {
this.canvas.width = w;
this.canvas.height = h;
return this;
};

// set the color for future use
Palette.prototype.setColor = function (color) {
this.context.fillStyle = color || "#000000";
this.context.strokeStyle = color || "#000000";
return this;
};

// create and set a linear gradient
Palette.prototype.gradient = function (x1, y1, x2, y2, color1, color2) {
var gradient = this.context.createLinearGradient(x1, y1, x2, y2);
gradient.addColorStop(0, color1);
gradient.addColorStop(1, color2);
this.setColor(gradient);
return this;
};

// paint a filled rectangle (color is optional)
Palette.prototype.rect = function (x, y, w, h, color) {
if (color) { this.setColor(color); }
this.context.fillRect(x, y, w, h);
return this;
};

// paint a stroked rectangle (color is optional)
Palette.prototype.strokedRect = function (x, y, w, h, color) {
if (color) { this.setColor(color); }
this.context.strokeRect(x, y, w, h);
return this;
};

// clear a rectangular area
Palette.prototype.clear = function (x, y, w, h) {
this.context.clearRect(x, y, w, h);
return this;
};

// paint a line (color is optional)
Palette.prototype.line = function (x1, y1, x2, y2, join, w, color) {
if (color) { this.setColor(color); }
this.context.lineJoin = join || "miter"; // miter, round, bevel
this.context.lineWidth = w || 1;
this.context.beginPath();
this.context.moveTo(x1, y1);
this.context.lineTo(x2, y2);
this.context.closePath();
this.context.stroke();
return this;
};

// paint a filled circle (color is optional)
Palette.prototype.circle = function (x, y, r, color) {
if (color) { this.setColor(color); }
this.context.beginPath();
this.context.arc(x, y, r, 0, 2*Math.PI);
this.context.closePath();
this.context.fill();
return this;
};

// paint a stroked circle (color is optional)
Palette.prototype.strokedCircle = function (x, y, r, color) {
if (color) { this.setColor(color); }
this.context.beginPath();
this.context.arc(x, y, r, 0, 2*Math.PI);
this.context.closePath();
this.context.stroke();
return this;
};

// paint a filled arc (color is optional)
Palette.prototype.arc = function (x, y, r, start, stop, color) {
if (color) { this.setColor(color); }
this.context.beginPath();
this.context.arc(x, y, r, start, stop);
this.context.closePath();
this.context.fill();
return this;
};

// paint a stroked arc (color is optional)
Palette.prototype.strokedArc = function (x, y, r, start, stop, color) {
if (color) { this.setColor(color); }
this.context.beginPath();
this.context.arc(x, y, r, start, stop);
this.context.closePath();
this.context.stroke();
return this;
};

// paint a filled text (color is optional)
Palette.prototype.text = function (text, x, y, font, color) {
if (color) { this.setColor(color); }
this.context.font = font;
this.context.fillText(text, x, y);
return this;
};

// paint a stroked text (color is optional)
Palette.prototype.strokedText = function (text, x, y, font, color) {
if (color) { this.setColor(color); }
this.context.font = font;
this.context.strokeText(text, x, y);
return this;
};

// paint an image (width and height are optionals)
Palette.prototype.image = function (src, x, y, w, h) {
var ctx = this.context;
var image = new Image();
image.onload = function() {
if (w && h) {
ctx.drawImage(image, x, y, w, h);
} else {
ctx.drawImage(image, x, y);
}
};
image.src = src;
return this;
};

// requestAnimationFrame polyfill
window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;

// set an animation at a specified fps. fps is optional, if not specified default is 60fps
Palette.prototype.animation = function (animation, fps) {
var palette = this;
if (!fps) { fps = 60; }
setTimeout(function() {
animation();
window.requestAnimationFrame(palette.animation(animation, fps));
}, 1000 / fps);
//return this;
};

0 comments on commit 25c64f3

Please sign in to comment.