{"id":4,"date":"2013-01-09T16:07:42","date_gmt":"2013-01-09T03:07:42","guid":{"rendered":"http:\/\/wp.davidbrebner.com\/?p=4"},"modified":"2022-11-18T05:01:53","modified_gmt":"2022-11-17T16:01:53","slug":"test","status":"publish","type":"post","link":"https:\/\/davidbrebner.com\/?p=4","title":{"rendered":"UMAJIN script introduction"},"content":{"rendered":"<h2>Why<\/h2>\n<p>UMAJIN \u201cYou Imagine\u201d<\/p>\n<p>The purpose of the UMAJIN script is to be a domain specific language which makes developing rich interactive applications easier and more natural.  It has properties of a declarative file format and a programming language.  Umajin was originally a virtual machine but has been compiled using LLVM since 2005.<\/p>\n<p>The goals of the framework are<\/p>\n<ul>\n<li>Fast development<\/li>\n<li>File size conscious<\/li>\n<li>Native internet<\/li>\n<li>Application performance<\/li>\n<li>Rich content (such as 3D)<\/li>\n<li>Rich inputs (such as touch, voice, pen, depth camera)<\/li>\n<\/ul>\n<h2>What<\/h2>\n<p>This diagram describes the basic architecture of the three parts of a project. These are the creative assets, the script and the engine.<\/p>\n<p><img decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"wp-content\/uploads\/2013\/01\/diagram.png\" \/><\/p>\n<p><strong>Creative Assets<\/strong><\/p>\n<p>The UMAJIN engine is able to load, play and render a wide range of content. Most common formats for images, audio and video are supported. There is support for fonts, 3D content, animation and Unicode text. The idea is to support the creative efforts of designers to create the most rich and interactive applications possible.<\/p>\n<p><strong>UMAJIN script<\/strong><\/p>\n<p>The UMAJIN script is a language for describing objects and logic. The language is designed with a low pattern syntax and object oriented features for lightweight reuse. This means that there are only a few keywords required and the syntax follows standard patterns.<\/p>\n<p>For example the declare pattern is;<\/p>\n<p><code>[keyword] [type] [name]<\/code><\/p>\n<p>This pattern can be used to declare visible objects, abstract classes, properties or local variables;<br \/>\n<code><\/code><\/p>\n<ul>\n<li>instance image my_image<\/li>\n<li>define image my_imageclass<\/li>\n<li>property int my_propint = 5<\/li>\n<li>int my_localint = 5<\/li>\n<\/ul>\n<p>The language is kept simple to master with only 10 core keywords;<\/p>\n<ul>\n<li>Instance<\/li>\n<li>Define<\/li>\n<li>If<\/li>\n<li>Loop<\/li>\n<li>Method<\/li>\n<li>Raise<\/li>\n<li>Property<\/li>\n<li>End (ends all blocks)<\/li>\n<li>In (for time based method calls, or assignments)<\/li>\n<li>Tween (used for time based assignments which will be animated)<\/li>\n<\/ul>\n<p>The object orientated syntax allows for very simple encapsulation of composite objects with custom methods and events. The key aim is lightweight reuse.<\/p>\n<p>The base objects and composite objects built from them &#8211; support declarative programming. This is where other users (potentially using the GUI) can create functional visual programs by creating instances of your objects, setting properties and binding logic to their events.<\/p>\n<p>The language is strongly typed, but allows coercion.<\/p>\n<p><strong>UMAJIN engine<\/strong><\/p>\n<p>This is runtime system which the language binds to.  The engine supports the creation and management of visual objects and simulating, temporal assignments, animation, media and physics.<\/p>\n<p>The rich object model is very important to productive development and includes items such as;<\/p>\n<ul>\n<li>Image<\/li>\n<li>Video<\/li>\n<li>Database<\/li>\n<li>http<\/li>\n<li>http_server<\/li>\n<li>Sound<\/li>\n<li>3D<\/li>\n<li>Shapes<\/li>\n<li>Text<\/li>\n<li>Web<\/li>\n<li>I\/O<\/li>\n<li>Timer<\/li>\n<li>Webcam<\/li>\n<\/ul>\n<p><\/p>\n<h2>How<\/h2>\n<p><strong>The Language<\/strong><\/p>\n<p>Declarative programming &#8211; Objects form the skeleton of declarative programs.  The programmer creates instances of the different classes of objects to form the visual basis of a document or application.  The programmer can then set the properties of these objects to adjust their appearance or behaviour.<\/p>\n<p>Objects can be \u2018nested\u2019 into hierarchies.  For example a button can be placed inside a panel.  As a result visual properties such as position and scale are inherited.  When you move the panel, the child button will move with it.<br \/>\nObjects also have methods.  Methods contain code which performs operations.  Methods can also bind to events which are raised by users.  For example clicking the mouse.<\/p>\n<p>An important concept in this style of programming is called sub-classing.  This is where a new \u2018sub\u2019 class is created from a parent class.  This is also known as the new class \u2018inheriting\u2019 from its parent.  This is used to create new and more complex classes from the original object model.<\/p>\n<p>New programmer created classes can also have custom properties, methods and events.<\/p>\n<blockquote><p><strong>Glossary<\/strong><\/p>\n<p>Object : A discreet bundle of components \u2013 often relating to a visual element (a button) or an abstract real world analogy (a customer).  The keyword INSTANCE is used to create an instance of a class, otherwise known as an object.<\/p>\n<p>Class : A class is the definition of a new type of object.  The keyword DEFINE is used to create a sub-class which is based on an existing class.<\/p>\n<p>Property : An attribute of an object represented by a value which has one of the UMAJIN types. <\/p>\n<p>Function : An action that can be performed on this object.  This is called a METHOD and will take parameters to help describe what it should do.  A method contains code and can return values.<\/p>\n<p>Event : A class can RAISE an event which triggers the matching named method in an instance of this class (an object). <\/p>\n<p>Code : An ordered list of instructions which are performed and can modify objects and properties and call methods.<\/p><\/blockquote>\n<h2>Declaring<\/h2>\n<p>UMAJIN script is a declarative language.  This means you can literally layout the hierarchy of objects and their properties you want the engine to create for you.<\/p>\n<p><strong>Instance<\/strong><br \/>\nMake an object of class image.  This makes an actual instance of an apple.<\/p>\n<pre>instance image apple\r\n   .filename=\u2019apple.png\u2019\r\nend<\/pre>\n<p><strong>Nested instance<\/strong><br \/>\nMake an object of class image, make another instance inside it.<\/p>\n<pre>instance image apple\r\n    .filename='apple.png'\r\n    <font color=#F00>instance image worm\r\n          .filename='worm.png'\r\n    end<\/font>\r\nend<\/pre>\n<p><strong>Define<\/strong><br \/>\nDefine a new sub-class of image.  This does not create an actual object.<\/p>\n<pre>define image button\r\n    .filename = 'button.png'\r\nend<\/pre>\n<p><strong>Define and Raise<\/strong><br \/>\nBind the new class to handle a mouse down event and in turn raise a custom on release event when an instance is created from this new class.<\/p>\n<pre>define image button\r\n   .filename = 'button.png'\r\n   event on_release()\r\n   method on_mouse_down(int x, int y, int mod)\r\n     raise .on_release()\r\n   end\r\nend\r\n\r\ninstance button mybutton\r\n   method on_release()\r\n   end\r\nend<\/pre>\n<h2>Logic<\/h2>\n<p>Logic or code is a series of instructions which each perform basic tasks which when combined together can create complex behaviours.<\/p>\n<p><strong>Types<\/strong><br \/>\nSeveral basic types are available, these are simpler than full objects and include;<\/p>\n<ul>\n<li>Int \t(int8, uint8, int16, uint16,int32, uint32, int64, uint64)<\/li>\n<li>Real    \t(Real32, Real64)<\/li>\n<li>String<\/li>\n<li>Bool<\/li>\n<li>Vec2, vec3, Mat4<\/li>\n<li>Color<\/li>\n<li>Datetime<\/li>\n<li>Var \t<\/li>\n<\/ul>\n<p><strong>Expressions<\/strong><\/p>\n<p>Programming starts with expressions and assignments.  This is where a variable or property is assigned a value.  The value can be an expression as simple as a single number or contain operators like addition, or calls to methods which return values.<\/p>\n<pre>Real velocity = 2.3\t\t\t(2.3 is the expression, the = is the assignment)\r\nReal speed = velocity * 1.87\t\t(velocity * 1.87 is the expression)\r\nInt length = sqrt((x1-x2)^2+(y1-y2)^2) \t(sqrt is a method inside the expression)<\/pre>\n<p><strong>Conditions<\/strong><\/p>\n<p>Conditions are decisions where code can be branched based on the success or failure of a comparison.  If, else and elseif are the structures provided.  The condition needs to evaluate to non zero to be true and succeed.  Comparison operators can be used to test values.  These include == (equal), != (not equal), > (greater), >= (greater or equal), < (less than), <= (less than or equal).\n\nExample 1 : Simple If block\n\n\n<pre>if velocity>2.1\r\n  \/\/place code here\r\nend\r\n<\/pre>\n<p>Example 2 : If\/Elseif\/Else block<\/p>\n<pre>\r\nif velocity>2.1\r\n  \/\/place code here\r\nelseif velocity==1.5\r\n  \/\/place code here\r\nelse\r\n  \/\/place code here\r\nend\r\n<\/pre>\n<p><strong>Loops<\/strong><\/p>\n<p>Loops allow repeating of a block of logic\/code multiple times.  This code will run until a condition is met.  Loops can be pre AND post tested.<\/p>\n<p>Example 1 : Simple pre tested loop  (Loop if)<\/p>\n<pre>int a=0\r\nloop a<100\r\n   \/\/do something many times...\r\n   a++\r\nend\r\n<\/pre>\n<p>Example 2 : Simple post tested loop  (End if)<\/p>\n<pre>int a=0\r\nloop \r\n   \/\/do something many times...\r\n   a++\r\nend a>100\r\n<\/pre>\n<p><strong>Arrays<\/strong><\/p>\n<p>Often used with loops these are a great way of processing lists of data.  Umajin supports numeric and string indexes.  To access the specific item in a condition, expression or assignment the index is simply specified between the square brackets.<br \/>\nMulti dimensional arrays can also be declared and used by having multiple sets of square brackets.<\/p>\n<p>Example 1 : Declare a basic array<\/p>\n<pre>int my_array[]<\/pre>\n<p>Example 2 : Accessing an array<\/p>\n<pre>string my_array[]\r\nmy_array[1] = \u201ccow\u201d\r\nmy_array[2] = \u201csheep\u201d\r\n<\/pre>\n<p>Example 3 : Use the array in a loop<\/p>\n<pre>int my_array[]\r\nint a=0\r\nloop a<100\r\n   my_array[a] = rnd(100)\r\n   a++\r\nend\r\n<\/pre>\n<p>Example 4 : Declare a 2 dimensional array<\/p>\n<pre>string my_big_array[][]\r\nmy_array[1] [\u201cname\u201d]= \u201ccow\u201d\r\nmy_array[1] [\u201cage\u201d]= \u201c13\u201d\r\nmy_array[2] [\u201cname\u201d]= \u201csheep\u201d\r\nmy_array[2] [\u201cage\u201d]= \u201c3\u201d<\/pre>\n<blockquote><p>Glossary<\/p>\n<p>Expression : a combination of numbers, variables, methods and operators which evaluate to a value.<\/p>\n<p>Assignment : setting a property or variable to a new value (potentially from an expression)<\/p>\n<p>Condition : based on a comparison succeeding or failing branch the flow of the program<\/p>\n<p>Loop : repeat instructions until a condition is met<\/p>\n<p>Type : Applies to the type of an object (e.g. image), or a basic variable (e.g. string, int, real)<\/p>\n<p>Array : A variable which hold more than one value declared by adding square brackets [] <\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Why UMAJIN \u201cYou Imagine\u201d The purpose of the UMAJIN script is to be a domain specific language which makes developing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1543,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[3,4,5],"class_list":["post-4","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-umajin-script","tag-umajin","tag-script","tag-introduction"],"_links":{"self":[{"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/posts\/4","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4"}],"version-history":[{"count":39,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/posts\/4\/revisions"}],"predecessor-version":[{"id":2266,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/posts\/4\/revisions\/2266"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/media\/1543"}],"wp:attachment":[{"href":"https:\/\/davidbrebner.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}