Advertisement
Richbadniss

Room Visualizer

Dec 1st, 2024
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from "react"
  2.  
  3. interface RoomVisualizerProps {
  4.   roomLength: number
  5.   roomWidth: number
  6.   tileSize: number
  7.   isMetric: boolean
  8. }
  9.  
  10. export function RoomVisualizer({ roomLength, roomWidth, tileSize, isMetric }: RoomVisualizerProps) {
  11.   // Calculate the container size (fixed viewport)
  12.   const containerWidth = 500  
  13.   const containerHeight = 500
  14.  
  15.   // Calculate scale based on the container size and room dimensions
  16.   const scale = Math.min(
  17.     (containerWidth * 0.85) / roomLength,
  18.     (containerHeight * 0.85) / roomWidth
  19.   )
  20.  
  21.   // Calculate scaled dimensions
  22.   const scaledLength = roomLength * scale
  23.   const scaledWidth = roomWidth * scale
  24.  
  25.   // Convert tile size to the same unit as room dimensions (feet or meters)
  26.   const tileSizeInFeet = tileSize / 12 // Convert inches to feet
  27.   const gridSizeScaled = tileSizeInFeet * scale
  28.  
  29.   return (
  30.     <div className="w-full h-full min-h-[500px] relative">
  31.      
  32.       <div className="absolute inset-[10%] flex items-center justify-center">
  33.         {/* Grid pattern background */}
  34.         <div className="relative"
  35.              style={{
  36.                width: scaledLength,
  37.                height: scaledWidth,
  38.                backgroundImage: 'linear-gradient(to right, rgba(0,0,0,0.1) 1px, transparent 1px), linear-gradient(to bottom, rgba(0,0,0,0.1) 1px, transparent 1px)',
  39.                backgroundSize: `${gridSizeScaled}px ${gridSizeScaled}px`
  40.              }}>
  41.           {/* Corner dots */}
  42.           <div className="absolute -left-1.5 -top-1.5 w-3 h-3 bg-black rounded-full shadow-md"></div>
  43.           <div className="absolute -right-1.5 -top-1.5 w-3 h-3 bg-black rounded-full shadow-md"></div>
  44.           <div className="absolute -left-1.5 -bottom-1.5 w-3 h-3 bg-black rounded-full shadow-md"></div>
  45.           <div className="absolute -right-1.5 -bottom-1.5 w-3 h-3 bg-black rounded-full shadow-md"></div>
  46.  
  47.           {/* Dotted lines */}
  48.           <div className="absolute inset-0 border-2 border-dashed border-black"></div>
  49.  
  50.           {/* Measurements */}
  51.           <div className="absolute transition-transform duration-300 hover:bg-transparent/45 hover:text-gray-50 top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2
  52.                      bg-black text-white px-3 py-1 rounded-full text-sm font-medium">
  53.             {(roomLength * roomWidth).toFixed(2)} sq {isMetric ? 'm' : 'ft'}
  54.           </div>
  55.  
  56.           <div className="absolute -top-8 left-1/2 -translate-x-1/2
  57.                      bg-black text-white px-3 py-1 rounded-full text-sm font-medium">
  58.             {roomLength.toFixed(2)} {isMetric ? 'm' : 'ft'}
  59.           </div>
  60.  
  61.           <div className="absolute top-1/2 -left-8 -translate-y-1/2 -rotate-90
  62.                      bg-black text-white px-3 py-1 rounded-full text-sm font-medium">
  63.             {roomWidth.toFixed(2)} {isMetric ? 'm' : 'ft'}
  64.           </div>
  65.         </div>
  66.       </div>
  67.     </div>
  68.   )
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement