Advertisement
Guest User

8x8 painter -- html

a guest
Nov 30th, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.71 KB | None | 0 0
  1. String indexHTML = R"=====(
  2. <!DOCTYPE html>
  3. <html lang="en" dir="ltr">
  4.     <head>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  6. <title>8x8 Painter</title>
  7. <style>
  8.     html,body{
  9.         font:18px Helvetica,Arial,sans-serif;
  10.         padding:50;
  11.         margin:50;
  12.         background-color:#aaa;
  13.     }
  14.    
  15.     #flexHolder{
  16.         display:flex;
  17.     }
  18.    
  19.     #output{
  20.         padding:20px;
  21.         border:4px solid black;
  22.         background-color:white;
  23.     }
  24.  
  25.     #allTheseLEDs{
  26.         padding:0;
  27.         margin:0;
  28.         border:4px solid black;
  29.         margin-right:50px;
  30.         /* display:flex; */
  31.         width:min-content;
  32.     }
  33.    
  34.     .oneRow{
  35.     flex-direction:row;
  36.         display:flex;
  37.     }
  38.  
  39.     .butHolder{
  40.         width:60px;
  41.         height:60px;
  42.         border:1px solid black;
  43.         background-color:#d0d0d0;
  44.         display:inline-table;
  45.     }
  46.  
  47.     .oneDot{
  48.         font-size:300%;
  49.         border:none;
  50.         background-color:transparent;
  51.         padding:0;
  52.         margin:0;
  53.         line-height:90%;
  54.         width:100%;
  55.         height:100%;
  56.     }
  57.    
  58.     .dotON{
  59.         color:#ff2525;
  60.     }
  61.    
  62.     .dotOFF{
  63.         color:#404040;
  64.     }
  65.    
  66.     #copyRight{}
  67.    
  68.     #copyRight a{
  69.         font-size:70%;
  70.         color:#666;
  71.         text-decoration:none;
  72.         border:none;
  73.     }
  74.  
  75.     #copyRight a:hover{
  76.         text-decoration:none;
  77.         border:none;
  78.         color:black;
  79.     }
  80. </style>
  81.  
  82. </head>
  83. <body>
  84.  
  85. <h1>8x8 Painter</h1>
  86.  
  87. <div id="flexHolder">
  88. <div id="allTheseLEDs"></div>
  89. <div id="output"><span id="stage"></span></div>
  90. </div>
  91.  
  92. <div id="copyRight">
  93.     <a href="https://detlefamend.de" target="_blank">Detlef Amend 2020</a>
  94. </div>
  95.  
  96. <script>
  97.     var line=1;
  98.     var divvLine;
  99.     var Url='http://' + location.hostname + '/'
  100.    
  101.     window.onload=bootup;
  102.    
  103.     function AjaxInit(){
  104.         AJ=new XMLHttpRequest();
  105.         // AJ.onreadystatechange=AJReader;
  106.     }
  107.  
  108.     function calcTheOutput(){
  109.         var allDotsDatStream='';
  110.         var stageString="Data-String:<br/><br/>const unsigned uint8_t PROGMEM img[]={<br/>";
  111.         for(t=1;t<=8;t++){
  112.             stageString+='B';
  113.             for(k=1;k<=8;k++){
  114.                 var thisDot=document.getElementById(t.toString()+k.toString());
  115.                
  116.                 if(thisDot.classList.contains("dotOFF")){
  117.                     stageString+='0';
  118.                     allDotsDatStream+='0';
  119.                 }else{
  120.                     stageString+='1';
  121.                     allDotsDatStream+='1';
  122.                 }
  123.             }
  124.             if(t==8){
  125.                 stageString+="<br/>";
  126.             }else{
  127.                 stageString+=",<br/>";
  128.             }
  129.         }
  130.         stageString+="};";
  131.         document.getElementById("stage").innerHTML=stageString;
  132.         AJ.open("GET",Url+"?data="+allDotsDatStream,true);
  133.         AJ.send();
  134.     }
  135.    
  136.     function addEvent(element,evnt,funct){
  137.         if(element.attachEvent)
  138.          return element.attachEvent('on'+evnt,funct);
  139.         else
  140.          return element.addEventListener(evnt,funct,false);
  141.     }
  142.    
  143.     function toggleThisDot(){
  144.         var whatBut=this.getAttribute('id');
  145.         console.log(whatBut);
  146.         if(this.classList.contains("dotOFF")){
  147.             this.classList.remove("dotOFF");
  148.             this.classList.add("dotON");
  149.         }else{
  150.             this.classList.remove("dotON");
  151.             this.classList.add("dotOFF");
  152.         }
  153.         calcTheOutput();
  154.     }
  155.    
  156.     function draw8Buttons(){
  157.         for(t=1;t<=8;t++){
  158.  
  159.             var holderDiv=document.createElement("DIV");
  160.             holderDiv.classList.add("butHolder");
  161.             holderDiv.id='holdOneBut'+line+t.toString();
  162.             document.getElementById(divvLine).appendChild(holderDiv);
  163.  
  164.             var but=document.createElement("BUTTON");
  165.             but.id=line+t.toString();
  166.             but.classList.add("oneDot");
  167.             but.classList.add("dotOFF");
  168.             but.innerHTML='&#9679;';
  169.             holderDiv.appendChild(but);
  170.            
  171.             addEvent(but,'click',toggleThisDot);
  172.         }
  173.     }
  174.    
  175.     function drawGrid(){
  176.         for(line=1;line<=8;line++){
  177.             var divv=document.createElement("DIV");
  178.             divvLine='line'+line.toString();
  179.             divv.id='line'+line.toString();
  180.             divv.classList.add("oneRow");
  181.             allTheseLEDs.appendChild(divv);
  182.             draw8Buttons();
  183.         }
  184.     }
  185.  
  186.     function bootup(){
  187.         drawGrid();
  188.         AjaxInit();
  189.         calcTheOutput();
  190.     }
  191. </script>
  192. </body>
  193. </html>
  194. )=====";
  195.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement