Doors and Windows
When we think of building something in a new world, the first thing come to mind is to build houses. We have walls already, let's build doors and windows in this lesson.
Gate
With two columns and a beam on the top, we can build a simple gate structure:
Call column()
, bar_x()
# Gate Structure, h:height, w:width
def gate(x,z,h,w,m):
column(x,z,h,m)
column(x+w, z,h,m)
bar_x(x, h, z, w, m)
gate(10, -20, 10, 8, 29) # oak gate
Standard Door
Let's design a standard size door with height:10, width:5, here is the doorFrame
:
# doorFrame, height 10, width 5
def doorFrame(x,z,m):
column(x,z,10,m)
column(x+w, z,10,m)
bar_x(x, h, z, 5, m)
Build a glass door on a wall
The process is: build a stone wall, build a oak door frame in the middle, then inside the frame build a piece of 'diamond' panel (looks like glass)
# useful functions: wall(x,z,h,w,m), doorFrame(x,z,m)
wall(0,-10,40,40, 2) # a stone wall
doorFrame(5, -10, 32) # oak door frame
wall(6,-10,9,4,3) # diamond panel
Or we can build a 'glass_brown'(6) panel inside the door frame that looks like a iron door.
doorFrame(12, -10, 32)
wall(13,-10,9,4, 6) # 'glass_brown'
A Door that can go through
Next thought, what if we want a real door that we can pass through?
Remember in previous lesson about dictionary
and materials
? We can add 'air'
block to materials
dictionary, then build a small piece of 'air'
wall inside the door frame, the effect is removing the stone blocks away and leave a hole inside the frame.
Let's try it:
# add `air` to `materials`
materials['air'] = 0
# make 'air' panel inside door frame
doorFrame(19, -10, 32)
wall(20,-10,9,4, 0) # 'air' panel
Function door(x,z,m)
Wrap up the previous code and define a function to make a door (this door has double frame for better looking)
def door(x,z,m):
materials['air'] = 0 # skip this line if it's already in previous lines
doorFrame(x,z,m)
doorFrame(x,z+1,m)
wall(x+1,z,9,4,0)
# build a door
door(28,-10,50) # a red double frame door
See the picture to understand the process of making a door.
==
save here, for code editor, no auto save now, 10/4/17
#wall
def wall(x,z,h,w,m):
for i in range(x,(x+w)):
column(i,z,h,m)
wall(0,-10,40,40, 2)
materials['air'] = 0
def doorFrame(x,z,m):
column(x,z,10,m) # latest column is columnM
column(x+5, z,10,m)
bar_x(x, 10, z, 5, m)
doorFrame(5, -10, 32)
wall(6,-10,9,4,3)
doorFrame(12, -10, 32)
wall(13,-10,9,4, 6)
doorFrame(19, -10, 32)
wall(20,-10,9,4, 0)
def door(x,z,m):
materials['air'] = 0
doorFrame(x,z,m)
doorFrame(x,z+1,m)
wall(x+1,z,9,4,0)
door(28,-10,50)
# build a window
flat_xy(3,12,-10,9,7, 0)
windowFrame(2,11,-10,10,8, 4)
# window should have even number h, w
def window(x,y,z,h,w,m):
flat_xy(x+1, y+1, z, h-1, w-1, 0) # 'air' panel
windowFrame(x,y,z,h,w,m)
def windowBrown(x,y,z,h,w,m):
flat_xy(x+1, y+1, z, h-1, w-1, 6) # 'glass_brown'
windowFrame(x,y,z,h,w,m)
window(15, 15,-10, 10,6, 44) # light blue
windowBrown(25, 15, -10, 8, 8, 43) # green
==save for now
Windows
We have doors, of cause we need windows.
Process to build a window:
On an existing wall build a 'glass'
or 'air'
panel;
around the glass/air panel build a window frame,
inside the frame, you can add some bars
# bar_x
def bar_x(x,y,z,length, m):
for i in range(x,x+length):
block(i, y, z, m)
# bar_y
def bar_y(x,y,z,length, m):
for j in range(y,y+length):
block(x, j, z, m)
# flat_xy
def flat_xy(x,y,z,h,w,m):
for j in range(y, y+h):
bar_x(x,j,z,w,m)
# window should have even number h, w
def windowFrame(x,y,z,h,w,m):
bar_x(x,y,z,w,m)
bar_x(x, y+h,z,w,m)
bar_y(x,y,z,h, m)
bar_y(x+w, y,z, h+1, m)
bar_x(x, y+h/2, z,w,m)
bar_y(x+w/2, y,z,h,m)
flat_xy(3,12,-10,9,7, 0)
windowFrame(2,11,-10,10,8, 4)
Function: A clear window
def window(x,y,z,h,w,m):
flat_xy(x+1, y+1, z, h-1, w-1, 0) # 'air' panel
windowFrame(x,y,z,h,w,m)
A 'glass_brown' window
def windowBrown(x,y,z,h,w,m):
flat_xy(x+1, y+1, z, h-1, w-1, 6) # 'glass_brown' panel
windowFrame(x,y,z,h,w,m)
See these windows:
window(15, 15,-10, 10,6, 44) # light blue
windowBrown(25, 15, -10, 8, 8, 43) # green
===
(a reminder note: later after learning 'Events', build a 'glass_brown' door, then when clicking on the door knob, the door opens as 'air' door so we can go through. ( at the side, build flat_xz('glass_brown') panel looks like the door is open)