Showing posts with label iOS. Show all posts
Showing posts with label iOS. Show all posts

Tuesday, June 6, 2017

Apple iOS Machine Learning

https://developer.apple.com/documentation/coreml

https://github.com/xmartlabs/Bender
- built on top of https://developer.apple.com/documentation/metalperformanceshaders


Thursday, September 8, 2016

Unity 3D on iOS

Doc:
https://docs.unity3d.com/Manual/iphone-GettingStarted.html

Part 1:
https://www.raywenderlich.com/25205/beginning-unity-3d-for-ios-part-13
Part 2:
https://www.raywenderlich.com/?p=25349
Part 3:
https://www.raywenderlich.com/?p=25828

Submission:
https://unity3d.com/learn/tutorials/topics/mobile-touch/how-submit-ios-app-store-overview

Bezier Curve

Quadratic:

Cubic:



In case of the cubic formula P0, P1 and P2 are your control points. t has to be a value between 0 and 1 and represents the "position" on the curve. By incrementing t step by step you'll get several points you can use to actually draw the curve.

So using the above formula you could do something like
glBegin(GL_LINE_STRIP);
for(float t=0; t <= 1; t += 0.1) {
     float x = (1-t)*(1-t)*p0.x + 2(1-t)*t*p1.x + t*t*p2.x;
     float y = (1-t)*(1-t)*p0.y + 2(1-t)*t*p1.y + t*t*p2.y;
     float z = (1-t)*(1-t)*p0.z + 2(1-t)*t*p1.z + t*t*p2.z;

     glVertex3f(x, y, z);
}
glEnd();
The smaller the steps you use for t the smoother the curve will become. That's it. Really.
Generic:
http://www.gamedev.net/topic/534082-drawing-a-curve-in-opengles---how/

iOS:
http://stackoverflow.com/questions/5054790/cgpathref-bezier-curves-in-opengl-es

Android:
http://blog.uncle.se/2012/02/opengl-es-tutorial-for-android-part-ii-building-a-polygon/

Unity:
http://www.theappguruz.com/blog/bezier-curve-in-games

Monday, July 25, 2016

pybee python ios

https://github.com/pybee/Python-Apple-support

#import "Python/Python.h"

http://stackoverflow.com/questions/9749260/python-for-ios-interpreter

A little trip to Ubuntu 16.04
Install Python 3.5
1
sudo apt-get install python3 python3-dev

helloworld.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <Python.h>

int
main(int argc, char *argv[])
{
    wchar_t *program = Py_DecodeLocale(argv[0], NULL);
    if (program == NULL) {
        fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
        exit(1);
    }
    Py_SetProgramName(program);  /* optional but recommended */
    Py_Initialize();
    PyRun_SimpleString("from time import time,ctime\n"
                       "print('Today is', ctime(time()))\n");
    Py_Finalize();
    PyMem_RawFree(program);
    return 0;
}

build
1
3
gcc -c hellowworld.c
gcc helloworld.o $(/usr/bin/python3.5-config --ldflags)


Calling Python from C and fetching return values

Python: sample.py
1
2
3
# Returns the sum of two numbers.
def add(a, b):
 return a+b

sample.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <python3.5/Python.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
 char localPath[40] = "\/home\/XXX\/XXX\/";

 printf("Calling Python to find the sum of 2 and 2.\n");

 // Initialize the Python interpreter.
 Py_Initialize();

 // Create some Python objects that will later be assigned values.
 PyObject *pName, *pModule, *pDict, *pFunc, *pArgs, *pValue;

 // Convert the file name to a Python string.
 pName = PyUnicode_FromString("sample");

 PyObject *sys_path = PySys_GetObject("path");
 PyList_Append(sys_path, PyUnicode_FromString(localPath));

 // Import the file as a Python module.
 pModule = PyImport_Import(pName);

 // Create a dictionary for the contents of the module.
 pDict = PyModule_GetDict(pModule);

 // Get the add method from the dictionary.
 pFunc = PyDict_GetItemString(pDict, "add");

 // Create a Python tuple to hold the arguments to the method.
 pArgs = PyTuple_New(2);

 // Convert 2 to a Python integer.
 pValue = PyLong_FromLong(2);

 // Set the Python int as the first and second arguments to the method.
 PyTuple_SetItem(pArgs, 0, pValue); 
 PyTuple_SetItem(pArgs, 1, pValue); 

 // Call the function with the arguments.
 PyObject* pResult = PyObject_CallObject(pFunc, pArgs);

 // Print a message if calling the method failed.
 if(pResult == NULL) printf("Calling the add method failed.\n");

 // Convert the result to a long from a Python object.
 long result = PyLong_AsLong(pResult);

 // Destroy the Python interpreter.
 Py_Finalize();

 // Print the result.
 printf("The result is %d.\n", result);
 //std::cin.ignore();

 return 0;
}

Objective-C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
- (void)helloWorld
{
    printf("Calling Python to find the sum of 2 and 2.\n");
    
    NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
    PyObject *sys_path = PySys_GetObject("path");
    PyList_Append(sys_path, PyUnicode_FromString([resourcePath UTF8String]));

    // Special environment to avoid writing bytecode because
    // the process will not have write attribute on the device.
    putenv("PYTHONDONTWRITEBYTECODE=1");
    
    NSString *python_home = [NSString stringWithFormat:@"%@/Library/Python.framework/Resources", resourcePath, nil];
    NSLog(@"PythonHome is: %@", python_home);
    wchar_t *wpython_home = Py_DecodeLocale([python_home UTF8String], NULL);
    Py_SetPythonHome(wpython_home);
    
    // iOS provides a specific directory for temp files.
    NSString *tmp_path = [NSString stringWithFormat:@"TMP=%@/tmp", resourcePath, nil];
    putenv((char *)[tmp_path UTF8String]);
    
    // Initialize the Python interpreter.
    Py_Initialize();
    
    // Create some Python objects that will later be assigned values.
    PyObject *pName, *pModule, *pDict, *pFunc, *pArgs, *pValue;
    
    // Convert the file name to a Python string.
    pName = PyUnicode_FromString("sample");
    
    // Import the file as a Python module.
    pModule = PyImport_Import(pName);
    
    // Create a dictionary for the contents of the module.
    pDict = PyModule_GetDict(pModule);
    
    // Get the add method from the dictionary.
    pFunc = PyDict_GetItemString(pDict, "add");
    
    // Create a Python tuple to hold the arguments to the method.
    pArgs = PyTuple_New(2);
    
    // Convert 2 to a Python integer.
    pValue = PyLong_FromLong(2);
    
    // Set the Python int as the first and second arguments to the method.
    PyTuple_SetItem(pArgs, 0, pValue);
    PyTuple_SetItem(pArgs, 1, pValue);
    
    // Call the function with the arguments.
    PyObject* pResult = PyObject_CallObject(pFunc, pArgs);
    
    // Print a message if calling the method failed.
    if(pResult == NULL) printf("Calling the add method failed.\n");
    
    // Convert the result to a long from a Python object.
    long result = PyLong_AsLong(pResult);
    
    // Destroy the Python interpreter.
    Py_Finalize();
    
    // Print the result.
    printf("The result is %d.\n", result);
}

Saturday, May 14, 2016

CALayer

https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CALayer_class/

alpha:
Simply change opacity directly. The range is within [0.0f, 1.0f]
http://stackoverflow.com/questions/15865500/calayer-sublayer-alpha-overriding

http://stackoverflow.com/questions/12448847/calayer-opacity-animation

rounded corner:
Can be changed on the fly through "setCornerRadiu"
http://stackoverflow.com/questions/4754392/uiview-with-rounded-corners-and-drop-shadow

frame:
Can be changed on the fly by writing to frame directly

contentsGravity vs contentsScale vs transform/affineTransform

contentsScale: 1 => 1 pixel per point, n=> n pixels per point
- when kCAGravityResizeAspect / kCAGravityCenter

If out of bound, masksToBounds property is useful.

contentsRect: 0-1.0.  unit coordinates.
- sprite sheets:

contentsCenter: area can be stretched.