From c077403eeca24283bfb33f3b924858d24ceb0f01 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Fri, 3 Jan 2020 18:29:46 -0800 Subject: [PATCH] Generate new seed on paste --- src/index.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/index.tsx b/src/index.tsx index f48d529ec..4451c193a 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -22,6 +22,10 @@ let elements = Array.of(); const LCG = (seed: number) => () => ((2 ** 31 - 1) & (seed = Math.imul(48271, seed))) / 2 ** 31; +function randomSeed() { + return Math.floor(Math.random() * 2 ** 31); +} + // Unfortunately, roughjs doesn't support a seed attribute (https://github.com/pshihn/rough/issues/27). // We can achieve the same result by overriding the Math.random function with a // pseudo random generator that supports a random seed and swapping it back after. @@ -174,7 +178,7 @@ function newElement( isSelected: false, strokeColor: strokeColor, backgroundColor: backgroundColor, - seed: Math.floor(Math.random() * 2 ** 31), + seed: randomSeed(), draw( rc: RoughCanvas, context: CanvasRenderingContext2D, @@ -737,6 +741,7 @@ class App extends React.Component<{}, AppState> { parsedElements.forEach(parsedElement => { parsedElement.x += 10; parsedElement.y += 10; + parsedElement.seed = randomSeed(); generateDraw(parsedElement); elements.push(parsedElement); });