Skip to content

Commit

Permalink
v-0.9.6 axes colors param
Browse files Browse the repository at this point in the history
  • Loading branch information
nakednous committed May 7, 2024
1 parent 8e9b906 commit 39fbbf2
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions p5.treegl.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
var Tree = (function (ext) {
const INFO = {
LIBRARY: 'p5.treegl',
VERSION: '0.9.5',
VERSION: '0.9.6',
HOMEPAGE: 'https://github.com/VisualComputing/p5.treegl'
};
Object.freeze(INFO);
Expand Down Expand Up @@ -1550,46 +1550,50 @@ void main() {
* @param {Number} bits bitwise mask that may be composed of Tree.X, Tree._X,
* Tree.Y, Tree._Y, Tree.Z, Tree._Z and Tree.LABELS bits.
*/
p5.RendererGL.prototype.axes = function ({ size = 100, bits = Tree.LABELS | Tree.X | Tree.Y | Tree.Z } = {}) {
p5.RendererGL.prototype.axes = function ({
size = 100,
colors = ['Red', 'Lime', 'DodgerBlue'],
bits = Tree.LABELS | Tree.X | Tree.Y | Tree.Z
} = {}) {
this._rendererState = this.push();
if ((bits & Tree.LABELS) !== 0) {
const charWidth = size / 40.0;
const charHeight = size / 30.0;
const charShift = 1.04 * size;
// The X
this.stroke(200, 0, 0);
this.stroke(colors[0 % colors.length]);
this.line(charShift, charWidth, -charHeight, charShift, -charWidth, charHeight);
this.line(charShift, -charWidth, -charHeight, charShift, charWidth, charHeight);
// The Y
this.stroke(0, 200, 0);
this.stroke(colors[1 % colors.length]);
this.line(charWidth, charShift, charHeight, 0.0, charShift, 0.0);
this.line(0.0, charShift, 0.0, -charWidth, charShift, charHeight);
this.line(-charWidth, charShift, charHeight, 0.0, charShift, 0.0);
this.line(0.0, charShift, 0.0, 0.0, charShift, -charHeight);
// The Z
this.stroke(0, 100, 200);
this.stroke(colors[2 % colors.length]);
this.line(-charWidth, -charHeight, charShift, charWidth, -charHeight, charShift);
this.line(charWidth, -charHeight, charShift, -charWidth, charHeight, charShift);
this.line(-charWidth, charHeight, charShift, charWidth, charHeight, charShift);
}
// X Axis
this.stroke(200, 0, 0);
this.stroke(colors[0 % colors.length]);
if ((bits & Tree.X) !== 0) {
this.line(0, 0, 0, size, 0, 0);
}
if ((bits & Tree._X) !== 0) {
this.line(0, 0, 0, -size, 0, 0);
}
// Y Axis
this.stroke(0, 200, 0);
this.stroke(colors[1 % colors.length]);
if ((bits & Tree.Y) !== 0) {
this.line(0, 0, 0, 0, size, 0);
}
if ((bits & Tree._Y) !== 0) {
this.line(0, 0, 0, 0, -size, 0);
}
// Z Axis
this.stroke(0, 100, 200);
this.stroke(colors[2 % colors.length]);
if ((bits & Tree.Z) !== 0) {
this.line(0, 0, 0, 0, 0, size);
}
Expand Down

0 comments on commit 39fbbf2

Please sign in to comment.