autoformat

This commit is contained in:
Tomáš Mládek 2021-09-11 23:51:22 +02:00
parent de53e1b741
commit 79f9108f34

View file

@ -11,14 +11,14 @@ export const collageModeType = [
export type CollageModeType = typeof collageModeType[number]; export type CollageModeType = typeof collageModeType[number];
function cleanDraw(ctx: CanvasRenderingContext2D, image: ImageBitmap, function cleanDraw(ctx: CanvasRenderingContext2D, image: ImageBitmap,
x: number, y: number, w: number, h: number) { x: number, y: number, w: number, h: number) {
const scaleRatio = Math.max(w / image.width, h / image.height); const scaleRatio = Math.max(w / image.width, h / image.height);
ctx.drawImage( ctx.drawImage(
image, image,
image.width / 2 - w / scaleRatio / 2, image.height / 2 - h / scaleRatio / 2, image.width / 2 - w / scaleRatio / 2, image.height / 2 - h / scaleRatio / 2,
w / scaleRatio, h / scaleRatio, w / scaleRatio, h / scaleRatio,
x - w / 2, y - h / 2, x - w / 2, y - h / 2,
w, h w, h
); );
} }
@ -78,13 +78,13 @@ const modes: { [key in CollageModeType]: CollageMode } = {
place: (ctx, images, segments) => { place: (ctx, images, segments) => {
const shuffledImages = shuffle(images); const shuffledImages = shuffle(images);
shuffle(segments.map((segment, idx) => [segment, idx] as [Segment, number])) shuffle(segments.map((segment, idx) => [segment, idx] as [Segment, number]))
.forEach(([segment, idx]) => { .forEach(([segment, idx]) => {
const image = shuffledImages[idx]; const image = shuffledImages[idx];
const scaleRatio = Math.max(segment.w / image.width, segment.h / image.height); const scaleRatio = Math.max(segment.w / image.width, segment.h / image.height);
ctx.drawImage(image, ctx.drawImage(image,
segment.x - (image.width * scaleRatio / 2), segment.y - (image.height * scaleRatio / 2), segment.x - (image.width * scaleRatio / 2), segment.y - (image.height * scaleRatio / 2),
image.width * scaleRatio, image.height * scaleRatio); image.width * scaleRatio, image.height * scaleRatio);
}); });
}, },
}, },
"row": { "row": {
@ -112,8 +112,8 @@ const modes: { [key in CollageModeType]: CollageMode } = {
const segmentSize = [ctx.canvas.width / numImages, ctx.canvas.height]; const segmentSize = [ctx.canvas.width / numImages, ctx.canvas.height];
return range(numImages).map((idx) => { return range(numImages).map((idx) => {
const irregularWidth = images ? const irregularWidth = images ?
segmentSize[0] + Math.random() * ((segmentSize[1] / images[idx].height * images[idx].width) - segmentSize[0]) : segmentSize[0] + Math.random() * ((segmentSize[1] / images[idx].height * images[idx].width) - segmentSize[0]) :
segmentSize[0] + Math.random() * segmentSize[0] * .5; segmentSize[0] + Math.random() * segmentSize[0] * .5;
return { return {
x: idx * segmentSize[0] + segmentSize[0] / 2, x: idx * segmentSize[0] + segmentSize[0] / 2,
y: segmentSize[1] / 2, y: segmentSize[1] / 2,
@ -149,8 +149,8 @@ const modes: { [key in CollageModeType]: CollageMode } = {
const segmentSize = [ctx.canvas.width, ctx.canvas.height / numImages]; const segmentSize = [ctx.canvas.width, ctx.canvas.height / numImages];
return range(numImages).map((idx) => { return range(numImages).map((idx) => {
const irregularHeight = images ? const irregularHeight = images ?
segmentSize[1] + Math.random() * ((segmentSize[0] / images[idx].width * images[idx].height) - segmentSize[1]) : segmentSize[1] + Math.random() * ((segmentSize[0] / images[idx].width * images[idx].height) - segmentSize[1]) :
segmentSize[1] + Math.random() * segmentSize[1] * .5; segmentSize[1] + Math.random() * segmentSize[1] * .5;
return { return {
x: segmentSize[0] / 2, x: segmentSize[0] / 2,
y: idx * segmentSize[1] + segmentSize[1] / 2, y: idx * segmentSize[1] + segmentSize[1] / 2,