Skip to content

Instantly share code, notes, and snippets.

@m2wasabi
Created September 27, 2016 12:30
Show Gist options
  • Save m2wasabi/cbe3baa36bc00d6bed64e73db969bb47 to your computer and use it in GitHub Desktop.
Save m2wasabi/cbe3baa36bc00d6bed64e73db969bb47 to your computer and use it in GitHub Desktop.
Milkcocoa Nefryハンズオン 緊急対応2
function toggelClass(){
$bulb.classList.toggle("light_up");
red = parseInt(Math.floor(Math.random()*256));
green = parseInt(Math.floor(Math.random()*256));
blue = parseInt(Math.floor(Math.random()*256));
let color = "#" + red.toString(16) + green.toString(16) + blue.toString(16) ;
addClass(color);
flag = 1;
//ドット絵から受け取ったデータをNefryに流す
nefry_ds.send({r:red,g:green,b:blue},(err,pushed) => {
console.log(pushed);
});
}
function removeClass(){
if(flag === 0)return;
$bulb.style.background = '#bbb';
$bulb.style.boxShadow = '';
$bulb.classList.remove("light_up");
}
function addClass(color){
$bulb.style.background = color;
$bulb.style.boxShadow = `0 -10px 100px ${color}`;
$bulb.classList.add("light_up");
}
let $light = document.querySelector('#light');
let $bulb = document.querySelector('.bulb');
$light.addEventListener("click", toggelClass, false);
/**
* step2で以下を追加 + step4で変更
*/
//Nefry側のアプリ&データストア
milkcocoa = new MilkCocoa(`woodilrg1cz3.mlkcca.com`);
const nefry_ds = milkcocoa.dataStore('nefry');
let flag = 0, red = 0, green = 0, blue = 0;
setInterval(()=>{
removeClass();
flag = 0;
},5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment