From 2fd9cc46ff2428bb2fa891f47002e9d3e7585583 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Sat, 13 Aug 2022 11:33:30 +0100 Subject: init: import project --- cubie.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 cubie.js (limited to 'cubie.js') diff --git a/cubie.js b/cubie.js new file mode 100755 index 0000000..d76f43d --- /dev/null +++ b/cubie.js @@ -0,0 +1,59 @@ + +"use strict"; + +Cubie.prototype.explosion = 0.55; + +Cubie.prototype.setPos = function(x,y,z) +{ + this.mesh.position.set(x * Cubie.prototype.explosion, + y * Cubie.prototype.explosion, + z * Cubie.prototype.explosion); +}; + +Cubie.prototype.updateExplosion = function() +{ + this.setPos(this.normPos[0],this.normPos[1],this.normPos[2]); +}; + +Cubie.prototype.updatePosition = function(pos) +{ + this.mesh.position.set((((Math.floor(pos/2) % 2) * (-2)) + 1) * Cubie.prototype.explosion, + ((Math.floor(pos/4) * (-2)) + 1) * Cubie.prototype.explosion, + (((Math.floor((pos+1)/2) % 2) * (-2)) + 1) * Cubie.prototype.explosion); +}; + +Cubie.prototype.getPos = function() +{ + return [this.mesh.position.x, this.mesh.position.y, this.mesh.position.z]; +}; + +function Cubie(key,pos,colors) +{ + this.key = key; + this.pos = pos; + this.colors = colors; + + var materials = new Array(6); + var us = new Array(6); + for(var i = 0; i < materials.length; i++) + { + materials[i] = new THREE.MeshBasicMaterial({ color: 0x000000, side: THREE.FrontSide }); + } + + for(var i = 0; i < colors.length; i++) + { + materials[colors[i].key] = new THREE.MeshBasicMaterial({ color: textures[colors[i].value], side: THREE.FrontSide }); + } + + this.normPos = [0.0,0.0,0.0]; + this.geometry = new THREE.BoxGeometry(1.0,1.0,1.0); + this.material = new THREE.MeshFaceMaterial(materials); + this.mesh = new THREE.Mesh(this.geometry,this.material); + + this.normPos = [(((Math.floor(this.pos/2) % 2) * (-2)) + 1), + ((Math.floor(this.pos/4) * (-2)) + 1), + (((Math.floor((this.pos+1)/2) % 2) * (-2)) + 1)]; + this.mesh.position.set((((Math.floor(pos/2) % 2) * (-2)) + 1) * Cubie.prototype.explosion, + ((Math.floor(pos/4) * (-2)) + 1) * Cubie.prototype.explosion, + (((Math.floor((pos+1)/2) % 2) * (-2)) + 1) * Cubie.prototype.explosion); +} -- cgit v1.2.3