css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              #app.container-fluid.pt-4
  .row
    .col-sm-9
      label Mirror
        input(type="checkbox", v-model="mirrorMode")
      .graph( @mousedown="editing=true" , @mouseup="editing=false")
        .row(v-for="o in settings.height")
          .block(v-for="i in settings.width", 
                @mousemove="editing?toggleBlock(i-1,o-1,true):''",
                @click="toggleBlock(i-1,o-1)",
                :class="{active: graphData[(o-1)*settings.width+(i-1)].value=='+'}") 
                //- span {{i}},{{o}}
      .modeTab(v-for="(item,itemId) in graphModes",
            @click="currentModeId=itemId",
            :class="{active: currentModeId==itemId}") {{ itemId+1 }}
        button(@click.stop="removeMode(itemId)") -
      .btn(@click="addMode") + 
      span(style="opacity: 0.3") (Use numkeys to switch)
    .col-sm-3
      .form
        label Width
        input.form-control(v-model.number="settings.width", type="number", @change="init")
        br
        label Height
        input.form-control(v-model.number="settings.height", type="number", @change="init")
        br
        button.form-control(@click="init") Clear
        br
        textarea.form-control(type='textarea' ,
          v-html="code",rows="5")
        br
        h5 Sample:
        select(v-model="sampleName")
          option(v-for="sample in samples", :value="sample.name") {{sample.name}}
        br
      button.form-control(@click="loadCustom") Load Other Code
      
      
      
            
          
!
            
              @mixin size($w,$h:$w)
  width: $w
  height: $h
html,body
  background-color: #111
  color: white
#app
  display: flex
  justify-content: center
  align-items: center
.graph
  display: flex
  flex-direction: column
  .row
    display: flex
  .block
    +size(5vmin)
    border: 1px solid #ddd
    background-color: #eee
    cursor: pointer
    &:hover
      background-color: #ccc
    &.active
      background-color: #333
.modeTab
  padding: 5px 30px
  background-color: #eee
  display: inline-block
  margin: 0px 1px
  cursor: pointer
  position: relative
  color: black
  &.active
    background-color: #aaa
    color: white
  button
    background-color: #f24
    color: white
    position: absolute
    right: 0
            
          
!
            
              
var vm = new Vue({
  el: "#app",
  data: {
    graphModes: [],
    settings: {
      width: 15,
      height: 15
    },
    mirrorMode: true,
    editing: false,
    currentModeId: 0,
    sampleName: "",
    samples: [
      {
        name: "Jelly",
        data: "8,8:18|3c|7e|db|ff|24|5a|a5#18|3c|7e|db|ff|5a|81|42"
      },{
        name: "Invader",
        data: "11,8:104|88|1fc|376|7ff|5fd|104|88#104|489|5fd|777|1fc|88|104|"
      },{
        name: "Ghost",
        data: "12,8:f0|7fe|fff|e67|fff|198|36c|c03#f0|7fe|fff|e67|fff|39c|666|30c"
      },{
        name: "Plane",
        data: "15,9:80|80|11c4|1364|17f4|1ffc|3ffe|770|220#80|80|1c0|1364|17f4|1ffc|3ffe|770|220"
      },{
        name: "Bomb",
        data: "7,7:|8|8|36|8|8|#49|2a||63||2a|49"
      },{
        name: "EnemyBullet",
        data: "3,5:2|1|2|4|2#2|2|2|2|2"
      },{
        name: "PlaneBullet",
        data: "3,3:2|7|2"
      },{
        name: "Ufo",
        data: "14,7:1e0|7f8|ffc|1ad6|3fff|e1c|408#1e0|7f8|ffc|1ad6|3fff|e1c|"
      }
    ]
  
  },
  created(){
    this.init()
    this.load('15,15:|||410|220|7f0|dd8|1ffc|17f4|410|360||||#|||410|1224|17f4|1ddc|ff8|410|808|||||')
    window.addEventListener('keydown',(evt)=>this.currentModeId=parseInt(evt.key)-1)
  },
  methods: {
    init(){ 
      this.currentModeId=0
      this.graphModes=[]
      this.addMode()
      console.log("init")
    },
    addMode(){
      this.graphModes.push(Array.from({length: this.settings.width*this.settings.height},()=>({value:"-"}) ))
     this.currentModeId= this.graphModes.length-1
    },
    
    toggleBlock(i,o,black){
      let obj = this.graphData[o*this.settings.width+i] 
      obj.value=obj.value=="+"?"-":"+"
      if (black){
        obj.value="+"
      }
      if (this.mirrorMode){
        let mid = ((this.settings.width-1)/2)
        let nx = -(i-mid)+mid
        let obj = this.graphData[o*this.settings.width+nx] 
        console.log(obj)
        obj.value=obj.value=="+"?"-":"+"
        if (black){
          obj.value="+"
        }
        
      }
    },
    load(data){
      let alltext =  data.split(":")[1]
      let settings = data.split(":")[0].split(",")
      // console.log(data.split(":")[1].replace(/\-/g," ")  .replace(/\+/g,"◼︎")  )
      this.settings.width=parseInt(settings[0])
      this.settings.height=parseInt(settings[1])
      this.init()
      console.log(alltext.split("#").map(modeHex=>
                  modeHex.split("|")
                    .map(t=>this.convertBinary(t))
                  .join("|")    
                ))
      this.graphModes = alltext
              .split("#")
                .map(modeHex=>
                  modeHex.split("|")
                    .map(t=>this.convertBinary(t))
                  .join("")    
                )
                .map(mode=>mode.split("").map(t=>({value:t})))
    },
    removeMode(id){
      if (this.currentModeId>=id){
        this.currentModeId-=1
      }
      this.graphModes.splice(id,1)
      
    },
    //convert HEX back to binary
    convertBinary(text){
      if (text==""){
        text="0"
      }
      let b = parseInt(text,16).toString(2)
      b = b.padStart(this.settings.width,'0')
      b = b.replace(/0/g,'-').replace(/1/g,'+')
      return b
    },
    //convert binary into hex code by line
    convertHex(text){
      let b = text.replace(/\-/g,'0').replace(/\+/g,'1')
      return parseInt(b,2).toString(16)
    },
    loadCustom(){
      this.load(prompt("Please Paste Code"))
    }
    
  },
  
  computed: {
    graphData(){
      return this.graphModes[this.currentModeId]
    },
    code(){ 
      let result = `${this.settings.width},${this.settings.height}:`
      result+=this.graphModes.map(mode=>{
        return  _.chunk(mode.map(block=>block.value),this.settings.width)
              .map(o=>o.join("")).map(t=>
          this.convertHex(t)
        ).map(
          t=>t!=0?t:""
        ).join("|")
      }).join("#")
      
      return result
    }
    
  },
  watch: {
    sampleName(){
     console.log("load sample") 
      this.load(this.samples.find(s=>s.name==this.sampleName).data)
    }
  }
})
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console