js实现图片拼图效果代码

代码语言:html

所属分类:其他

代码描述:js实现图片拼图效果代码,拼图的卡扣还在不断变化。

代码标签: js 图片 拼图

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

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  


  
  
  
<style>
*, *:before, *:after {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  width: 100%;
  color: black;
  background: #0c0c0b;
  overflow: hidden;
  display: grid;
  place-content: center;
  background: url(//repo.bfw.wiki/bfwrepo/image/626903b0b64e2.png) center center / cover;
}
svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  filter: drop-shadow(#ffffff 1px 1px 0px);
  mix-blend-mode: overlay
}

g {
  
}

path {
  fill: transparent;
  stroke: #000000ff;
}
</style>


  
</head>

<body translate="no">
  <svg>
	<g></g>
</svg>
  
      <script  >
const svg = document.querySelector("svg");

const tileSize = 50;
const tilesWide = 40;
const tilesHigh = 20;
const changeChance = 0.01;
const animationTolerance = 0.002;
const animationSpeed = 0.1;

const targetPositions = Array(tilesWide * tilesHigh * 2).fill(0).map(_ => Math.random() > 0.5 ? -1 : 1);
const currentPositions = [...targetPositions];

function render() {
  let html = "";
  for (let x = 0; x < tilesWide; x++) {
    let linePoints = `M ${x * tileSize} 0`;
    for (let y = 0; y < tilesHigh; y++) {
      const pos = currentPositions[x + y * tilesWide];
      linePoints += `L ${x * tileSize} ${(y + 0.2) * tileSize}`;
      linePoints += `C ${x * tileSize} ${(y + 0.6) * tileSize}
                       ${(x + pos * 0.2) * tileSize} ${(y + 0.5 - 0.4 * pos * pos) * tileSize}
                       ${(x + pos * 0.2) * tileSize} ${(y + 0.5) * tileSize}`;
      linePoints += `C ${(x + pos * 0.2) * tileSize} ${(y + 0.5.........完整代码请登录后点击上方下载按钮下载查看

网友评论0