Mobilizing is a programming language made from scratch and not an API constructed on an already existing programming language. However, we decided to make it as similar as possible to standard language on certain points. One point is that data needs to be typed, like in C or Java.
bool : boolean value. Can be only "true" or "false"
-
-
-
-
void : void fonction returning. Specifies that a function cannot return any value
= (assignment) : assign A in B, where A and B have the same type or can be casted, int ↔ float for example.
+ (addition) : adds two numerical expressions
- (subtraction) : subtracts two numerical expressions
* (multiplication) : multiplies two numerical expressions
/ (division) : divides two numerical expressions
% (modulo) : calculates the remainder of two numerical expressions
++ (increment) : adds 1 to its operand (unary, can be used as prefix (++i, increments and use) or postfix (i++,use and increments))
-- (decrement) : subtracts 1 from its operand (unary, can be used as prefix (–i, decrements and use) or postfix (i–,use and decrements))
+= (addition assignment) : adds two numerical expressions and assign to the left operand
-= (subtraction assignment) : subtracts two numerical expressions and assign to the left operand
*= (multiplication assignment) : multiplies two numerical expressions and assign to the left operand
/= (division assignment) : divides two numerical expressions and assign to the left operand
%= (modulo assignment) : calculates the remainder of two numerical expressions and assign to the left operand
== (equality) : tests two expressions for equality
!= (inequality) : tests two expressions for inequality
< (less than) : Compares two expressions and determines if the first one is inferior to the second one
<= (less than or equal to) : Compares two expressions and determines if the first one is inferior or egal to the second one
> (greater than) : compares two expressions and determines if the first is superior to the second one
>= (greater than or equal to) : compares two expressions and determines if the first is the superior or equal to the second one
|| (or) : OR, often used in if() comparison.
&& (and): AND, often used in if() comparison.
! (not): NOT, often used in if() comparison with a bool or int value.
-
else : else, when if test fails.
else if : else condition, when if test fails.
-
-
switch : switch condition control structure.
case : used only with switch to define conditions.
break : breaks (stops) the loop or switch test execution, can be used with while, for and switch only.
To create and use an array, use this way :
int[] arrayInt;
void setup(){
//elements are added dynamically to the array, you can get value with arrayInt[index]
for( int i=0; i<10; i++ ){
arrayInt[i] = i;
}
//to get the number of elements in the array
println( sizeof(arrayInt) );
}
void update(){
}
[ ] Array declaration brackets.
int
sizeof(array_name) : Returns the number of elements inside the array.
void
= (assignement): Assigns a string into a text object.
void
+ (concatenation): Concatenate two strings.
int
compareStrings(string1, string2) : Compares the difference between two strings. If there's no differences, 0 is return, 1 otherwise.
int
sizeof(string) : Returns the string length. !!Can be false when accents are used or with non-latin alphabets!!.
string
getSubstring(base_string, string_to_search) : Search for a certain string and if it's found, return a part of base_string beginning at stringSearch and ending at the end of base_string.
void
setup() : start function
void
update() : update function, launched at each frame
For repetitives tasks, user can construct functions that can take several arguments of any types and return a value
- hello_simpleFunction.txt
//Mobilizing Sample Code
//
//hello_simpleFunction
//
//Dominique Cunin 2010
//
//Demonstrate how to use user made functions
int[] image;//ID Array
int imgTotal = 100;
// Initialize
void setup()
{
exitOnQuit(1);//app will not run in background
for(int i=0; i<=imgTotal; i++){
image[i] = load("sampleData/seq/image"+ i%20 +".png");
setCenter(image[i], getWidth(image[i])/2, getHeight(image[i])/2);
float r1 = random(Width);
float r2 = random(Height);
setPosition(image[i],r1,r2);
}
}
// Refresh Loop
void update()
{
for(int i=0; i<=imgTotal; i++){
if( testIntersects(image[i], TouchX1, TouchY1) ){
setOpacity(image[i],20);
}else{
setOpacity(image[i],100);
}
}
}
//your functions can return int, float, string
int testIntersects(int id, float x, float y){
return intersects(x,y,id);
}
void
framerate(int newrate) : set the global application timer speed in frame by second. Default is 60 (or 60 fps).
void
print(primitve_type value) : console output. int, float or string can be passed.
void
println(primitve_type value) : console output with line feed int, float or string can be passed.
void
showFps() : show the current overall framerate of the application in the bottom-left corner of the screen. For debbuging purpose only : can slow down a little the actual fps!
void
exitOnQuit(int yes_no) : 0 = your application will run in background when the Home Button is pressed. 1 = your application will quit when the Home Button is pressed. Default = 0.
void
disableSleep() : Disable screen sleep to avoid black screen.
void sleep() : set the application to sleep during x secondes
float
random (float maximum) : return a random integer between 0 and the maximum.
float
random (float minimum, float maximum) : return a random integer between the minimum and the maximum.
float
abs (float value) : absolute value.
float
round (float value) : round a float to the nearest integer number.
float
floor (float value) : return the closest integer that is less than or equal to the float
float
ceil (float value) : return the closest integer that is greater than or equal to the float
float
lerp (float value1, float value2, float ponderation) : interpolation (or average) of 2 float values, with ponderation.
float
map (float value, float downScale, float upScale, float down2Scale, float up2Scale) : maps a proportion of value bitween the two scales.
float
norm (float value, float downScale, float upScale) matchs to a proportional scale of 1 (normalize).
float
dist (float x1, float y1, float x2, float y2) : distance bitween 2 points.
float
pow (float value, int pow) : pow.
float
sqrt (float value) : square root.
float
degrees (float value) : converts radians to degrees.
float
radians (float degrees) : converts degrees to radians.
float
cos (float value) : cosinus.
float
acos (float value) : arc cosinus.
float
sin (float value) : sinus.
float
asin (float value) : arc sinus.
float
tan (float value) : tangente.
float
atan (float value) : arc tangente.
float
atan2 (float x, float y) : variation de arc tangente.
int
millis () : time ellapsed from the application start
void setTimer (function name, float delay) : call the function after a delay
int day () : current date day, from 1 to 7
int hour () : current date hour, from 0 to 24
int minute () : current date minute, from 0 to 59
int month () : current date month, from 1 to 12
int second () : current date seconde, from 0 to 59
int year () : current year
Almost every smartphone has built-in accelerometers. This sensors first function is to mesure device relative accelerations, each one on a different axis (x,y,z). As gravity affects them as well as user generated acceleration, many things can be done with accelerometers values. For the iOS devices, here is how they are built :
The following variables reflects the variables we can get from iOS API directly, wihtout any changes.
float
AccX : Accelerometer's X raw value. returns a float.
float
AccY : Accelerometer's Y raw value. returns a float.
float
AccZ : Accelerometer's Z raw value. returns a float.
Functions that allow to obtain filtered values of AccX, AccY et AccZ (smoothed or filtered values). Takes only one argument, 0 = strong filter, 1 = no filter. 0.07 = usually good to use filtering value. Returns a float. If it's very strong, the attenuation can cause a significant discrepancy between the actual orientation of the screen and the value obtained. Basically, the code under these function is a lowpass filter.
Unlike Accelerometers, Gyroscope is a sensor made to mesure the device relative rotation. What can be done with AccGravity variable can be done with gyro in a more reliable (but different) way. Gyro is usefull for real-time 3D navigation, but can be used in many other ways (as Mobilziing can only do small and very limited things in 3D). Gyro is not built-in all mobiles devices, but they are in iPhone 4 and iPod Touch v4.
Here is how it is built-in iOS devices :
bool GyroAvailable : Variable that returns true if Gyro is built-in the device, false if not.
void gyroOn() : turns on gyroscopes (if not available, an error is printed in console).
void gyroOff() : turns off gyroscopes.
void resetGyro() : restart gyroscopes to reset the base reference rotation used to calculate the current device rotation.
iOS use special algorithm to compute device orientation from sensors values. The following variables reflects the variables we can get from iOS API directly, wihtout any changes.
float GyroPitch : returns gyros pitch value (on the x axis) in degrees.
float GyroYaw : returns gyros yaw value (on the y axis) in degrees.
float GyroRoll : returns gyros roll value (on the z axis) in degrees.
float getGyroMatrix(int rotationMatrixElementIndex) : returns one element of the gyroscope rotation matrix generated by the iOS. The matrix is made of 3 row and 3 colones, 9 elements, like this : m11, m12, m13, m21, m22, m23, m31, m32, m33. The index of the element can then be from 0 to 8 with this mapping : m11 (0), m12 (1), m13 (2), m21 (3), m22 (4), m23 (5), m31 (6), m32 (7), m33 (8).
Compass (magnetometer), when used alone can returns the magnetic North, but it is very sensible to magnetic interferences and is not built-in every devices.
void
compassOn() : (function) turns the compass ON, on 3GS and iPhone 4. Set to OFF by default.
void
compassOff() : (function) turns the compass OFF.
float
Compass : (variable) Gives the present value of the compass when the device is whether facing the sky or held in portrait. Value between 0 and 360 based on the magnetic north.
float
CompassLandscape : (variable) Gives the present value of the compass when the device is held in landscape. Value between 0 and 360 based on the magnetic north.
Depending on the device and the available services, iOS can use Wifi and cellular connexion to get a location in space.
void
locationOn() : (function) Set the location service ON. Set to OFF by default.
-
float
Latitude : (variable) Present latitude as a float, if available.
float
Longitude : (variable) Present longitude as a float, if available.
The iPhone, as well as the iPod Touch can't use more than 5 touch, iPad have 10. The following variables allow to retrieve their position on the screen.
int
TouchCount : (variable) return the number of touches actually active.
int
TouchPressed : (variable) return 1 if at least one touch is active, 0 if not.
int
Taps : (variable) returns the number of "taps" (equivalent to a mouse-click count).
int
TouchX1 : (variable) returns the position X of touch 1.
int
TouchY1 : (variable) returns the position Y of touch 1.
int
TouchX2 : (variable) you should understand all the rest…
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
int
getTouchX(int touch_index) : (function) give an easy way to get the x value of a touch using its index. Useful with loops.
int
getTouchY(int touch_index) : (function) give an easy way to get the y value of a touch using its index. Useful with loops.
float
TouchPinch : (variable) Returns the interval between two touches, to easily reprocude the "zoom-in/ zoom-out" effect from the iPhone's User Interface or anything else.
Available only on the iPhone, the proximity sensor is an infared sensor is used to temporally turn the screen off, in order to avoid undesired interaction between the user face and the screen when one is making a call. This sensor can be enabled at any time. When it's occulted by something (your hand or anything), the screen enter in "pause" mode and is shut off. Of type "all or nothing", this sensor returns 0 or 1 only, 0 when nothing occulte the sensor, 1 otherwise.
-
-
int
ProximityState : (variable) information about the state of the proximity senor. Returns 0 or 1.
iPhone can vibrate for a short time. iPod and iPad cannot vibrate.
void
vibrate() : (function) make the iPhone vibrate for a short time. Call this function several times to create longer vibration. This has no effect on iPod and iPad devices.
Microphone can be used as a sensor by using incoming sound volume. By blowing on the mic, sound is produced, which makes the mic a good "blow sensor". Incoming sound can be monitored, or in other word, played through the device speaker (or headphones) in live.
void micOn() : turns microphone on;
void micOff() : turns microphone off;
void micMonitorOn() : turns mic play through on;
void micMonitorOff() : turns mic play through off;
float MicVolume : (variable) returns the current mic input sound volume.
The application orientation can be forced at the very beginning of the setup() function. It is important to set the orientation at first as Width and Height native variables may return different value depending on the choosen orientation.
iOS simulator can be rotated to simulate the device orientation. Obviously, this has no effect on the real device…
void
setSimulatorOrientation(string mode) : Turns the simulator according to the mode given. Possibles modes ar :
"portrait" -
"portrait_inversed" -
"landscape_right" -
"landscape_left".
Note : this
will not rotate the application but only the simulator!
string
DeviceModel : Native Variable returning the name of the iOS Device the current program is running. Possible returning values are : "iPhone 1G", "iPhone 3G", "iPhone 3GS", "iPhone 4", "iPod Touch 1G", "iPod Touch 2G", "iPod Touch 3G", "iPod Touch 4G", "iPad", "iPad 2", "Simulator".
void
setScreenBrightness(float value) : Sets the brightness of the screen (hardware). Value should be between 0 and 100.
Mobilizing provides some global parameters that user can set to the scene. You can use a 3D rendering style in Mobilizing, but keep in mind that Mobilizing is not a 3D engine (yet). All media 2D can use 3 axis for translation or rotation. As a small hack, you can also set the global scene rotation and translation in 3D (like with a camera) when you really wants to acheive 3D like effect, but don't expect 3D engine like fonctions.
void
background(int rgb) : Sets the background color (grayscale mode). Values range is 0-255.
void
background(int r, int g, int b) : Sets the background color (rgb mode). Values range is 0-255.
void
set3DRendering() : Sets 3D rendering On. You should call it in the setup(). In this mode,
every media 2D will be rendered in perspective.
void sceneTranslationX(float x) : sets the scene translation on x axis;
void sceneTranslationY(float y) : sets the scene translation on y axis;
void sceneTranslationZ(float z) : sets the scene translation on z axis;
Some functions are shared by all graphics elements available in Mobilizing. Media 2D means bitmap images, still pictures sequences, geometric shapes and videos. Mobilizing uses the concept of graphical object's local space and scene global space. This means that it is possible to define a reference point of the graphic object that will used during translation and rotation of the object. To work well, the first argument of these functions of transformation and manipulation must be the index of the target media. This index is automatically returned when creating an object:
int image = 0;
void setup(){
image = load("path/to/image.jpg");//here, image variable become a media ID, represented by an int
setVisible(image, 1);//then, this variable can be passed to all manipulation functions.
}
void update(){
}
void
setCenter(int media_id, float x, float y) : Sets the center point of the 2D media. This center will be the reference point for setPosition() and setRotation() (applies to all 2D medias).
void
setCenter(int media_id, float x, float y, float z) : Sets the center point of the 2D media.
void
setCenterX(int media_id, float x) : Sets the center X point of the 2D media (applies to all 2D medias).
void
setCenterX(int media_id, float y) : Sets the center Y point of the 2D media (applies to all 2D medias).
void
setCenterZ(int media_id, float z) : Sets the center Z point of the 2D media (applies to all 2D medias, has no effect when the scene is not rendered in perspective).
float
getCenterX(int media_id) : Gets the center X point of the 2D media (applies to all 2D medias).
float
getCenterX(int media_id) : Gets the center Y point of the 2D media (applies to all 2D medias).
float
getCenterZ(int media_id) : Gets the center Z point of the 2D media (applies to all 2D medias, has no effect when the scene is not rendered in perspective).
void
setPosition(int media_id, float x, float y) : Sets the position of the 2D media on x and y axis (applies to all 2D medias).
void
setPosition(int media_id, float x, float y, float z) : Sets the position of the 2D media on x and y axis (applies to all 2D medias).
void
setPositionX(int media_id, float x) : Sets the position of the 2D media on x axis (applies to all 2D medias).
void
setPositionY(int media_id, float y) : Sets the position of the 2D media on y axis (applies to all 2D medias).
void
setPositionZ(int media_id, float z) : Sets the position of the 2D media on z axis (applies to all 2D medias).
float
getPositionX(int media_id) : Return the present x position of the 2D media (applies to all 2D medias).
float
getPositionY(int media_id) : Return the present y position of the 2D media (applies to all 2D medias).
float
getPositionZ(int media_id) : Return the present z position of the 2D media (applies to all 2D medias).
float
getAbsolutePositionX(int media_id) : Return the present x position of the 2D media (applies to all 2D medias). This is the absolute position of the media. Use this fonction to know where is located a media that you positionned in 3D and rotated. Don't use it if you're not using set3DRendering().
float
getAbsolutePositionY(int media_id) : Return the present y position of the 2D media (applies to all 2D medias). This is the absolute position of the media. Use this fonction to know where is located a media that you positionned in 3D and rotated. Don't use it if you're not using set3DRendering().
float
getAbsolutePositionZ(int media_id) : Return the present z position of the 2D media (applies to all 2D medias). This is the absolute position of the media. Use this fonction to know where is located a media that you positionned in 3D and rotated. Don't use it if you're not using set3DRendering().
float
getRotation(int media_id) : Returns the rotation of the 2D media in degree, clockwise (applies to all 2D medias).
float
getRotationX(int media_id) : Returns the rotation of the 2D media in degree, clockwise (applies to all 2D medias).
float
getRotationY(int media_id) : Returns the rotation of the 2D media in degree, clockwise (applies to all 2D medias).
float
getRotationZ(int media_id) : Synonym of getRotation().
void
setScale(int media_id, float scaleX, float scaleY) : define the scale of the image for x and y.
void
setScaleX(int media_id, float scaleX) : define the scale of the image for x.
void
setScaleY(int media_id, float scaleY) : define the scale of the image for y.
float
getScaleX(int media_id) : Returns the scale of the image for x.
float
getScaleY(int media_id) : Returns the scale of the image for y.
void
setWidth(int media_id) : Sets the width of the 2D media (applies only to
image, arc, rect, ellipse).
void
setHeight(int media_id) : Sets the height of the 2D media (applies applies only to
image, arc, rect, ellipse).
float
getWidth(int media_id) : Return the width of the 2D media (applies to all 2D medias).
float
getHeight(int media_id) : Return the height of the 2D media (applies to all 2D medias).
void
setVisible(int media_id, int visible) : Sets the visibility. 0 = invisible, 1 = visible.
int
getVisible(int media_id) : Returns the media visibility.
void
setAutoFade(int media_id, bool value) : Define if the automatic fading effect should be used when visibility change for the media.
bool
getAutoFade(int media_id, bool value) : Returns if the automatic fading effect should be used when visibility change for the media.
void
setOpacity(int media_id, int opacity) : Sets the media transparency (image, pictures sequence & video). 0 = fully transparent, 100 = fully opaque.
int
getOpacity(int media_id) : Returns the media transparency (image, pictures sequence & video).
void
setMask(int media_id, int media_id) : Use the second argument 2D media to create a mask for the first argument 2D media. All 2D media can mask other one, at the exception of video, which can be masked but can't be used as mask. Multiple masks can be set to the same media.
note : when setted as mask of an other media, the current media's transforms are relative to the "parent" media (the one it's masking). i.e. the point (0,0) of the mask is the upper-left corner of the masked media!
void
clearMask(int media_id, int media_id) : Remove the mask from the 2D media, if it exists.
void
addChild(int media_id, int media_id) : Use the second argument 2D media to create a child for the first argument 2D media. All 2D media can be the child of an other one. Multiple childs can be set to the same media.
note : when setted as child of an other media, the current media's transforms are relative to the "parent" media. i.e. the point (0,0) of the child is the upper-left corner of the parent media or the point defined by the setCenter() function.
void
removeChild(int media_id, int media_id) : Remove the child from the 2D media, if it exists.
void
node() : Create a new empty 3D node, a special kind of media 2D that is only used to attach childs to it and to preserve 3D perspective transformation. When adding child to a "normal" layer, all layers will be flattened into the parent layer's space. Node avoid this effect and permit to create "groups" of layer in a 3D engine fashion.
int
intersects(int media_id, int media_id) : Intersection test between to two given medias
(applies to images, images sequences, rect, quad, triangle and line). Returns 0 if no intersection occurs, 1 otherwise. !! Do not give good results when using 3D rendering mode!!
int
intersects(float x, float y, int media_id) : Intersection test between a point define by x and y and the given media
(applies to images, images sequences, rect, quad, triangle, ellispe and line). Returns 0 if no intersection occurs, 1 otherwise. !! Do not give good results when using 3D rendering mode!!
int
intersects(float x, float y, int media_id, bool useCALayerContainsPointMethod) : Intersection test between a point define by x and y and the given media
(applies to images, images sequences, rect, quad, triangle, ellispe and line). Returns 0 if no intersection occurs, 1 otherwise. !!
Gives very good results even when using 3D rendering mode!!
TO DO : intesection support for videos.
void
setRenderToContext(int media_id, bool state) : Define the rendering mode of the given media. When rendered to context, media are rendered inside the pixel buffer of the screen. This produces a drawing mode similar to Processing or Java 2D : shapes are painted to the screen and needs to be erased at each loop to avoid traces. NOTE : every media can have a different rendering mode. When rendre to the context buffer, 3D perspective mode is inefficient.
void
clearContext(): Clear the pixel buffer of the graphical context. Erase it to transparent color to let apprear fully the backround color.
Mobilizing allows to load images of any size and any color space. However, the mobile devices are not as powerful as computers, therefore display of very large images can slow down the speed of an executed program. Transparency of the image is respected when using png, gif and tif formats.
Available formats and extensions are : .png, .jpg, .jpeg, .gif, .tiff, .tif, .bmp
int
load(string image_path): Loads an image from the given path. ex : load("monImage.png"). load() function returns a media ID that you can use in all other media related functions. Note : Image are loaded into memory for rapid access. There's not (yet) the possibility to unload the image from memory.
int load(string image_path, string cacheMode): Loads an image from the given path. ex : load("monImage.png"). load() function returns a media ID that you can use in all other media related functions. cacheMode is a hint for memory management of the image resource and can be "cache" (default value) or "nocache". If "nocache" is used, image resource will be flush from memory when the image's visibilty is set to false and loaded again when setted to true.
Precise access to video frames is difficult but is often needed for various artistic projects. The very base of animation is several still pictures scrolling at a certain frequency. Computer graphics can reproduce this principle. Mobilizing proposes the use of still pictures sequences that can be manipulated temporally (chrono-photographic sequences). A sequence is an object composed of multiples pictures (frames) that can scroll in various ways.
Images that can make a sequence must meet a specific nomenclature. All the files must have the same name and file extension, the index is placed between those two, e.g. : image0.png, image1.png, image2.png… NOTE : the first image is the image 0 (not 1).
int
loadSequence(string imagePathWithoutIndex) : Load a sequence. Following the previous example, the sequence is loaded by typing loadSequence("image.png") to automatically load all pictures named "image_index_.png". Available pictures format are the same as describe in the "Image" section of this wiki (.png, .jpg, .jpeg, .gif, .tiff, .tif, .bmp). Like the load() function, loadSequence will return a media ID.
int
loadSequence(string imagePathWithoutIndex, string memory_mode) : Load a sequence with memory mode option. Available modes are : "cache" - "cache_on_display" - "nocache".
"cache" is the default mode, used when no mode is defined by user. Every picture is loaded into memory before playing the sequence, this can take some time to be done and can be a problem when done during update().
"cache_on_display" will load pictures in the memory cache only once it was displayed. The beginning of the sequence ready is very fast as we don't wait for the pictures to be loaded in memory, but the first reading of the sequence can be slow as picture are first accessed from from disk.
"nocache" never load pictures in memory but always from disk. Use this as last ressort when your picture sequence contains too much frame and generate out of memory crash. In this mode you can use very large sequence, with "cache" and "cache_on_display" modes the number of pictures you can load is limited and can quickly ends on out of memory crash.
void
play(int sequence_id) : play the sequence.
void
pause(int sequence_id) : pause the sequence.
void
stop(int sequence_id) : stop the sequence and set the playhead back to the first frame.
void
setLoop(int sequence_id, int loop) : 1 sets the sequence loop in both "forward" and "backward" mode (see setSequenceMode() below), 0 to avoid loop playing.
int
isPlaying(int sequence_id) : Returns the current playing status (0 = is not playing, 1 = is being played).
int
getFrameCount(int sequence_id) : Returns the number of frames that the sequence contains.
void
setFrameRate(int sequence_id, int frameRate) : define the number of frames per second (or the reading speed).
void
setSequenceMode(int sequence_id, string mode) : set the playback mode of the sequence. Available modes are : "forward" - "backward" - "random" - "pingpong".
void
setCurrentFrame(int sequence_id, int currentFrame) : Sets the present frame of the sequence. Can be sets also if the sequence is paused.
int
getCurrentFrame(int sequence_id) : Returns the present frame of the sequence.
According to this section introduction, we can see that memory managment is a problem on mobile devices. Pictures sequence is a difficult point. Therefore, it is possible to unload a sequence to erase it content and replace it with new pictures.
void
unloadSequence(int sequence_id) : discharge images of the sequences. The sequence object
is destroyed but the ID is still usable. Even if the ID could be left empty, it is better to reuse it by loading a new contents with loadSequence(). Check the attached sample code for more details about unloadSequence.
Mobilizing provides the ability to draw various geometric shapes. The thickness and color of stroke and fill color can be defined globally to affects all created shapes or locally to the object. If fill and stroke color or stroke weight are not defined for an object, the default values are applied (which are white fill and black, one point thick stroke). These defaults can be changed at any time. RGBA color space is used : red, green, blue and alpha (for opacity).
void fill(int r, int g, int b, int a) : Sets the default fill color for each color channel.
void fill(int r, int g, int b) : Sets the default fill color. The opacity is at maximum.
void fill(int rgb) : Sets the default fill color. The value argument is applied to all channels except the opacity, which is at maximum.
void noFill() : Deactivate fill color (sets alpha to 0).
void stroke(int r, int g, int b, int a) : Sets the default line color for each color channel.
void stroke(int r, int g, int b) : Sets the default line color. Opacity is at the maximum.
void stroke(int rgba) : Sets the default line color. The value argument is applied to all channels except opacity which is at maximum.
void noStroke() : Deactivate stroke (sets opacity to 0).
void setFillColor(int shape_id, int r, int g, int b, int a) : Sets the fill color of the shape for each color channel.
void setFillColor(int shape_id, int r, int g, int b)
void setFillColor(int shape_id, int rgb)
void setStrokeColor(int shape_id, int r, int g, int b, int a) : Sets the stroke color of the shape for each color channel.
void setStrokeColor(int shape_id, int r, int g, int b)
void setStrokeColor(int shape_id, int rgb);
Shapes are considered as 2D Media objects. Shapes creation involves the creation of a media ID, which is return by all shapes creation functions explained below. Created shapes objects respond to all 2D Media general methods (position and rotation).
int point(float x, float y) : Draws a point a x et y. Basically, a point is a 1*1 pixel square.
int line(float x1, float y1, float x2, float y2) : Draws a line between x1,y1 and x2,y2.
int arc(float x, float y, float radius, float startAngle, float endAngle) : Draws a cercle arc frome point x,y, between startAngle and endAngle (clockwise) according to the given radius.
int bezier(float x1, float x2, float ctrlPointX1, float ctrlPointY1, float ctrlPointX2, float ctrlPointY2, float x2, float y2) : Draws a bezier curve between points x1,y1 et x2,y2, with the corresponding control points.
int ellipse(float x, float y, float width, float height) : Draws an ellipse at point x,y.
int rect(float x, float y, float width, float height) : Draws a rectangle at point x,y.
int triangle(float x1, float y1, float x2, float y2, float x3, float y3) : Draws a triangle according to three points.
int quad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) : Draws a quad (square) according to four points.
After creating a shape, it is possible to change the coordinates of its constituent points. The following functions do not apply to all forms, so those that are handled by a particular function are listed at the end of each line.
void setShapeWidth(int shape_id, int width) : Sets shape width (rect, ellispe and arc radius).
void setShapeHeight(int shape_id, int height) : Sets shape height (rect and ellispe).
void setShapeX1(int shape_id, float x) : Changes the x coordinate of the shape 1st point (line, bezier, triangle & quad).
void setShapeY1(int shape_id, float y) : Changes the y coordinate of the shape 1st point (line, bezier, triangle & quad).
void setShapeX2(int shape_id, float x) : Changes the x coordinate of the shape 2nd point (line, bezier, triangle & quad).
void setShapeY2(int shape_id, float y) : Changes the y coordinate of the shape 2nd point (line, bezier, triangle & quad).
void setShapeX3(int shape_id, float x) : Changes the x coordinate of the shape 3rd point (triangle & quad).
void setShapeY3(int shape_id, float y) : Changes the y coordinate of the shape 3rd point (triangle & quad).
void setShapeX4(int shape_id, float x) : Changes the x coordinate of the shape 4th point (quad).
void setShapeY4(int shape_id, float y) : Changes the y coordinate of the shape 4th point (quad).
float getShapeX1(int shape_id) : gets the x coordinate of the shape 1st point (line, bezier, triangle & quad).
float getShapeY1(int shape_id) : gets the y coordinate of the shape 1st point (line, bezier, triangle & quad).
float getShapeX2(int shape_id) : gets the x coordinate of the shape 2nd point (line, bezier, triangle & quad).
float getShapeY2(int shape_id) : gets the y coordinate of the shape 2nd point (line, bezier, triangle & quad).
float getShapeX3(int shape_id) : gets the x coordinate of the shape 3rd point (triangle & quad).
float getShapeY3(int shape_id) : gets the y coordinate of the shape 3rd point (triangle & quad).
float getShapeX4(int shape_id) : gets the x coordinate of the shape 4th point (quad).
float getShapeY4(int shape_id) : gets the y coordinate of the shape 4th point (quad).
void setShapeStartAngle(int arc_id, float startAngle) : Changes arc startAngle.
void setShapeStopAngle(int arc_id, float endStart) : Canges arc endAngle.
void setShapeControlPointX1(int bezier_id, float ctrlPointX1) : Changes the x coordinate of the 1st control point of the bezier curve.
void setShapeControlPointY1(int bezier_id, float ctrlPointY1) : Changes the y coordinate of the 1st control point of the bezier curve.
void setShapeControlPointX2(int bezier_id, float ctrlPointX2) : Changes the x coordinate of the 2nd control point of the bezier curve..
void setShapeControlPointY2(int bezier_id, float ctrlPointY2) : Changes the y coordinate of the 2nd control point of the bezier curve.
float getShapeControlPointX1(int bezier_id) : gets the x coordinate of the 1st control point of the bezier curve.
float getShapeControlPointY1(int bezier_id) : gets the y coordinate of the 1st control point of the bezier curve.
float getShapeControlPointX2(int bezier_id) : gets the x coordinate of the 2nd control point of the bezier curve..
float getShapeControlPointY2(int bezier_id) : gets the y coordinate of the 2nd control point of the bezier curve.
Mobilizing allows the insertion of text using character strings (string). The fonts used are those of the iPhone OS, a list of available fonts is provided below. Tow different type of drawing are available. The first a text direct drawing of vector glyph in a pixel buffer, the second uses a special iOS class, UILabel, which permits drawing text on multiple lines and inside a rectangular frame. The default drawing mode is "vector". Text, as other media, are considered as media objects and use media ID.
-
int
text (string texte) : Creates a text with the argument string.
Default font is Verdana, default font size is 12.
void
setTextFont (int text_id, string fontName, int fontSize) : Define the font to use for the text object (report to font list). ex : setTextFont(myTexte, "Times New Roman").
void
setTextSize (int text_id, int taille) : Sets the text font size.
void
setText (int text_id, string texte) : Sets the text of this text object.
void
setTextDrawMode (int text_id, string drawMode) : Sets the rendering mode for this text object. Available modes are :
"label" and
"vector". Default mode is "vector". Presently, you
must use "label" if you want to write text in non-latin language. In this case (japanese, chinese, arabian…) you should also set an adapted font.
void
setTextHasMultipleLine (int text_id, int hasMultipleLine) : ONLY FOR "label" TEXT MODE. Enable multiple lines text drawing. Should be set to 0 or 1. In this mode, text is adapted in a rectangular frame, creating a king of page.
void
setTextFrameSize (int text_id, int width, int height) : ONLY FOR "label" TEXT MODE. Sets the width and height of the text frame. This will have effect only if setTextHasMultipleLine() has been activated (sets to 1).
void
setTextAlign (int text_id, string align) : ONLY FOR "label" TEXT MODE. Sets text align mode, available modes are
"left",
"right" &
"center"
string
getText (int text_id) : Returns the text string.
string
getTextFont (int text_id) : Returns the text font string.
int
getTextSize (int text_id) : Returns the text font size.
string
getTextDrawMode (int text_id) : Returns the text draw mode, one of "vector" and "label".
-
-
-
string
getTextAlign (int text_id) : Returns the text align style, if any, one of "left", "center" or "right".
Movie files management on iOS can be a difficult task. Mobilizing provides functions to load and manipulate video clips in a unified way with other 2D media and make it simple and fast. Considered as a 2D Media, videos respond to all general 2D Media management functions. They also can be rendered in perspective and be masked by another media. Movie file format have to be taken in consideration. iOS is able to read .m4v, mp4 and mjpeg .avi movie files only. Reports to the iOS specifications to learn more about supported video format.
int load (string path) : Loads the movie file. .m4v, .mp4 and .avi files are accepted but it is the user responsability to provide a file encoded in order to be recongnize by iOS. If the movie file is not recognized, errors will emerge. As for other medias, returns a media ID.
void play (int video_id) : play the movie.
void pause (int video_id) : pause the movie.
void stop (int video_id) : stop the movie and go back to the begin.
int isPlaying (int video_id) : Returns 1 if the movie is playing, 0 otherwise.
void
setLoop(int sound_id, int loop) : 1 to enable loop playing, 0 to disable.
void setRate (int video_id, float rate) : Sets the playing rate of the movie. Negative values will play the file backward.
float getRate (int video_id) : Returns the playing rate of the movie.
void setCurrentTime (int video_id, float time) : Move the playhead to the given time. Raise an error if this time is out of the movie duration.
float getCurrentTime (int video_id) : Returns the movie present time in seconds.
Mobilizing uses the OpenAL framework, which allows the spatialization of sound. Usually used in conjunction with OpenGL to assign sounds to 3D objects in space, this system of sound management consists essentially in the definition of a listener position in space and sound source emission points. Mobilizing allows to define the position on x, y and z axis of sounds and listener. OpenAL doesn't spatialize sounds if source files are not in mono. Stereo sound files can be used but can't be spatialized (so they can become a kind of background sound). To benefit of this spatialization, it is recommended to use a headset or headphones with the device (iPhone / iPod Touch / iPad).
void setListenerPosition(int x, int y) : Sets the "listener" position. This is the position where the microphone would be located recording the sound emitted from sound sources into the space.
void setListenerPosition(float vectorAtX, float vectorAtY, float vectorAtZ, float vectorUpX, float vectorUpY, float vectorUpZ) : Sets the "listener" position. This is the position where the microphone would be located recording the sound emitted from sound sources into the space. This is the original way fo setting OpenAL listner with 6 component, or 2 3D vector : at vector and up vector.
float getListenerPositionX() : Gets the "listener" x position.
float getListenerPositionY() : Gets the "listener" y position.
void setLoop(int sound_id, int loop) : 0 or 1 to activate or deactivate the sound loop.
int getLoop(int sound_id) : Get the sound looping state.
int load(string sound_path) : Load a sound. Available file formats are .wav et .aif. To place the sound in space, the sounds should be in mono. Returns a Media ID.
void play(int sound_id) : Play a soundfile.
void stop(int sound_id) : Stop a soundfile.
void
setLoop(int sound_id, int loop) : 1 to enable loop playing, 0 to disable.
void setPosition(int sound_id, float x, float y) : Sets the x and y position of the sound.
void setPositionX(int sound_id, float x) : Sets the x position of the sound.
void setPositionY(int sound_id, float y) : Sets the y position of the sound.
void setPositionZ(int sound_id, float z) : Sets the z position of the sound.
float
getPositionX(int sound_id) : Return the present x position of the sound.
float
getPositionY(int sound_id) : Return the present y position of the sound.
float
getPositionZ(int sound_id) : Return the present z position of the sound.
void setSoundMaxDistance(int sound_id, int maxDistance) : Force the sound to emit only in the given boundary. Works best in "linear" mode. Example : setSoundMaxDistance(yourSound, 100) will force your sound to emit from its current location in the screen up to a circular area of 100 pixels around itself.
int getSoundMaxDistance(int sound_id) : Returns the maximum distance of the sound emission.
void setSoundRolloff(int sound_id, float int) : Change the frequency of sound attenuation according to the distance to the listener (works in "default" and "exponential" mode).
int getSoundRolloff(int sound_id) : Returns the sound attenuation curve.
void setSoundGain(int sound_id, float gain) : Sets the sound volume.
float getSoundGain(int sound_id) : Returns the sound volume.
void setSoundPitch(int sound_id, float pitch) : Sets the pitch (speed of reading the file) of a soundfile. Example : setSoundPitch(yourSound, 0.5) to read the saounf at half speed.
float getSoundPitch(int sound_id) : Returns the pitch of the soundfile.
For some projects, it can be useful to record some datas results in a plain text file to use it afterward for analyse. Presently, Mobilizing gives few functions for this kind of operations. It is possible to create a text file and to write string inside it. Any king of values can be written in the file. As Mobilizing is iOS file sharing enabled, it is easy to extract the file. To access it, the user should connect the device and use iTunes (at the bottom of the "Apps" tab) to view file sharing enabled applications. Selects your Mobilizing to see the files and copy it to your computer.
int createTextFile(string fileName) : Creates a text file object to write in and returns it's ID.
void print(textFile_id, string something) : Writes the string in the text file.
void println(textFile_id, string something) : Writes the string in the text file with a line feed.
TO DO Provide a way to read and use text files contents ?
Mobilizing contains a set of function that facilitates the construction of simple visual novel systems. Functions made for visual novel management all get the "vn" prefixe as they implies a special use of Mobilizing.
int vnMakeNewScene(): Create a new visual novel scene. A scene is like a node that can contains a background image, multiple sensible zones (interactive buttons) and manage flags attached to these buttons. Like nodes in a graph, scenes are linked together to allow the creation of narration. Like other Mobilizing media, scene are given a media ID at their creation ex : int scene1 = vnMakeNewScene(); will generate a new scene ID that can be used for further management.
void vnSceneAddBackgroundImage(int sceneID, int mediaID) : Adds a background image to the given scene. Several images can be add but not function permit to manipulate them yet, so it's better to use only one background image for now. Several writting styles can be used with this function.
- script.mob
int scene;
int background;
void setup(){
scene = vnMakeNewScene();
background = load("yourImage.extension");
vnSceneAddBackgroundImage(scene, background);//this adds the background to the scene
//but this way of writting does the same result.
vnSceneAddBackgroundImage(scene, load("yourImage.extension"));
}
void vnSceneAddTextImage(int sceneID, int mediaID) : Adds a text image to the scene. Text image are just image that you creae with a transparent background and that are added automatically on top of background image by this function. Multiple text images can be add to the same scene. If you do so, you should be careful of the writting order of your script.
void vnSceneAddButton(int sceneID, int mediaID) : Adds a button to the scene. Buttons are meant to be interactive zones inside the scene. They can be made from any kind of shapes that Mobilizing can handle and that can be tested for intersection. You are responsible for creating the intersection test structure to make the button interactive.
int vnSceneGetButton(int sceneID, int buttonIndex) : Returns the ID of the button of the scene. ButtonIndex is the number of the targetted button. If you added 2 button to a scene through vnSceneAddButton, then you can use index 0 and 1.
int vnSceneGetButtonCount(int sceneID) : Returns the number of buttons that are attached to the scene (correspond to number of time vnSceneAddButton() has been called on the scene.
void vnSceneSetButtonType(int sceneID, int buttonIndex, string type) : Changes the type of the button. ButtonIndex is the number of the button who's types needs to be changed. If you added 2 button to a scene through vnSceneAddButton, then you can use index 0 and 1. Type can be "nextScene", "nextText", "nextTextAndScene". Each type define different behaviors for the button. "nextScene" is the default type value and defines a button that, when touched, should leads to the next scene. "nextText" defines a button that should only act on the text layer of the scene and displays the next text when exists. "nextTextAndScene" defines a button that should act on the text layer to display all the available text and goes to the nextScene once all texts have been displayed. NOTE : the type of the button just give the possibility to check the type in order to construct your own behavior mecanism, it will not produced a ready-to-use button.
string vnSceneGetButtonType(int sceneID, int buttonIndex) : Returns the current type of the button as a string : "nextScene", "nextText" or "nextTextAndScene". ButtonIndex is the number of the targetted button. If you added 2 button to a scene through vnSceneAddButton, then you can use index 0 and 1.
void vnSceneAddConnection(int sceneID, int buttonIndex, int sceneID) : Create a link between the scenes with the given button. ButtonIndex is the number of the targetted button. If you added 2 button to a scene through vnSceneAddButton, then you can use index 0 and 1.
int vnGetConnection(int sceneID, int buttonIndex) : Returns the scene media ID of the scene the given button is connected to.ButtonIndex is the number of the targetted button. If you added 2 button to a scene through vnSceneAddButton, then you can use index 0 and 1.
void vnSceneSetType(int sceneID, string type) : Sets the type of the scene. Possible value of type is only "start" for now. By defining one scene to be of type start, this scene will be the firt of your visual novel. NOTE : if you don't define any start scene, the screen will remains black as every created scene is automatically set to invisible!
void vnSceneSetFlag(int sceneID, int buttonIndex, bool flagValue) : A flag is basically boolean value attached to a specific button of a scene. If it's set to false, the button is inactive. Usually, flags are used to lock/unlock particular path into the novel structure : one way is locked until the user passed through a certain scene to will unlock it. ButtonIndex is the number of the targetted button. If you added 2 button to a scene through vnSceneAddButton, then you can use index 0 and 1.
bool vnSceneGetFlag(int sceneID, int buttonIndex) : Returns the value of the given button's flag of the given scene.
void vnSceneSetWillSetFlag(int sceneID, int buttonIndex, int otherSceneID, int otherSceneButtonIndex, bool flagValue) : Function used to give hints that will change the flag of button 'otherSceneButtonIndex' of scene 'otherSceneID' when button 'buttonIndex' of scene 'sceneID'.
int vnSceneGetWillSetFlagScene(int sceneID, int buttonIndex) : returns the targeted scene media ID of the given scene's button if information were added to it throught vnSceneSetWillSetFlag() function.
int vnSceneGetWillSetFlagIndex(int sceneID, int buttonIndex) : returns the targeted button media ID of the given scene's button if information were added to it throught vnSceneSetWillSetFlag() function.
bool vnSceneGetWillSetFlagValue(int sceneID, int buttonIndex) : returns the targeted button flag of the given scene's button if information were added to it throught vnSceneSetWillSetFlag() function.
- script.mob
int scene;
int scene2;
int scene3;
int scenes;//to enable looped process of scenes
void setup(){
scene = vnMakeNewScene();
int img = load("data/background/image1-0.png");
vnSceneAddBackgroundImage(scene, img);//added background image
int bt = rect(0,0, 200,200);//cosntruct a rectangle to make it a button
vnSceneAddButton(scene, bt);
int bt = rect(400,400, 200,200);//!!mobilizing is tolerant about double variable declarations!!
vnSceneAddButton(scene, bt);
scene2 = vnMakeNewScene();
int image2 = load("data/background/image2-0.png");
vnSceneAddBackgroundImage(scene2, image2);
int bt = rect(400,400, 200,200);
vnSceneAddButton(scene2, bt);
scene3 = vnMakeNewScene();
int image3 = load("data/background/image3-0.png");
vnSceneAddButton(scene3, image3);
//add scenes index to a list
scenes[0] = scene;
scenes[1] = scene2;
scenes[2] = scene3;
//connection should be setted only when scene have already been created
vnSceneAddConnection(scene, 0, scene2);//links scene to scene2 through button number 0 of scene.
vnSceneAddConnection(scene, 1, scene3);//links scene to scene3 through button number 1 of scene.
vnSceneAddConnection(scene2, 0, scene3);//links scene2 to scene3 through button number 0 of scene2.
vnSceneSetFlag(scene, 1, flase);//lock the path of the button 1
vnSceneWillSetFlag(scene,0, scene2,1, true);//bt 0 of scene should unlock bt 1 of scene 2
vnSceneSetType(scene,"start");//the novel will start with scene.
}
bool touchStarted;
void update(){
if(TouchPressed == true && touchStarted == false ){
touchStarted = true;//to avoid useless loops with touch
for(int i=0; i<sizeof(scenes);i++){//loop through all scenes
for(int j=0; i<vnSceneGetButtonCount(scenes[i]); j++){//loop through all scene buttons
//in the update loop, here is how to reconstruct the information setted by vnSceneGetWillSetFlagScene
int flagScenePoint = vnSceneGetWillSetFlagScene(scenes[i],j));//give real media ID!!
int flagIndex = vnSceneGetWillSetFlagIndex(scenes[i],j));
bool flagValue = vnSceneGetWillSetFlagValue(scenes[i],j));
...//do your stuff, check what you want (intersection with button for ex.)
vnSceneSetFlag(flagScenePoint, flagIndex, flagValue);//reconstruct the command to set the flag at a certain point of the script
...
}
}
}
}
if(TouchPressed == false){
touchStarted = false;
}
}
void vnSceneGoToNextText(int sceneID) : Tells the given scene to show the next text, if exists. Usually used for "nextText" type of scenes.
void vnSceneGoToScene(int sceneID, int buttonIndex) = Tells the given scene to show the next scene, according to the connection created with vnSceneAddConnection() function for the given button 'buttonIndex'. ButtonIndex is the number of the targetted button. If you added 2 button to a scene through vnSceneAddButton, then you can use index 0 and 1.