Created
October 14, 2017 04:32
-
-
Save cwervo/0be3678bad0cc3aac313210bb0893cf0 to your computer and use it in GitHub Desktop.
An implementation of the 10print algorithm in an A-Frame component!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AFRAME.registerComponent('10print', { | |
schema : { | |
x : { default : 0 }, | |
y : { default : 0 }, | |
width : { default : 30 }, | |
height : { default : 5 }, | |
spacing : { default : 1 }, | |
color : { default : 'white', type : 'color'}, | |
side: { default : 'double' } | |
}, | |
init: function () { | |
console.log("boop") | |
}, | |
tick : function (t) { | |
let slash = document.createElement('a-plane') | |
slash.setAttribute('position', `${this.data.x} ${this.data.y} 0`) | |
slash.setAttribute('width', 0.25) | |
slash.setAttribute('material', `color: ${this.data.rainbow ? `hsl(${t % 360}, 100%, 80%)` : this.data.color}; side: ${this.data.side}`) | |
slash.setAttribute('height', 1.65) | |
if (Math.random() < 0.5) { | |
slash.setAttribute('rotation', 'z', -45) | |
} else { | |
slash.setAttribute('rotation', 'z', 45) | |
} | |
this.el.appendChild(slash) | |
this.data.x += this.data.spacing | |
if (this.data.x >= this.data.width) { | |
this.data.x -= this.data.width; | |
this.data.y += this.data.spacing; | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lives at this link