可以编辑粒子特效的编辑器,可导出json

代码语言:html

所属分类:粒子

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<title> particleEditor.json</title>

<style>
      html, body {
  margin: 0;
  background: #131417;
  color: #FFF;
  font-family: 'Inconsolata', monospace;
  height: 100%;
}

body {
  box-sizing: border-box;
  padding: 1em;
  font-size: 18px;
  display: flex;
}
@media (max-width: 650px) {
  body {
    font-size: 16px;
  }
}
@media (max-width: 500px) {
  body {
    font-size: 14px;
  }
}

.container {
  margin: auto;
  width: 30em;
}
.container * {
  box-sizing: border-box;
}
.container .title {
  margin-bottom: 0.5em;
  opacity: 0;
  -webkit-animation: inDown 0.25s forwards;
          animation: inDown 0.25s forwards;
  -webkit-animation-delay: 0.5s;
          animation-delay: 0.5s;
}
.container .scene {
  padding-top: 50%;
  position: relative;
  -webkit-animation: inUp 0.25s;
          animation: inUp 0.25s;
}
.container .scene .info {
  position: absolute;
  z-index: 100;
  top: 0.5em;
  left: 0.5em;
  opacity: 0;
  pointer-events: none;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
}
.container .scene:hover .info {
  opacity: 1;
}
.container .scene canvas {
  background: #333;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 3px;
  image-rendering: optimizeSpeed;
  /* Legal fallback */
  image-rendering: -moz-crisp-edges;
  /* Firefox        */
  image-rendering: -o-crisp-edges;
  /* Opera          */
  image-rendering: -webkit-optimize-contrast;
  /* Safari         */
  image-rendering: optimize-contrast;
  /* CSS3 Proposed  */
  image-rendering: crisp-edges;
  /* CSS4 Proposed  */
  image-rendering: pixelated;
  /* CSS4 Proposed  */
  -ms-interpolation-mode: nearest-neighbor;
  /* IE8+           */
}
.container .scene .scale {
  position: absolute;
  bottom: 0;
  right: 0;
  display: flex;
}
.container .scene .scale .btn, .container .scene .scale .label {
  min-width: 1.5em;
  height: 1.5em;
  line-height: 1.5em;
  text-align: center;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
}
.container .scene .scale .btn {
  cursor: pointer;
}
.container .scene .scale .btn:hover {
  background: rgba(255, 255, 255, 0.1);
}
.container .settings {
  margin-top: 1em;
  margin-bottom: 1em;
  padding: 1em;
  background: #333;
  border-radius: 3px;
  height: 15em;
  opacity: 0;
  -webkit-animation: inDown 0.25s forwards;
          animation: inDown 0.25s forwards;
  -webkit-animation-delay: 0.25s;
          animation-delay: 0.25s;
}
.container .settings textarea {
  font-family: 'Inconsolata', monospace;
  width: 100%;
  height: 100%;
  font-size: 0.9em;
  padding: 0;
  resize: none;
  color: #FFF;
  border: none;
  background: none;
  outline: none;
  color: #4d7;
  letter-spacing: 0.05em;
  line-height: 1.5em;
}

@-webkit-keyframes inUp {
  from {
    -webkit-transform: translateY(-100%);
            transform: translateY(-100%);
    opacity: 0;
  }
  to {
    -webkit-transform: translateY(0%);
            transform: translateY(0%);
    opacity: 1;
  }
}

@keyframes inUp {
  from {
    -webkit-transform: translateY(-100%);
            transform: translateY(-100%);
    opacity: 0;
  }
  to {
    -webkit-transform: translateY(0%);
            transform: translateY(0%);
    opacity: 1;
  }
}
@-webkit-keyframes inDown {
  from {
    -webkit-transform: translateY(100%);
            transform: translateY(100%);
    opacity: 0;
  }
  to {
    -webkit-transform: translateY(0%);
            transform: translateY(0%);
    opacity: 1;
  }
}
@keyframes inDown {
  from {
    -webkit-transform: translateY(100%);
            transform: translateY(100%);
    opacity: 0;
  }
  to {
    -webkit-transform: translateY(0%);
            transform: translateY(0%);
    opacity: 1;
  }
}

    </style>

</head>
<body translate="no">
<div class="container">
<div class="scene">
<canvas></canvas>
<div class="info">move mouse/click to burst</div>
<div class="scale">
<div class="btn scale-down">-</div>
<div class="label">1</div>
<div class="btn scale-up">+</div>
</div>
</div>
<div class="settings">
<textarea></textarea>
</div>
</div>

<script>
  // console.clear()
var canvas = document.querySelector('canvas')
var particleSystem = new ParticleSystem(canvas)

var settings = JSON.parse(`{
   "width": 90,
   "height": 0,
   "count": 1,
   "interval": 1,
   "gaussian": 1,
   "life": 120,
   "colors": [
      [ "#F22", "#FFF" ],
      [ "#F82", "#F22" ]
   ],
   "vel": {
      "min": 1,
      "max": 5
   },
   "accel": 0,
   "size": { "min": 2, "max": 15 },
   "grow": 0.1,
   "shape": "square",
   "wobble": { "time": 60, "amount": 0.1 },
   "direction": {
      "min": 270,
      "max": 270
   },
   "alpha": 1,
   "fade": 0.025
}`)


//----------------------------------------------------------------------------------//
//----------------------------------| interface |-----------------------------------//
//----------------------------------------------------------------------------------//
var mouse = {
   down: false,
   over: false,
   x: 0,
   y: 0
}

var html = {}
html.textarea = document.querySelector('textarea')
html.canvas = document.querySelector('canvas')
html.scale = document.querySelector('.scale')
html.scaleUp = html.scale.querySelector('.scale-up')
html.scaleDown = html.scale.querySelector('.scale-down')
html.scaleLabel = document.querySelector('.label')

var scaleCanvas = function(amount) {
   var value = Number(this.html.scaleLabel.innerHTML)
   value = Math.min(Math.max(0, value+amount), 12)
   this.html.scaleLabel.innerHTML = value
   particleSystem.changeScale(value)
}

html.scaleUp.addEventListener('click', function() {
   this.scaleCanvas(0.5)
}.bind(this))

this.html.scaleDown.addEventListener('click', function() {
   this.scaleCanvas(-0.5)
}.bind(this))

this.html.textarea.innerHTML = JSON.stringify(settings, null, 3)
this.html.textarea.addEventListener('input', function(e) {
   try {
      var newValue = e.target.value
      settings = JSON.parse(newValue)
   } catch(e) {
      console.log('json error', e)
   }
}.bind(this))  

this.html.canvas.addEventListener('mousemove', function(e) {
   mouse.x = e.layerX
   mouse.y = e.layerY
})

this.html.canvas.addEventListener('mousedown', function(e) { e.preventDefault(); mouse.down = true })
this.html.canvas.addEventListener('mouseup', function(e.........完整代码请登录后点击上方下载按钮下载查看

网友评论0