From 81913ff490894cebdcea717ce004a3cb8630dec5 Mon Sep 17 00:00:00 2001 From: Kseninia Mikhaylova Date: Thu, 23 May 2024 14:10:05 +0300 Subject: [PATCH] color --- front/src/components/FloorplanItem.vue | 49 ++++++++++++++------------ 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/front/src/components/FloorplanItem.vue b/front/src/components/FloorplanItem.vue index 0a058c5..735a91a 100644 --- a/front/src/components/FloorplanItem.vue +++ b/front/src/components/FloorplanItem.vue @@ -5,6 +5,7 @@ import PF, { Grid } from 'pathfinding' import { useFloorplanStore } from '../stores/floorplan'; import { useRoute } from 'vue-router'; +import { random_сolor } from '../helpers'; type PathItem = { path: string, unwalkable: boolean, x: number, y: number } const floorplan = useFloorplanStore() @@ -15,12 +16,12 @@ const context = ref(); const grid = ref() const startPoint = ref<{ x: number, y: number }>({ x: 25, y: 40 }) const endPoint = ref<{ x: number, y: number }>() -const startToEndPath = ref() +const startToEndPath = ref([]) const plan = useFloorplanStore() const paths = ref([]) -const finder = new PF.AStarFinder(); +const finder = new PF.BreadthFirstFinder(); const nextFrame = () => new Promise(resolve => requestAnimationFrame(resolve)); const route = useRoute() @@ -31,16 +32,17 @@ const newDraw = async () => { context.value = canvasElement.value?.getContext('2d') || undefined; const lines = plan.np_array + const c = random_сolor() for (let indexY = 0; indexY < lines.length; indexY++) { const line = lines[indexY]; for (let indexX = 0; indexX < line.length; indexX++) { const point = line[indexX]; if (canvasElement.value && context.value && point > 0) { - context.value.fillStyle = 'purple' + context.value.fillStyle = c.replace(')', ',0.5)').replace('rgb', 'rgba') context.value.fillRect(indexX, indexY, 1, 1) } } - if (indexY % 4 == 0) { + if (indexY % 10 == 0) { await nextFrame() } } @@ -65,8 +67,10 @@ const newDraw = async () => { } const findPath = async () => { + // filders.forEach((finder,i) => { + console.time(`findpath`) if (!endPoint.value) return - const localPath = finder.findPath( + const localPath: number[][] = finder.findPath( Math.round(startPoint.value.x), Math.round(startPoint.value.y), Math.round(endPoint.value.x), @@ -74,6 +78,8 @@ const findPath = async () => { (grid.value?.clone() as Grid) ); startToEndPath.value = localPath + console.timeEnd(`findpath`) + // }); } const setPointSvg = (item: { x: number, y: number }) => { @@ -97,12 +103,21 @@ const ch = 800
- + + +
@@ -116,18 +131,6 @@ const ch = 800