Directory
1. Introduction
2. Description of the problem
3. Solution Ideas
4. Solution
5. Code
1 Introduction
The idea of drawing a two-dimensional array diagram
2 Problem description
Given a drawing object's high-end, X-spacing, y-spacing, and initialization coordinates x, y draw m*n
3 Solution Ideas
The idea map is as follows
, at this time
401 Coordinates (0,0) 402 coordinates (x+ room width + pitch x,0) 403 coordinates for (x+ room width *2+ pitch x*2,0)
301 coordinates for (0,y+ room height + pitch y) 302 coordinates for (x+ room width + pitch x, y+ room height + pitch y)
303 (x+ room width *2+ pitch x*2, y+ room height + pitch y)
Let's say there's a floor.
Can get the coordinates of the nth room (x+ room width * (n-1) + pitch x* (n-1), y+ room height * (a-m) + pitch y* (a-m) in the section m floor
i.e. (x+ (broadly + pitch x) * (n-1), y+ (room height + pitch y) * (a-m))
4 Code
var x=0,y=0; Define initial coordinates x, y
var roomh=10,rooml=10; Define room height for Roomh, broadly for ROOML
var marginx=5,marginy=5; Define x-axis spacing: marginx,y axis spacing: marginy
var floortotal=4,roomsinfloor=3;//definition total number of floors floortotal, number of rooms per floor: Roomsinfloor
for (var m=floortotal;m>=1;m--)//Cycle floor
{
for (var n=1;n< roomsinfloor;n++)//number of circulating rooms
{
var roomx=x+ (Rooml+marginx) * (n-1);
var roomy=y+ (roomh+marginy) * (FLOORTOTAL-M);
}
}
Algorithm: Drawing scheme