Thyme

「Thyme」の編集履歴(バックアップ)一覧に戻る

Thyme - (2009/03/22 (日) 01:14:23) のソース

β5が公開されました。実に7ヵ月ぶりのバージョンアップです。
|注意:&br()β5でもβ4.22以前のファイルを開くことができますが、β3.5→β4.22のバージョンアップのときと同様、完全な互換性が保障されているわけではないので、動作が変わってしまうのが嫌な場合は、β4.22も残しておきましょう。&br() また、久しぶりのバージョンアップであること、大規模な変更が行われていること、近日のテストバージョンのアップデートの頻度が高いことから、今後数日の間は、頻繁にバージョンアップが行われるだろうと予想されます。&br() 何度もインストールをするのは面倒だという場合は、少し様子を見た方が良いでしょう。|

今回のバージョンアップの目玉の一つとして、スクリプトの機能拡張が挙げられます。

このThymeスクリプトを使用すると、例えば、[[時間に合わせて引力の値が変化する図形>http://www.phunland.com/phunbox/details.php?id=17651]]を作ることができます。

以下の文章は、Phunβ5.25に同梱されている、Thyme.cfgの内容を訳したものです(読みやすさのために、訳者の補足説明も地の文として表示しています)。

----

ThymeはAlgodooとPhunにおいて実装されている独自のスクリプト言語です。
基本となる型は4種類あります。Int型、Float型、Bool型、String型です。これらの型を組み合わせて、配列(リスト)や関数を作成することが可能です。
識別子は演算子 := を用いて宣言します。代入には = を使用してください。識別子は型付けされません。

hoge := 7; // 新しい識別子 'hoge' を初期値3で宣言します。
hoge = [hoge, "hello", true];  // 宣言済みの変数 'hoge' をリストとして再定義します。 このリストはヘテロジニアス(Heterogeneous:異種混合)です。
print hoge(1); // このコードは "hello" を返します。()で配列の要素にアクセスしています。
print hoge([0,2]); // このコードは [7, true] を返します。
isEven := (n)=>{ n%2==0 }; // 関数 "isEven" を宣言します。 1つの引数を受取、もし、その値が偶数ならtrueを返す関数です。


for関数が実装されています。
for関数は、Thymeにおけるシンプルなループ構造です。「再帰の上限」が存在する影響で、約50回以上ループさせると警告・もしくはエラーが出ます。
次のように使われます: for(n, (i)->{ ... }); ここで n は関数を呼ぶ回数です。 i は 0, 1, ..., n-2, n-1 受け取ります。
例:
	for(4, (n)=>{print ((n+1) + " bottles of beer on the wall.")})
出力:
	1 bottles of beer on the wall.
	2 bottles of beer on the wall.
	3 bottles of beer on the wall.
	4 bottles of beer on the wall.

for関数は以下のように実装されています。
  for = (n, what)=>{
      n < 0 ? true : {
          for(n - 1, what);
          what(n-1)
      }
  };

他にも関数の定義例があります。
inclusive_range = (min, max)=>{min > max ? [] : {[min] ++ inclusive_range(min + 1, max)}};
infix 2 left: _ .. _ => inclusive_range; // Usage:  1..5 == [1,2,3,4,5]

infix は 演算子を定義します。これを定義しておくと、1..5 が [1,2,3,4,5]と同値になります。
infix 2 left は、おそらく、2変数、左結合という意味です。

<- Thyme.cfgの内容ここまで。

関数は、
関数名 = (引数 [,引数2, 引数3, ...]) => {処理内容}
という形式で定義することができます。


絶対値を返す関数:
  abs = (x) => {x > 0 ? x : -x};
使用例:
  abs(-4)
出力
  4


値を整数に丸める関数(Int型に型変換を行うわけではありません)
  floor = (x) => {x >= 0 ? x - math.mod(x, 1) : (math.mod(x, 1) == 0 ? x : x - math.mod(x, 1) - 1)};
使用例:
  floor(3.14)
出力
  3


距離を返す関数:
  dist = (a, b)=>{((a(0) - b(0)) ^ 2 + (a(1) - b(1)) ^ 2)^0.5};
使用例:
  dist([0, 0], [3, 4])
出力:
  5


rand関数の実装例:
  next_rand = 1;
  rand = () => {next_rand = next_rand * 1103515245 + 12345; (next_rand / 65536) % 32768;};
  srand = (rand_seed) => {next_rand = rand_seed};
(このrand関数は、RAND_MAX := 32767 です。)
使用例:
  rand;
  rand;
出力
  16838
  -27009


図形の衝突時に関数を呼び出すことも可能です。onCollideという属性を利用します。
  onCollide = (e)=>{処理したい内容}
という記述方法で、この処理内容の中では、衝突された図形および衝突した図形の属性の値を、
e.this.collideSet や e.other.color
で手に入れることができます。thisはスクリプトの書かれている図形、otherは衝突した図形です。
その他、e.posで衝突した位置を、e.normalで衝突した面の向きを得ることができます。

例えば、
  Scene.addBox{
    onCollide = (e)=>{Scene.addCircle{ radius = 0.1; collideSet = e.this.collideSet; pos = e.pos}}; 
  }
という図形(この場合はボックス)をPhunで作成すると、衝突する度に、衝突した位置に半径が0.1メートルで衝突グループが図形と同じ円(まる)が出る図形の完成です。※このスクリプトのままだと、物体が出続けてしまいます。
他に、
[[衝突するたびに色や密度の変化する図形>http://www.phunland.com/phunbox/details/17509]]
[[スコアボード>http://www.phunland.com/phunbox/details.php?id=17453]]
[[色の読み取り>http://www.phunland.com/phunbox/details/17600]](Scene.my.で独自の変数recognitionを定義しています。)
などの例があります。
純粋なシミュレーションではなく、主にゲーム目的に広く応用できそうな機能と言えるかもしれません。

----


(以下の情報はβ5以前のものです。)

このページは、本家Wikiの[[Thyme>http://www.phunland.com/wiki/Thyme]]の内容を基にしています(本家の方が情報が新しいです)。

'''Thyme'''は、Phun内部につくられたスクリプト言語です。[[Emil氏>http://www.phunland.com/wiki/Emil]]により開発され、重力の大きさなどの値を変更するのに使用されます。
このスクリプトは、[F11]を押して現れるコンソール画面で入力するか、.phnファイル内に埋め込むか、背景にペーストすることで効力を発揮します。なお、[F11]を押して現れるコンソール画面上では、Tabを入力することで自動補完されます。
現在のところループ文(繰り返し文。いわいるfor文)や条件分岐(いわいるif文)は存在しません。
どちらかというとマクロに近い?

変数は何に使用されるかによってグループ分けされています。
グループ:
&link_anchor(APP.){APP.}
&link_anchor(Console.){Console.}
&link_anchor(FileInfo.){FileInfo.}(new since Beta 4)
&link_anchor(GUI.){GUI.}(not the same as &link_anchor(App.GUI.){App.GUI.})
&link_anchor(Keys.){Keys.}
&link_anchor(math.){math.}
&link_anchor(Resources.){Resources.}
&link_anchor(SPH.){SPH.}
&link_anchor(Scene.){Scene.} (new since Beta 4)
&link_anchor(Sim.){Sim.}
&link_anchor(System.){System.}

*&aname(APP.,option=nolink){App.}
App.はレンダリングに関する設定を扱います。

変数のリスト:
|変数名||変数型||説明|
|Background.                  || sub group              || See &link_anchor(App.Background.){App.Background.}|
|DPI                          || positive integer value || The amount of dots per inch to render with|
|GUI.                         || sub group              || See &link_anchor(App.GUI.){App.GUI.}|
|autosaveTime                 || decimal positive value || The interval in minutes between autosaves|
|borderWidth                  || decimal positive value || The width of the borders around objects|
|borders                      || true or false          || Sets if borders should be rendered|
|chainDensityFactor           || decimal positive value || The density per circle in a chain divided by two|
|dragToolStrength             || decimal positive value || The strength multiplier per distance unit for the drag tool|
|drawBCs                      || true or false          || If collision radius should be visible|
|drawBodyCenters              || true or false          || If the center of the object should be visible as a dot|
|drawCollisions               || true or false          || If collision lines should be drawn|
|drawMapOBBs                  || true or false          || If the oriented bounding box map should be visible|
|drawOBBs                     || true or false          || If the minimum oriented bounding box|
|drawParticleCenters          || true or false          || If the center of particles (water) should be drawn as a dot|
|drawVertices                 || true or false          || If the vertices on polygons should be drawn as a dot|
|fadeRotate                   || decimal value          || How many degrees should already been colored in when you start a rotate|
|fadeScale                    || array of two decimal values || Used in GroovyOn, easteregg function|
|fadeTranslate                || array of two decimal values || Used in GroovyOn, easteregg function|
|language                     || string				|| Language of the user interface|
|lineWidth                    || positive decimal value || Width of the line when drawing|
|maxPointDist                 || positive decimal value || The maximum distance between vertices when drawing. Lower = higher resolution of vertices|
|maxSPHspawn                  || positive integer value || The maximum allowed number of water particles to be created|
|maxUndo                      || positive integer value || The maximum number of undo operations|


&aname(App.Background.,option=nolink){APP.Background.} はPhunの背景の空に関係のある変数のグループです。

変数のリスト:
|変数名||変数型||説明|
|cloudOpacity || positive decimal value || The opacity of the clouds|
|drawClouds   || true or false          || if clouds should be drawn|
|skyColor     || four positive decimal values || The RGBA color code for the sky color.|


&aname(App.GUI.,option=nolink){App.GUI.}はGUIに関する設定を扱います。

変数のリスト:
|変数名||変数型||説明|
|drawHingesWhenRunning || true or false || If hinges should be visible during the simulation|
|drawInside            || true or false || If it should be possible to draw inside objects|
|leftClickMenus        || true or false || If left mouse click opens the menus|
|zoomFactor            || decimal positive value || The amount your zoom increases when zooming in and out|

*&aname(Console.,option=nolink){Console.}
The console group sets console-related variables. 
|変数名||変数型||説明|
|clear      || function                     || Clears the console window|
|color      || four positive decimal values || The RGBA color code for the console window|
|delay      || positive decimal value       || The amount of seconds it takes before the console appears|
|fade       || true or false                || If the console window should fade in transparency lengthwise|
|screenSize || positive decimal value       || How much of the screen should be covered by the console. 0.0 = 0%, 1 = 100%|
|scroll     || true or false                || If the console window should scroll in view, or fade in view when opened|


*&aname(FileInfo.,option=nolink){FileInfo.}
FileInfo.(ファイル情報)はファイルの作者名・タイトル・説明 を扱います。

変数のリスト:
|変数名||変数型||説明|
|author                      || string || Defines the author of a file|
|description                 || string || Gives a description of the file|
|title                       || string || The title of the file|
|version                     || string || Version of thyme used to make the file|


*&aname(GUI.,option=nolink){GUI.}
GUI handles things related to the user interface. Stuff like font rendering and size of the user interface.

変数のリスト:
|変数名||変数型||説明|
|clickTimeTolerance || positive decimal value || how long time in seconds before a click is no longer a click|
|clcikTolerance || positive decimal value || how far in pixels the mouse may move before a click is not longer a click|
|crispFontFactor|| positive decimal value || amount of crispiness on the fonts.. Don't touch, default is good enough|
|crispFonts|| 	 true or false  || Whether or not to use crisp fonts|
|font|| string || what font to use. Only fixedsys and arial_black are supported as of now|
|fontShadow||  true or false || whether or not to render shadows of text|
|fontShadowOffset|| array of two decimal values || XY offset of shadow|
|forceOSCursor|| true or false || force operating system cursor or use the phun cursors|
|opaqueness|| positive decimal value || transparency of user interface|
|scale||positive decimal value || scale of user interface|

*&aname(Keys.,option=nolink){Keys.}
Keys only has one function: bind
This function is used to bind a piece of code to a key press:
Keys.bind("space", {Sim.running = ! Sim.running});

*&aname(math.,option=nolink){math.}
Math doesn't contain any variables, only functions and a constant.
|変数名||変数型||説明|
|acos(x) || function, x = decimal        || returns the inverse cosine of the number entered |
|add(x,y) || function, x & y = decimal     || adds two numbers together|
|asin(x) || function, x = decimal        || returns the inverse sine of the number entered |
|atan(x) || function, x = decimal        || returns the inverse tangent of the number entered  |
|cos(x) || function, x = decimal         || returns the cosine of the number entered  |
|divide(x,y) || function, x & y = decimal  || divides x by y |
|multiply(x,y) || function, x & y = decimal|| multiplies x by y |
|negate(x) || function, x = boolean      || flips the value of x |
|pi || constant || gives a value of 3.1415926535.... |
|sin(x) || function, x = decimal         || returns the sine of the number entered  |
|subtract(x,y) || function, x & y = decimal|| subtracts y from x |
|tan(x) || function, x = decimal         || returns the tangent of the number entered  |


*&aname(Resources.,option=nolink){Resources.}
Resources handles things most phun users shouldn't worry about. It gives access to things like 16 bit textures, shaders and other resources.

変数のリスト:
|変数名||変数型||説明|
|force16BitTextures || true or false || whether or not 16 bit color-mode should be used|
|loadAll || function || loads all resources into the ram|
|reloadAll || function || reload all resources|
|reloadShaders || function || reload only shaders|
|reloadTextures || function || reload only textures|
|shaders || true or false || whether or not shaders should be used|
|unloadAll || function || unload all resources|

|vramUsage || read-only decimal positive value || how much bytes of video RAM are used by Phun|

*&aname(SPH.,option=nolink){SPH.}
SPH is short for [[Smoothed Particle Hydrodynamics>http://en.wikipedia.org/wiki/Smoothed_particle_hydrodynamics]], the method used forsimulating fluids in Phun. The SPH particles represent the fluid flow, and thus also the fluid density and velocity field. Particles are affected by a pressure force, a viscosity force, and various external forces (gravity and boundary conditions). The pressure force attempts to conserve the fluid volume, but with the size of the timesteps used in Phun, you will notice that Phun fluids are much more compressible than e.g. water is.

This is a list of variables used for SPH in Phun:
|変数名||変数型||説明|
|SPH.AVG_density || decimal positive value || average density of the water (related to pressure)|
|SPH.AVG_neighCount|| decimal positive value || average number of neighbouring drops of water |
|SPH.AVG_pressure|| decimal positive value || average pressure exerted on the water|
|SPH.bucketSize|| decimal positive value || use when checking SPH neighbourhood. Changing this value should not affect behavior, but may affect performance.|
|SPH.density|| decimal positive value || the weight of a water droplet.|
|SPH.friction|| decimal positive value || the amount of friction experienced between two water droplets.|
|SPH.hashInfo|| function || gives information about the water. Bucket size, number of particles and average bucket size|
|SPH.influence|| decimal positive value || the influcence radius of an SPH particle. A larger value will give a slower, but maybe more stable, simulation.|
|SPH.jitter|| decimal positive value || adds random movement to the SPH particle. The larger the value, the stronger forces. A value of 0 means no jitter.|
|SPH.pressMultiplier|| decimal positive value || multiplication factor of pressure forces|
|SPH.radius|| decimal positive value || the size of a water droplet.|
|SPH.restitution|| decimal positive value || the amount of bounciness of the water|
|SPH.soundSpeed|| decimal positive value  || the update frequency of the water system|
|SPH.specialPressure|| true or false || changes to a different pressure averaging formula|
|SPH.surfaceTension|| decimal positive value  || not used|
|SPH.vaporizeTime || decimal positive value || the time that a water droplet can be idle before it disappears.|
|SPH.viscMultiplier|| decimal positive value || multiplication factor of viscosity forces|
|SPH.viscosity|| decimal positive value || the viscosity of the water|

*&aname(Scene.,option=nolink){Scene.}
Scene gives access to mostly phun file related functions, like adding or deleting objects.
|変数名||変数型||説明|
|Camera. || sub-group || see &link_anchor(Scene.Camera.){Scene.Camera.}|
|Clear || function || clears the entire scene of objects and water|
|EraseWater || function || clears only water|
|New || function || creates a new scene, and resets all scene variables to default|
|addBox || function || adds a box|
|addCircle || function || adds a circle|
|addFixjoint || function || adds a fixate|
|addGroup || function || adds a group|
|addHinge || function || adds a hinge|
|addPen || function || adds a pen|
|addPlane || function || adds a plane|
|addPolygon || function || adds a complex polygon|
|addSpring || function || adds a spring|
|addWater || function || adds water|
|addWidget || function || adds a window|
|author || string || author of the file|
|description || string || description of file|
|title || string || title of file|
For information about the addXXX functions, please look at the [[phn形式について]]


&aname(Scene.Camera.,option=nolink){Scene.Camera.} is a subgroup of &link_anchor(Scene.){Scene.} , and has the variables of the camera: zoom and pan. 
|変数名||変数型||説明|
|pan || array of two decimal values || XY position of the camera |
|zoom || positive decimal value || zoom factor of camera|

*&aname(Sim.,option=nolink){Sim.}
Sim is a pretty big group, with a lot of variables that govern the simulation. You can set the accuracy of the sim, and influences like friction.
You can also define if some parts of the physics engine should be used or not.
A lot of these variables concernes the inner workings of the Phun physics solver. Touch at your own peril!

|変数名||変数型||説明|
|adHocSolver || true or false || if true, switches from [[SPOOK>http://www.phunland.com/wiki/SPOOK]] to a different and more basic solver. default is false|
|airDensity || positive decimal value || density of the air|
|airFrictionLinear || positive decimal value || linear friction of the air |
|airFrictionQuadratic || positive decimal value || quadratic friction of the air|
|airSwitch || true or false || whether air friction is enabled or not|
|defaultBodyDensity || positive decimal value || default density of objects|
|defaultBodyFriction || positive decimal value || default friction of objects|
|defaultBodyRestitution || positive decimal value || default bounciness of objects|
|fallLimit || positive decimal value || the limit of when an object gets deleted after falling outside of the screen|
|gravity || array of two decimal values || X and Y force of gravity|
|gravitySwitch || true or false || whether gravity is enabled or not|
|leapFrog || true or false || if false, switches to euler integration instead of leap-frog. true by default.|
|maxPositionCorrection || positive decimal value || sets the maximum penetration used when applying impulses in constraint violations. Set to infinity by default.|
|prioritizedSolver || true or false || if set to true, will yield a more stable, but far slower, constraint solver.|
|rotFrictionLinear || positive decimal value || linear rotational friction|
|running || true or false || whether the simulation is running or not|
|solveAccFactor || positive decimal value || sets how much the solver will conuter-act acceleration differences between two constrained bodies. Set to 1 by default. Don't touch.|
|solveConstant || positive decimal value || Affects the [[SPOOK>http://www.phunland.com/wiki/SPOOK]] solver. Don't touch!|
|solveDconstraints || positive decimal value || The number of time steps the [[SPOOK>http://www.phunland.com/wiki/SPOOK]] solver will aim to satisfy a hinge contraint within. A low number means faster convergence; a high number means more damped and stable simulation.|
|solveDcontacts || positive decimal value || The number of time steps the [[SPOOK>http://www.phunland.com/wiki/SPOOK]] solver will aim to satisfy c contact within. A low number means faster convergence; a high number means more damped and stable simulation.|
|solveDistFactor || positive decimal value || sets how much the solver will conuter-act penteration in constraint violation. Set to 1 by default. Don't touch.|
|solveIter || positive decimal value || the number of constraint solving iterations. A higher number means a more stable simulation.|
|solvePenetrationDamping || true or false || not used.|
|solvePreSortConstraints || true or false || sets if the constraints will be ordered by violation amount before solving them. true by default.|
|solveRegularizationFactor || positive decimal value || Affects the amount of regalurization in the [[SPOOK>http://www.phunland.com/wiki/SPOOK]] solver. Set to 1 by default.|
|solveVelFactor || positive decimal value || sets how much the solver will conuter-act velocity differences between two constrained bodies. Set to 1 by default. Don't touch.|
|springForce || positive decimal value || this is the value by which spring strengths are multiplied. Alterning this will change the strength of all springs.|
|targetPenetration || positive decimal value || sets how much penetration is allowed in a contact|
|time || constant positive decimal value || number of seconds the simulation has been running|
|timeDelta || positive decimal value || time between two physics engine solvings|
|timeFactor || positive decimal value || sets the simulation speed. A value of 1 means realtime.|
|warmStart || true or false || whether or not to apply forces at sim start|
|warmStartFactor || positive decimal value || multiplication value of warm-start forces existing at sim start|

*&aname(System.,option=nolink){System.}
System is the object that handles certain system-related settings. Be careful when you don't know what you're doing!

List of variabled in the System scope:
|変数名||変数型||説明|
|antiAlias  || positive integer value || determines the amount of antialias used|
|depth      || positive integer value || color depth|
|exit       || function               || shuts down the game|
|fullscreen || true or false          || sets phun to fullscreen and back|
|maxFPS     || decimal positive value || the maximum allowed FPS|
|minFPS     || decimal positive value || the minimum allowed FPS|
|objectCurrent || Read only positive integer value || don't touch|
|objectHandleCurrent || Read only positive integer value || don't touch|
|objectTotal  || Read only positive integer value || the total amount of objects|
|recreateWindow || function           || rebuilds the main window|
|resizable      || true or false      || if the window can be resized or not|
|resolution     || array of 2 positive integers || the resolution of the window|
|screenshot     || function           || makes a screenshot of the window|
|time           || decimal positive value || the amount of seconds the game has been running|
|vSync          || true or false      || if vSync is enabled|
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。