
NB. Created app def file is as follows

NB. ====================================================================================================
NB. ====  (1/4) name of application =======

NB./*/APP_FOLDER_NAME/50_print_a_beautiful_triangle_with_figure_length_calculation
NB. 

NB. ====================================================================================================
NB. ====  (2/4) design of HTML doc  =======

NB./*/HTML_TITLE/a_beautiful_triangle
NB./*/HTML_REMARK/beautiful triangle formed with numbers (original function by Toshio Nishikawa and modified by Yuji Suda)
NB.
NB./*/triangle with numbers
NB./*/NEWLINE
NB./*/TEXTBOX/00/HORIZONTAL/4/column number/5
NB./*/TEXTBOX/01/HORIZONTAL/4/horizontal connection number/4
NB./*/TEXTBOX/02/HORIZONTAL/4/vertical connection number/2
NB. 
NB./*/HORIZONTALLINE
NB./*/selection for shape and connection option
NB./*/NEWLINE
NB./*/RADIOBUTTON/00/HORIZONTAL/selection for shape/yamagata+yamagata/diamonde+diamond
NB./*/NEWLINE
NB./*/RADIOBUTTON/01/HORIZONTAL/connection/No+no/Yes+yes
NB. 

NB. ====================================================================================================
NB. ====  (3/4) descrition of J function  =======
NB.define your J function(s) which will be used in YOUR_JOB function

NB. 西川　利男氏のオリジナル関数
wr =: 1!:2&2

run =: 3 : 0
n =. y
i =. 0
while. i < n
do.
i =. i + 1
N =. ". i#'1' 
NN =. ". (":N) ,'x'   NB. Nを文字列にして、後ろに'x'を付けて、数値に戻す 
wr ((10 - i)#' ') , ": NN * NN
end. 
'***'
)

NB.　オリジナルから最後の***を非表示にしたもの
run2 =: 3 : 0
n =. y
i =. 0
a =. ''
while. i < n
do.
i =. i + 1
N =. ". i#'1' 
NN =. ". (":N) ,'x'   NB. Nを文字列にして、後ろに'x'を付けて、数値に戻す 
NB. a0 =. ((10 - i)#' ') , ": NN * NN
a0 =. ((10 - i)#' ') , ": NN * NN
NB. wr ((10 - i)#' ') , ": NN * NN
a =. a, a0, CRLF
end. 
a
NB.'***'
)

NB.　オリジナルから最後の***を非表示にし、さらに桁長を最大にそろえたもの
run2b =: 3 : 0
n =. y
i =. 0
a =. ''
while. i < n
do.
i =. i + 1
N =. ". i#'1' 
NN =. ". (":N) ,'x'   NB. Nを文字列にして、後ろに'x'を付けて、数値に戻す 
NB. a0 =. ((10 - i)#' ') , ": NN * NN
a0 =. ((10 - i)#' ') , (": NN * NN), ((10 - i)#' ')
NB. wr ((10 - i)#' ') , ": NN * NN
a =. a, a0, CRLF
end. 
a
NB.'***'
)

NB. 三角で各行長が最大行に等しいもの インデントをなくしたもの
run3 =: 3 : 0
if. y >: 20 do. n =. 19 else. n =. y end.
NB. n =. y
i =. 0
a =. ''
b =. ''
len =. n
while. i < n
do.
i =. i + 1
N =. ". i#'1' 
NN =. ". (":N) ,'x'   NB. Nを文字列にして、後ろに'x'を付けて、数値に戻す 
NB. a0 =. ((10 - i)#' ') , ": NN * NN
a0 =. ((len - i)#' ') , (": NN * NN), ((len - i)#' ')
NB. wr ((10 - i)#' ') , ": NN * NN
a =. a, a0, CRLF
b =. b, a0  NB. no addition of CRLF
end. 
D_WIDTH =: $ a0
D_HEIGHT =: n NB. (n * 2) - 1

NB. D_TXTはテキストデータ型　行末にCRLFがあるのでHTMLで直接テキスト出力可能
NB. グローバル変数として作っているので、外部関数で参照可能
D_TXT =: a

NB. J_TXTはJの配列型
J_TXT =: (D_HEIGHT, D_WIDTH) $ b

a
NB.'***'
)

NB.　逆三角形出力
run3r =: 3 : 0
if. y >: 19 do. n =. 18 else. n =. y end.
NB. n =. y
n =. n + 1
i =. n
a =. ''
b =. ''
len =. n
while. i > 1  NB.< n
do.
i =. i - 1
N =. ". i#'1' 
NN =. ". (":N) ,'x'   NB. Nを文字列にして、後ろに'x'を付けて、数値に戻す 
NB. a0 =. ((10 - i)#' ') , ": NN * NN
a0 =. ((len - i)#' ') , (": NN * NN), ((len - i)#' ')
a0 =. 1 }. a0
a0 =. _1 }. a0
NB. wr ((10 - i)#' ') , ": NN * NN
a =. a, a0, CRLF
b =. b, a0
end. 
D_WIDTH =: $ a0
D_HEIGHT =: n -1 NB. (n * 2) - 1

NB. D_TXTはテキストデータ型　行末にCRLFがあるのでHTMLで直接テキスト出力可能
NB. グローバル変数として作っているので、外部関数で参照可能
D_TXT =: a

NB. J_TXTはJの配列型
J_TXT =: (D_HEIGHT, D_WIDTH) $ b

a

NB.'***'
)

NB. 三角＋逆三角でダイヤモンド型に表示したもの
run4 =: 3 : 0
if. y >: 20 do. n =. 19 else. n =. y end.
i =. 0
a =. ''
b =. ''
len =. n
while. i < n
do.
i =. i + 1
N =. ". i#'1' 
NN =. ". (":N) ,'x'   NB. Nを文字列にして、後ろに'x'を付けて、数値に戻す 
NB. a0 =. ((10 - i)#' ') , ": NN * NN
a0 =. ((len - i)#' ') , (": NN * NN), ((len - i)#' ')
NB. wr ((10 - i)#' ') , ": NN * NN
a =. a, a0, CRLF
b =. b, a0
end. 
NB. repeat in reverse
NB. i =. 0
i =. n
while. i > 1 NB.< n
do.
i =. i - 1
N =. ". i#'1' 
NN =. ". (":N) ,'x'   NB. Nを文字列にして、後ろに'x'を付けて、数値に戻す 
NB. a0 =. ((10 - i)#' ') , ": NN * NN
a0 =. ((len - i)#' ') , (": NN * NN), ((len - i)#' ')
NB. wr ((10 - i)#' ') , ": NN * NN
a =. a, a0, CRLF
b =. b, a0
end. 
D_WIDTH  =: $ a0
D_HEIGHT =: (n * 2) - 1

NB. D_TXTはテキストデータ型　行末にCRLFがあるのでHTMLで直接テキスト出力可能
NB. グローバル変数として作っているので、外部関数で参照可能
D_TXT =: a

NB. J_TXTはJの配列型
J_TXT =: (D_HEIGHT, D_WIDTH) $ b
a  NB. 1
NB.'***'
)

char_matrix_to_CRLF_added_str =: 3 : 0
total_row =. 0{$y
cnt =. 0
result =. ''
while. cnt < total_row do.
   aRow =. cnt { y
   result =. result, aRow, CRLF
   cnt =. cnt + 1
end.
result
)

NB. ====================================================================================================
NB. ====  (4/4) desctiption of your job based on POSTed data as argument of J function =======

YOUR_JOB =: 3 : 0

NB.受信データのモニター
   a_monitor =. monitor_entry_ID_values 0

try.
NB.   print 'これから実行します＊＊＊＊＊＊'
   print 'now execute computation.....'
   ketasu =. ".TEXTBOX_00_VALUE
   yoko_renketsu_su =. ". TEXTBOX_01_VALUE
   tate_renketsu_su =. ". TEXTBOX_02_VALUE
   katachi =. RADIO_00_VALUE
   renketsu_umu =. RADIO_01_VALUE

   print 'ketasu = ', ":ketasu
   print 'yoko_renketsu_su = ', ":yoko_renketsu_su
   print 'tate_renketsu_su = ', ":tate_renketsu_su
   print 'katachi = ', katachi
   print 'renketsu_umu = ', renketsu_umu 

   if. katachi -: 'yamagata' do.
        kekka0 =. run3 ketasu
        kekka =. D_TXT
   end.
   if. katachi -: 'diamond' do.
        kekka0 =. run4 ketasu
        kekka =. D_TXT
   end.
   
   if. renketsu_umu -: 'yes' do.
        NB. do yoko_renketsu and tate_renketu with J_TXT and 
        NB. convert matrix to CRLF added string
        if. yoko_renketsu_su > 1 do.
          cnt =. 1
          result_yoko =. J_TXT,.J_TXT
          cnt =. cnt + 1
          while. cnt < yoko_renketsu_su do.
             result_yoko =.result_yoko,.J_TXT
             cnt =. cnt + 1
          end.
        end.
        if. tate_renketsu_su > 1 do.
          cnt =. 1
          result_tate =. result_yoko, result_yoko
          cnt =. cnt + 1
          while. cnt < tate_renketsu_su do.
             result_tate =.result_tate, result_yoko
             cnt =. cnt + 1
          end.
        end.
        kekka =. char_matrix_to_CRLF_added_str result_tate
   end.
   
   process_msg =. a_monitor, CRLF, 'result is as follows', CRLF, kekka

catch.
   process_msg =. 'Error has occurred in the execution'
end.
NB. この関数の戻り値はストリングでなければなりません。
process_msg
)
NB. end of file

