Skip to content

Instantly share code, notes, and snippets.

@cwervo
Created October 14, 2017 04:32
Show Gist options
  • Save cwervo/0be3678bad0cc3aac313210bb0893cf0 to your computer and use it in GitHub Desktop.
Save cwervo/0be3678bad0cc3aac313210bb0893cf0 to your computer and use it in GitHub Desktop.
An implementation of the 10print algorithm in an A-Frame component!
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;
}
}
})
@cwervo
Copy link
Author

cwervo commented Oct 14, 2017

Lives at this link

giphy 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment