Skip to content

Instantly share code, notes, and snippets.

@martinmev
Last active December 15, 2015 15:29
Show Gist options
  • Save martinmev/5281794 to your computer and use it in GitHub Desktop.
Save martinmev/5281794 to your computer and use it in GitHub Desktop.
Simple plan of flat created in Processing
// Copyright Martin Mevald 2013.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// https://gist.github.com/martinmev/5281794
// PDFs and PNGs:
// https://www.dropbox.com/sh/vwdpj0m79e09mek/_Qj_S9iLuE
import processing.pdf.*;
String language = "English"; // "Czech";
// picture path != null - create picture
String picture; // = "c:\\Users\\Martin\\Dropbox\\prog\\byt\\planek\\planek.png";
// pdfFile path != null - create PDF file
String pdfFile; // = "c:\\Users\\Martin\\Dropbox\\prog\\byt\\planek\\plan.pdf";
float livingRoomWallWindow=3.410;
float livingRoomWallWindowWidth=1.5; //unknown
float enclosedBalconyDoorWidth=0.7; //unknown
float beforeWindow = (livingRoomWallWindow - livingRoomWallWindowWidth - enclosedBalconyDoorWidth)/2; // unknown
float afterWindow = beforeWindow/2; //unknown
float livingRoomWall=4.884;
float livingRoomCeiling=2.651;
float enclosedBalcony = 1.154;
float enclosedBalcony2=livingRoomWallWindow;
float enclosedBalconyBanister= 0.967;
float bathLength=2.294;
float wcLength=0.66;
float closetWidth = 0.7;
float corridorLength=2.428;
float corridorWidth = 1.164;
float corridorDoorWidth = corridorWidth - closetWidth;
float bathFromCorridor = 0.841;
float wcFromWall = 0.66;
// Bosch PLR 25 Digital Laser Range Finder
// +- 2,0 mm
float bathroomDoorBeforeCorridorDoorWidth = 0.774;
float bathroomDoorWidth = corridorDoorWidth ; // unknown
float corridorLengthBeforeBathroomDoor = corridorLength - bathroomDoorWidth - bathroomDoorBeforeCorridorDoorWidth;
float standPipesWidth=(corridorLength-bathLength);
float flatLength = livingRoomWall+corridorLength;
float squaredMeters=flatLength*livingRoomWallWindow;
float objectWidth = flatLength + enclosedBalcony;
float objectHeight= livingRoomWallWindow;
float squaredMetersTotal= objectWidth*objectHeight;
int windowWidth = 1200;
int windowHeight = 500;
int margin=40;
float doubleLineWidth = 5;
float scaleWidth = (windowWidth - (2*margin) ) / objectWidth;
float scaleHeight = (windowHeight - (2*margin) ) / objectHeight;
int textSize=11;
int grayFill = 0;
int gray = 150;
int black = 0;
HashMap languageHashMap = new HashMap();
float tW(float w) {
return (w*scaleWidth);
}
float tH(float h) {
return (h*scaleHeight);
}
float tX(float x) {
return tW(x);
}
float tY(float y) {
return tH(y);
}
void Czech2Eng(HashMap h) {
h.put("lodžie", "loggia");
h.put("skříně", "closets");
h.put("vana", "bath");
h.put("stoupačky", "standpipes");
h.put("umyvadlo", "washbasin");
h.put("60.6 pod umyvadlem", "60.6 under washbasin");
h.put("36.1 i se sifonem", "36.1 with siphon");
h.put("okno", "window");
}
void drawText(String s, float x, float y) {
String s2 = (String) languageHashMap.get(trim(s));
if (s2!=null) {
s=s2;
}
fill(grayFill);
textSize(textSize);
text(s,x,y);
noFill();
if (s.indexOf(" ")!=-1 || int(s)==0) {
//println(s); // translation
}
}
void drawNumber(float n, float x, float y) { // in centimeters
drawText(str(round(n*100)),x,y);
}
void translateOn(float a) {
pushMatrix();
translate(margin+a,margin-a);
}
void translateOff() {
popMatrix();
}
void wallRect(float a, float b, float c, float d) {
rect(a,b,c,d);
rect(a+doubleLineWidth,b+doubleLineWidth,c-(2*doubleLineWidth),d-(2*doubleLineWidth));
}
void drawClosedLine(float y){
line(tX(flatLength)-doubleLineWidth,y,tX(objectWidth),y);
line(tX(flatLength)-doubleLineWidth,doubleLineWidth+y,tX(objectWidth),doubleLineWidth+y);
line(tX(objectWidth),y,tX(objectWidth),doubleLineWidth+y);
}
void dashLine(float x1,float y1, float x2, float y2, int dashes) {
float x = x1;
float y = y1;
float dx = (x2-x1) / dashes;
float dy = (y2-y1) / dashes;
dx += dx / dashes / 2;
dy += dy / dashes / 2 ;
float halfDx = dx / 2;
float halfDy = dy / 2;
for (int c = 0 ; c < dashes; c++ ) {
line(x,y,x+(dx/2),y+(dy/2));
x += dx;
y += dy;
}
}
void drawFlat() {
drawNumber(livingRoomWallWindow,margin-35,windowHeight/2);
arrowLine(margin-10,windowHeight-margin,margin-10,margin);
drawNumber(flatLength,windowWidth/2,windowHeight-margin+25);
arrowLine(margin,windowHeight-margin+10,tX(flatLength)+margin,windowHeight-margin+10);
drawNumber(livingRoomWall,windowWidth/2,30+margin);
arrowLine(tX(corridorLength)+margin+doubleLineWidth,tY(0.3)+margin,tX(flatLength)+margin-doubleLineWidth,tY(0.3)+margin);
translateOn(0);
wallRect(0,0,tW(flatLength),tH(livingRoomWallWindow));
translateOff();
translateOn(0);
drawClosedLine(0);
drawClosedLine(tY(livingRoomWallWindow)-doubleLineWidth);
float x = tX(objectWidth-enclosedBalcony+enclosedBalconyBanister);
float y = tY(livingRoomWallWindow) - doubleLineWidth;
dashLine(x,doubleLineWidth,x,y,30);
drawText("lodžie",x-tX(0.4),y/2);
translateOff();
}
void drawWallSocket(float x, float y) {
float a = 5;
float r = 17;
line(x,y,x-a,y+a);
line(x-a,y+a,x,y+a);
line(x,y+a,x-a,y+(2*a));
ellipse(x-(a/2),y+a,r,r);
}
void drawWallSocketOutOfOrder(float x, float y) {
drawWallSocket(x,y);
line(x-10,y,x+5,y+10);
}
void drawCorridor() {
translateOn(doubleLineWidth);
float x1 = 0; //tW(flatLength);
float y1 = tY(livingRoomWallWindow)-tY(corridorWidth);
float x2 = tX(corridorLengthBeforeBathroomDoor);
float y2= y1;
line(x1,y1,x2,y2);
stroke(gray);
line(x2,y2,x2,y2+tY(0.2));
stroke(black);
drawNumber(corridorWidth,tX(0.1),y1+tY(corridorWidth/2));
arrowLine(tX(0.3),tY(livingRoomWallWindow),tX(0.3),tY(livingRoomWallWindow)-tY(corridorWidth));
drawNumber(corridorLength,tX(corridorLength-0.4),y1+tY(corridorWidth/5));
arrowLine(0,y1+tY(corridorWidth/4),tX(corridorLength),y1+tY(corridorWidth/4));
x1 = tX(corridorLengthBeforeBathroomDoor+bathroomDoorWidth);
float dx = x1-x2;
x2 = tX(corridorLength);
line(x1,y1,x2,y2);
stroke(gray);
arc(x1-dx,y1,2*dx,dx-doubleLineWidth,0, HALF_PI);
stroke(black);
float[] livingRoomEntryDoorLine = {tX(corridorLength),tY(livingRoomWallWindow),tX(corridorLength),tY(livingRoomWallWindow)-tY(corridorWidth)+tY(closetWidth)};
line(livingRoomEntryDoorLine[0],livingRoomEntryDoorLine[1],livingRoomEntryDoorLine[2],livingRoomEntryDoorLine[3]);
float d = -tX(0.1);
stroke(gray);
arrowLine(livingRoomEntryDoorLine[0]+d,livingRoomEntryDoorLine[1],livingRoomEntryDoorLine[2]+d,livingRoomEntryDoorLine[3]);
stroke(black);
line(x2,y2,x2,2*doubleLineWidth);
x1 = 0;
y1 = tY(livingRoomWallWindow)-tY(corridorWidth)+tY(closetWidth);
x2 = tX(corridorLength);
y2 = y1;
dx = tX(0.4);
stroke(gray);
line(x1,y1,x2,y2);
stroke(black);
line(x2,y1,x2+dx,y2);
stroke(gray);
float yCorridor = tY(livingRoomWallWindow)-tY(corridorWidth);
float[] points = {
x2,yCorridor,
x2+40,yCorridor - 10,
x2+60,yCorridor + 30,
x2+dx,y2
};
bezier(points[0],points[1],
points[2],points[3],
points[4],points[5],
points[6],points[7]);
grayFill = gray;
x2 -= tX(0.3);
y1 += tY(closetWidth/3);
drawNumber(closetWidth,x2,y1);
drawText("skříně",x2-tX(0.4),y1);
stroke(black);
grayFill = black;
translateOff();
}
void drawBathroom() {
translateOn(doubleLineWidth);
float x1 = 3;
float y1 = tY(livingRoomWallWindow)-tY(corridorWidth)-tY(bathFromCorridor);
float dx = tX(corridorLength)-tX(wcFromWall);
float dy = -tY(0.90); //unknown bath size
strokeWeight(2);
line(x1+dx,y1,tX(corridorLength),y1);
strokeWeight(1);
rect(x1,y1,dx,dy);
drawText("vana",x1+(dx/2),y1+(dy/2));
String s = "stoupačky ";
drawText(s, tX(corridorLength)-textWidth(s),y1+(dy/2));
float wcY1 = y1+tY(0.3);
rect(x1+dx,wcY1,tX(wcFromWall)-tX(0.1), tY(0.3)); //wc unknown size
s="WC";
drawText(s,x1+dx+(tX(wcFromWall)/2)-textWidth(s),wcY1+tY(0.15));
x1 = 0;
y1 += dy-3;
float x2=tX(corridorLength);
line(x1,y1,x2,y1);
y1 -= doubleLineWidth;
line(x1,y1,x2,y1);
x1 = 5;
y1= wcY1; //tY(livingRoomWallWindow)-tY(corridorWidth)-tY(0.3); //unkown position
dx = tX(0.5);
dy = tY(0.3);
rect(x1,y1,dx,dy);
s = "umyvadlo ";
drawText(s,x1+dx-textWidth(s),wcY1+tY(0.15));
float x = x1+dx+tX(0.15);
float y = wcY1;
drawText("60.6 pod umyvadlem", x, y);
drawText("36.1 i se sifonem", x, y+tY(0.13));
translateOff();
}
void drawWallSockets() {
translateOn(doubleLineWidth);
float x1 = 0;
float y1 = tY(livingRoomWallWindow);
float d = tX(0.15);
drawWallSocket(x1+d,y1-d);
y1=0;
x1=tX(flatLength);
drawWallSocket(x1-d,y1+d);
drawWallSocket(x1-(2*d),y1+d);
y1 = tY(livingRoomWallWindow);
drawWallSocketOutOfOrder(x1-d,y1-d);
drawWallSocketOutOfOrder(x1-(2*d),y1-d);
translateOff();
}
void rotatedLine(float x, float y, float angle, float d) {
pushMatrix();
translate(x,y);
rotate(angle);
line(0,0,d,d);
popMatrix();
}
void arrowLine(float x1, float y1, float x2, float y2) {
float d = tX(0.05);
float angle = atan2(y1-y2,x1-x2);
line(x1,y1,x2,y2);
rotatedLine(x1,y1,angle+HALF_PI,d);
rotatedLine(x1,y1,angle-PI,d);
rotatedLine(x2,y2,angle,d);
rotatedLine(x2,y2,angle-HALF_PI,d);
}
void drawWindow() {
float x1 = tX(flatLength)+margin-(2*doubleLineWidth);
float dx = 3*doubleLineWidth;
float y1 = tY(beforeWindow)+margin;
float dy = tY(livingRoomWallWindowWidth);
drawText("okno",x1-tX(0.35),y1+(dy/2));
fill(255);
rect(x1, y1, dx, dy, 20);
y1 += dy + tY(0.1);
dy = tY(enclosedBalconyDoorWidth);
rect(x1, y1, dx, dy, 5);
noFill();
float[] points = {
x1-tX(0.5),y1,
x1-tX(0.55),y1+tY(0.3),
x1-tX(0.6),y1+tY(0.6),
x1+dx,y1+dy
};
line(x1+(2*doubleLineWidth),y1,points[0],points[1]);
stroke(gray);
bezier(points[0],points[1],
points[2],points[3],
points[4],points[5],
points[6],points[7]);
stroke(black);
}
void drawRuler() {
int n = 3;
float x1 = tX(objectWidth+0.7);
float y1 = margin;
float y2 = y1 + tY(3.0);
line(x1,y1,x1,y2);
float step = 10.0;
for (int c = 0 ; c <= n*step ; c++ ) {
float yPos = y1 + tY(c / step);
float l = 5;
if (c % 10 == 0) {
l = 10;
drawNumber(c / step, x1+20,yPos);
}
line(x1-l,yPos,x1+l,yPos);
}
}
void setup() {
if (language=="English") {
Czech2Eng(languageHashMap);
}
scaleWidth = min(scaleWidth,scaleHeight);
scaleHeight = scaleWidth;
if (pdfFile!=null) {
size(windowWidth,windowHeight,PDF,pdfFile);
} else {
size(windowWidth,windowHeight);
smooth();
}
background(255,255,255);
noFill();
noLoop();
}
void draw() {
drawFlat();
drawCorridor();
drawBathroom();
drawWallSockets();
drawWindow();
drawRuler();
//println(squaredMeters);
//println(squaredMetersTotal);
if (pdfFile!=null) {
exit();
} else if (picture!=null) {
saveFrame(picture);
}
}
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment