;============制御構造===================
;-----------制御マクロの再定義----------
;while
#define global U_while(%1=1) repeat -1 %c if %1 {
#define global U_wend } else : break %c loop
;do
#define global U_do repeat -1
#define global U_until(%1=1) if %1 : break %c loop
;for
#define global U_for(%1,%2=0,%3=0,%4=1) %tfor_ %s4 %s1 %1 = %2 %c repeat -1 %c if %1 < %3 {
#define global U_next %tfor_ %o += %o %c } else : break %c loop
;-----------------n次foreach--------------------
#define global U_foreach2(%1=0) repeat length2(%1), 0 ;2次元目でforeach
#define global U_foreach3(%1=0) repeat length3(%1), 0 ;3次元目でforeach
#define global U_foreach4(%1=0) repeat length4(%1), 0 ;4次元目でforeach
;==============汎用===============
;------------------------------
;color命令をカラーコード(#ffaa80など)で表せる
;------------------------------
#define global U_color(%1 = "#000000") func_color str(%1)
;----------------getkeyの関数化--------------
#define global U_check_key(%1) cfunc_check_key(int(%1))
;==============数学関連===============
;---------------2点間の距離を求める---------------
#define global ctype U_distance(%1,%2,%3,%4) sqrt((double(%1) - %3) * (double(%1) - %3)+(double(%2) - %4) * (double(%2) - %4));(%1, %2)と(%3, %4)の距離
;-------------べき乗-------------
#define global ctype U_pow(%1,%2) cfunc_pow(%1,%2) ;%1^%2
;-------------度数法三角関数-------------
#define global ctype U_cos_d(%1) cos(deg2rad(%1)) ;cos
#define global ctype U_sin_d(%1) sin(deg2rad(%1)) ;sin
#define global ctype U_tan_d(%1) tan(deg2rad(%1)) ;tan
#define global ctype U_atan_d(%1, %2 = 1) rad2deg(atan(%1,%2)) ;atan
#module mod_user
;==============汎用===============
;------------------------------
;color命令をカラーコード(#ffaa80など)で表せる
;------------------------------
#deffunc func_color str p_RGB, local l_color, local l_s
l_color = p_RGB
if "#" ! strmid(l_color, 0, 1) { dialog "カラーコードの頭に#をつけて下さい。" : end}
if strlen(p_RGB) ! 7 { dialog "カラーコードは6桁の十六進数です。" : end}
repeat 6,1
l_s = strmid(l_color, cnt, 1)
if 0 = (l_s = "0" | l_s = "1" | l_s = "2" | l_s = "3" | l_s = "4" | l_s = "5" | l_s = "6" | l_s = "7" | l_s = "8" | l_s = "9" | l_s = "a" | l_s = "b" | l_s = "c" | l_s = "d" | l_s = "e" | l_s = "f" | l_s = "A" | l_s = "B" | l_s = "C" | l_s = "D" | l_s = "E" | l_s = "F") { dialog "不適当な文字\"" + l_s + "\"が使われています" : end}
loop
color int("$" + strmid(l_color, 1, 2)), int("$" + strmid(l_color, 3, 2)), int("$" + strmid(l_color, 5, 2))
return
;------------------------------
;getkeyを命令から関数に変更
;p_KEY : 調べるキー
;------------------------------
#defcfunc cfunc_check_key int p_KEY, local l_x
getkey l_x, p_KEY
return l_x
;==============数学関連===============
;------------------------------
;べき乗
;BASE : a^bのa
;EXP : a^bのb
;------------------------------
#defcfunc cfunc_pow double p_BASE, double p_EXP, local l_y
l_y = logf(-1);初期値。エラー時用
if p_EXP = int(p_EXP) { ;整数のとき
l_y = 1.0
if 0 <= p_EXP {
repeat int(p_EXP)
l_y *= p_BASE
loop
} else {
repeat abs(int(p_EXP))
l_y /= p_BASE
loop
}
} else {
if 0 < p_BASE : l_y = expf(p_EXP * logf(p_BASE))
}
return l_y
#global
// デバッグ時用クリーンアップ命令
#ifdef _DEBUG
#module
#deffunc _Debug_CleanupStatement_ onexit
exist "obj" : if ( strsize >= 0 ) { delete "obj" }
exist "hsptmp" : if ( strsize >= 0 ) { delete "hsptmp" }
return
#global
#endif
開いてそのまんまコピペ。
制御マクロの再定義はbreak,continue,looplev,cntを共有したかったので作ったもの。U_forは殆ど使ってないから挙動に自信ない。
U_colorはあったことも忘れてた代物。たぶん$で16進数表記ができることも知らなかった最初期の作。
get_keyは関数化したほうが絶対使いやすい!
後は数学関係。
べき乗a^bはpowfが標準定義マクロにもあるけど、単純にe^b*log(a)してるだけでマイナスに対応してないのが気に食わなかったので実数全体に拡張。
ゲームとかで極座標をラジアンで指定すんのは私の頭では無理なので、度数法三角関数は必須。
デバッグ時用クリーンアップ命令はたぶん昔ここで紹介されてたもの…