Create Python code to generate a 2D floor plan for a modern single-story house. Use the…
- User
Create Python code to generate a 2D floor plan for a modern single-story house. Use the Cairo graphics library for drawing. The plan should include the following specifications:
Total Rooms: 7 (including Living Room, Kitchen, Dining Room, 2 Bedrooms, 2 Bathrooms, Entry, Hallway, Storage) Room Specifications:
Living Room: Include a large window, seating area, and a coffee table. Kitchen: Include L-shaped countertops, a sink, refrigerator, and stove. Add an island with barstools. Dining Room: Include a rectangular table with chairs. Bedrooms: Two bedrooms with beds and nightstands. One should have a walk-in closet. Bathrooms: Two bathrooms, each with essential fixtures (bathtub or shower, toilet, sink). Entry: Include a front door and space for a coat rack. Hallway: Connecting all rooms. Storage Room: Include shelving units. Additional Requirements:
Windows: Include windows in every room for natural light. Lighting: Consider different lighting types for each room (ceiling fixtures, lamps, sconces). Exterior Features: Include a small porch at the front entry and basic landscaping. Color Palette: Use neutral tones with accents in decor.
Code Structure:
Use the following libraries: cairo: For drawing the plan numpy: To handle any calculations, if necessary The code should create a PNG file of the house plan. Expected Output: Provide the complete Python code that, when executed, generates a 2D floor plan as described.
- Assistant
import cairo import numpy as np # Set the image size and create a Cairo surface and context WIDTH, HEIGHT = 1000, 800 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT) ctx = cairo.Context(surface) # Define a scale for drawing (e.g., pixels per foot/meter) SCALE = 1.0 # For now, one unit equals one pixel # Define a color palette using neutral tones with accent colors COLORS = { 'background': (1, 1, 1), 'walls': (0, 0, 0), 'floor': (0.9, 0.9, 0.9), 'window_glass': (0.5, 0.8, 1.0, 0.5), # semi-transparent blue 'door': (0.6, 0.3, 0, 1), # brown 'furniture': (0.7, 0.7, 0.7), 'bed': (0.8, 0.8, 0.6), 'table': (0.6, 0.4, 0.2), 'chair': (0.5, 0.3, 0.1), 'sink': (0.8, 0.8, 0.8), 'toilet': (0.9, 0.9, 0.9), 'shower': (0.8, 0.8, 0.9), 'appliances': (0.7, 0.7, 0.8), 'lighting': (1, 1, 0), # yellow 'exterior': (0.5, 0.9, 0.5), # green for landscaping 'porch': (0.6, 0.4, 0.2), } # Fill background ctx.set_source_rgb(*COLORS['background']) ctx.rectangle(0, 0, WIDTH, HEIGHT) ctx.fill() # Functions to draw various elements def draw_room(x, y, width, height, label=None): # Draw floor ctx.set_source_rgb(*COLORS['floor']) ctx.rectangle(x, y, width, height) ctx.fill() # Draw walls ctx.set_source_rgb(*COLORS['walls']) ctx.set_line_width(2) ctx.rectangle(x, y, width, height) ctx.stroke() # Add room label if label: ctx.set_source_rgb(0, 0, 0) ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) ctx.set_font_size(14) ctx.move_to(x + 5, y + 15) ctx.show_text(label) def draw_door(x, y, width, height): ctx.set_source_rgba(*COLORS['door']) ctx.set_line_width(2) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_window(x, y, width, height): ctx.set_source_rgba(*COLORS['window_glass']) ctx.set_line_width(2) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_bed(x, y, width, height): ctx.set_source_rgb(*COLORS['bed']) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_table(x, y, width, height): ctx.set_source_rgb(*COLORS['table']) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_chair(x, y, width, height): ctx.set_source_rgb(*COLORS['chair']) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_sofa(x, y, width, height): ctx.set_source_rgb(*COLORS['furniture']) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_coffee_table(x, y, width, height): ctx.set_source_rgb(*COLORS['table']) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_sink(x, y, width, height): ctx.set_source_rgb(*COLORS['sink']) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_toilet(x, y, width, height): ctx.set_source_rgb(*COLORS['toilet']) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_shower(x, y, width, height): ctx.set_source_rgb(*COLORS['shower']) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_stove(x, y, width, height): ctx.set_source_rgb(*COLORS['appliances']) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_refrigerator(x, y, width, height): ctx.set_source_rgb(*COLORS['appliances']) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_countertop(x, y, width, height): ctx.set_source_rgb(*COLORS['floor']) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_island(x, y, width, height): ctx.set_source_rgb(*COLORS['table']) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_barstool(x, y, width, height): ctx.set_source_rgb(*COLORS['chair']) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_shelving(x, y, width, height): ctx.set_source_rgb(*COLORS['furniture']) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_lighting(x, y): ctx.set_source_rgb(*COLORS['lighting']) ctx.arc(x, y, 5, 0, 2*np.pi) ctx.fill() def draw_landscaping(x, y, width, height): ctx.set_source_rgb(*COLORS['exterior']) ctx.rectangle(x, y, width, height) ctx.fill() def draw_porch(x, y, width, height): ctx.set_source_rgb(*COLORS['porch']) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_coat_rack(x, y, width, height): ctx.set_source_rgb(*COLORS['furniture']) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.rectangle(x, y, width, height) ctx.stroke() def draw_walk_in_closet(x, y, width, height): ctx.set_source_rgb(*COLORS['floor']) ctx.rectangle(x, y, width, height) ctx.fill() ctx.set_source_rgb(*COLORS['walls']) ctx.set_line_width(2) ctx.rectangle(x, y, width, height) ctx.stroke() # Now, define room positions and sizes # Let's define some constants for room sizes ROOM_HEIGHT = 200 ROOM_WIDTH = 200 HALLWAY_WIDTH = 80 # Entry entry_x, entry_y = 100, 100 entry_width, entry_height = 120, 80 # Living Room living_x, living_y = entry_x + entry_width + 20, entry_y living_width, living_height = 300, 250 # Kitchen kitchen_x, kitchen_y = living_x + living_width + 20, living_y kitchen_width, kitchen_height = 250, 200 # Dining Room dining_x, dining_y = kitchen_x, kitchen_y + kitchen_height + 20 dining_width, dining_height = 250, 150 # Hallway hall_x, hall_y = entry_x, entry_y + entry_height + 20 hall_width, hall_height = HALLWAY_WIDTH, 400 # Bedroom 1 bed1_x, bed1_y = hall_x + hall_width + 20, hall_y bed1_width, bed1_height = 250, 200 # Bedroom 2 bed2_x, bed2_y = bed1_x, bed1_y + bed1_height + 20 bed2_width, bed2_height = 250, 200 # Bathroom 1 bath1_x, bath1_y = bed1_x + bed1_width + 20, bed1_y bath1_width, bath1_height = 150, 120 # Bathroom 2 bath2_x, bath2_y = bed2_x + bed2_width + 20, bed2_y bath2_width, bath2_height = 150, 120 # Storage Room storage_x, storage_y = entry_x, hall_y + hall_height + 20 storage_width, storage_height = 150, 100 # Draw rooms draw_room(entry_x, entry_y, entry_width, entry_height, label='Entry') draw_room(living_x, living_y, living_width, living_height, label='Living Room') draw_room(kitchen_x, kitchen_y, kitchen_width, kitchen_height, label='Kitchen') draw_room(dining_x, dining_y, dining_width, dining_height, label='Dining Room') draw_room(hall_x, hall_y, hall_width, hall_height, label='Hallway') draw_room(bed1_x, bed1_y, bed1_width, bed1_height, label='Bedroom 1') draw_room(bed2_x, bed2_y, bed2_width, bed2_height, label='Bedroom 2') draw_room(bath1_x, bath1_y, bath1_width, bath1_height, label='Bathroom 1') draw_room(bath2_x, bath2_y, bath2_width, bath2_height, label='Bathroom 2') draw_room(storage_x, storage_y, storage_width, storage_height, label='Storage') # Now, add specific features to rooms # Entry features draw_door(entry_x, entry_y, entry_width, 5) # Front door at the top of entry draw_coat_rack(entry_x + 10, entry_y + 20, 20, 10) # Living Room features # Large window draw_window(living_x + living_width - 5, living_y + 10, 5, 100) # Sofa draw_sofa(living_x + 20, living_y + 20, 80, 40) # Coffee Table draw_coffee_table(living_x + 110, living_y + 20, 50, 30) # Additional seating draw_chair(living_x + 20, living_y + 80, 40, 40) # Kitchen features # Countertops (L-shaped) draw_countertop(kitchen_x + 10, kitchen_y + 10, 200, 20) # Top wall draw_countertop(kitchen_x + 10, kitchen_y + 10, 20, 150) # Left wall # Sink on counter draw_sink(kitchen_x + 30, kitchen_y + 20, 30, 20) # Refrigerator draw_refrigerator(kitchen_x + 10, kitchen_y + 120, 20, 40) # Stove draw_stove(kitchen_x + 150, kitchen_y + 10, 40, 20) # Island with barstools draw_island(kitchen_x + 80, kitchen_y + 60, 100, 30) draw_barstool(kitchen_x + 90, kitchen_y + 95, 20, 20) draw_barstool(kitchen_x + 130, kitchen_y + 95, 20, 20) # Dining Room features # Dining table draw_table(dining_x + 40, dining_y + 30, 150, 70) # Chairs around table draw_chair(dining_x + 40, dining_y + 10, 30, 20) draw_chair(dining_x + 160, dining_y + 10, 30, 20) draw_chair(dining_x + 40, dining_y + 110, 30, 20) draw_chair(dining_x + 160, dining_y + 110, 30, 20) # Bedroom 1 features # Bed draw_bed(bed1_x + 20, bed1_y + 20, 80, 60) # Nightstand draw_table(bed1_x + 110, bed1_y + 20, 20, 20) # Walk-in closet closet_x = bed1_x + bed1_width - 80 closet_y = bed1_y + bed1_height - 80 closet_width = 60 closet_height = 80 draw_walk_in_closet(closet_x, closet_y, closet_width, closet_height) ctx.set_source_rgb(0, 0, 0) ctx.move_to(closet_x + 5, closet_y + 15) ctx.show_text("Closet") # Bedroom 2 features # Bed draw_bed(bed2_x + 20, bed2_y + 20, 80, 60) # Nightstand draw_table(bed2_x + 110, bed2_y + 20, 20, 20) # Bathroom 1 features # Sink draw_sink(bath1_x + 10, bath1_y + 10, 30, 20) # Toilet draw_toilet(bath1_x + 60, bath1_y + 10, 30, 20) # Bathtub draw_shower(bath1_x + 10, bath1_y + 50, 80, 50) # Bathroom 2 features # Sink draw_sink(bath2_x + 10, bath2_y + 10, 30, 20) # Toilet draw_toilet(bath2_x + 60, bath2_y + 10, 30, 20) # Shower draw_shower(bath2_x + 10, bath2_y + 50, 80, 50) # Storage Room features draw_shelving(storage_x + 10, storage_y + 10, storage_width - 20, 20) draw_shelving(storage_x + 10, storage_y + 40, storage_width - 20, 20) draw_shelving(storage_x + 10, storage_y + 70, storage_width - 20, 20) # Windows in every room for natural light # Entry window draw_window(entry_x + entry_width - 5, entry_y + 5, 5, entry_height - 10) # Living Room window already drawn # Kitchen window draw_window(kitchen_x + 5, kitchen_y + kitchen_height - 5, kitchen_width - 10, 5) # Dining Room window draw_window(dining_x + dining_width - 5, dining_y + 5, 5, dining_height - 10) # Bedroom 1 window draw_window(bed1_x + bed1_width - 5, bed1_y + 5, 5, bed1_height - 10) # Bedroom 2 window draw_window(bed2_x + 5, bed2_y + bed2_height - 5, bed2_width - 10, 5) # Bathrooms windows draw_window(bath1_x + bath1_width - 5, bath1_y + 5, 5, bath1_height - 10) draw_window(bath2_x + bath2_width - 5, bath2_y + 5, 5, bath2_height - 10) # Storage window draw_window(storage_x + storage_width -5, storage_y + 5, 5, storage_height - 10) # Lighting in rooms # Entry lighting draw_lighting(entry_x + entry_width / 2, entry_y + entry_height / 2) # Living Room draw_lighting(living_x + living_width / 2, living_y + living_height / 2) # Kitchen draw_lighting(kitchen_x + kitchen_width / 2, kitchen_y + kitchen_height / 2) # Dining Room draw_lighting(dining_x + dining_width / 2, dining_y + dining_height / 2) # Hallway draw_lighting(hall_x + hall_width / 2, hall_y + hall_height / 2) # Bedrooms draw_lighting(bed1_x + bed1_width / 2, bed1_y + bed1_height / 2) draw_lighting(bed2_x + bed2_width / 2, bed2_y + bed2_height / 2) # Bathrooms draw_lighting(bath1_x + bath1_width / 2, bath1_y + bath1_height / 2) draw_lighting(bath2_x + bath2_width / 2, bath2_y + bath2_height / 2) # Storage draw_lighting(storage_x + storage_width / 2, storage_y + storage_height / 2) # Exterior features # Porch at front entry porch_x = entry_x - 20 porch_y = entry_y - 40 porch_width = entry_width + 40 porch_height = 40 draw_porch(porch_x, porch_y, porch_width, porch_height) # Landscaping draw_landscaping(0, 0, WIDTH, porch_y) draw_landscaping(0, porch_y, porch_x, HEIGHT - porch_y) draw_landscaping(porch_x + porch_width, porch_y, WIDTH - (porch_x + porch_width), HEIGHT - porch_y) draw_landscaping(0, storage_y + storage_height, WIDTH, HEIGHT - (storage_y + storage_height)) # Save the image surface.write_to_png("house_plan.png")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.