Skip to content

Commit

Permalink
🐛 Fix seed
Browse files Browse the repository at this point in the history
We need to pass the original seeds into the design and cut functions, they're used for shuffle-seed in designs.
  • Loading branch information
pouretrebelle committed Apr 25, 2021
1 parent 41cd4c8 commit b7edc21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/pages/api/preview/[sketch].ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const handler = async (req: Req, res: Res) => {
const { settings, design, DesignNoiseSeeds, cut, CutNoiseSeeds } = await import(`../../../../sketches/${req.query.sketch || '001'}/index.ts`)

const canvasWidth = req.query.width ? parseInt(req.query.width) : 200
const designSeeds = req.query.designSeeds ? req.query.designSeeds.split(',') : []
const cutSeeds = req.query.cutSeeds ? req.query.cutSeeds.split(',') : []
const queryDesignSeeds = req.query.designSeeds ? req.query.designSeeds.split(',') : []
const queryCutSeeds = req.query.cutSeeds ? req.query.cutSeeds.split(',') : []

const canvas = createCanvas(canvasWidth, canvasWidth)
const c = canvas.getContext('2d') as CanvasRenderingContext2D
Expand All @@ -36,7 +36,7 @@ const handler = async (req: Req, res: Res) => {
const designWidth = canvasWidth - canvasBleed * 2
const designCanvas = createCanvas(designWidth, designWidth)
const designC = designCanvas.getContext('2d') as CanvasRenderingContext2D
const designSimplex = Object.keys(DesignNoiseSeeds).map((_, i) => new SimplexNoise(designSeeds[i] || makeRandomSeed()))
const designSeeds = Object.keys(DesignNoiseSeeds).map((_, i) => queryDesignSeeds[i] || makeRandomSeed())

const designScale = designWidth / (settings.width)

Expand All @@ -51,15 +51,16 @@ const handler = async (req: Req, res: Res) => {

design({
c: designC,
simplex: designSimplex,
seed: designSeeds,
simplex: designSeeds.map(seed => new SimplexNoise(seed)),
noiseStart: 0,
...settings,
width: settings.width ? settings.width + settings.bleed * 2 : undefined,
height: settings.height ? settings.height + settings.bleed * 2 : undefined,
} as Design)
designC.restore()

const cutSimplex = Object.keys(CutNoiseSeeds).map((_, i) => new SimplexNoise(cutSeeds[i] || makeRandomSeed()))
const cutSeeds = Object.keys(CutNoiseSeeds).map((_, i) => queryCutSeeds[i] || makeRandomSeed())

designC.strokeStyle = 'black'
designC.lineWidth = 0.5 / designScale
Expand All @@ -68,7 +69,8 @@ const handler = async (req: Req, res: Res) => {
designC.scale(designScale, designScale)
cut({
c: designC,
simplex: cutSimplex,
seed: cutSeeds,
simplex: cutSeeds.map(seed => new SimplexNoise(seed)),
noiseStart: 0,
...settings
} as Cut)
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export interface Sketch {
export interface Cut {
c: CanvasRenderingContext2D
simplex: SimplexNoise[]
seed: string[]
width: number
height: number
rows: number
Expand All @@ -99,6 +100,7 @@ export interface Cut {
export interface Design {
c: CanvasRenderingContext2D
simplex: SimplexNoise[]
seed: string[]
width: number
height: number
bleed: number
Expand Down

0 comments on commit b7edc21

Please sign in to comment.