autoformat

master
Tomáš Mládek 2021-09-11 23:51:22 +02:00
parent de53e1b741
commit 79f9108f34
1 changed files with 17 additions and 17 deletions

View File

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