qrbtf/src/components/renderer/RendererRandRect.js

54 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-05-22 08:23:19 +00:00
import React from "react";
import {rand} from "../../utils/util";
2020-05-20 12:10:45 +00:00
import {createRenderer} from "../style/Renderer";
2020-06-22 06:57:32 +00:00
import {RendererLine} from "./RendererLine";
2020-05-04 08:51:12 +00:00
2020-05-08 16:04:36 +00:00
function listPoints(qrcode, params) {
if (!qrcode) return []
2020-05-04 08:51:12 +00:00
const nCount = qrcode.getModuleCount();
const pointList = [];
let id = 0;
let randArr = [];
for (let row = 0; row < nCount; row++) {
for (let col = 0; col < nCount; col++) {
randArr.push([row,col]);
}
}
randArr.sort(function() {
return (0.5-Math.random());
})
for (let i = 0; i < randArr.length; i++) {
let row = randArr[i][0];
let col = randArr[i][1];
2020-05-05 02:33:20 +00:00
if (qrcode.isDark(row, col)) {
let tempRand = rand(0.8, 1.3);
let randNum = rand(50,230);
let tempRGB = [
'rgb(' + Math.floor(20 + randNum) + ',' + Math.floor(170 - randNum / 2) + ',' + Math.floor(60 + randNum * 2) + ')',
'rgb(' + Math.floor(-20 + randNum) + ',' + Math.floor(130 - randNum / 2) + ',' + Math.floor(20 + randNum * 2) + ')'
];
let width = 0.15;
pointList.push(<rect key={id++} opacity="0.9" fill={tempRGB[1]} width={1 * tempRand + width} height={1 * tempRand + width} x={row - (tempRand - 1)/2} y={col - (tempRand - 1)/2}/>);
pointList.push(<rect key={id++} fill={tempRGB[0]} width={1 * tempRand} height={1 * tempRand} x={row - (tempRand - 1)/2} y={col - (tempRand - 1)/2}/>);
}
2020-05-04 08:51:12 +00:00
}
return pointList;
}
2020-05-08 16:04:36 +00:00
function getParamInfo() {
return []
}
2020-05-20 12:10:45 +00:00
const RendererRandRect = createRenderer({
listPoints: listPoints,
getParamInfo: getParamInfo
})
2020-05-04 08:51:12 +00:00
2020-05-08 16:04:36 +00:00
export default RendererRandRect
2020-06-22 06:57:32 +00:00
RendererRandRect.detail = (
<div>有一点点骚的配色很适合你</div>
);