to use data structures
list
http://docs.python.org/tutorial/introduction.html#lists
a = [1, 3,4,2]
names = ['BY', 'jon']
#access individual items
eg.: a[2]
cannot use index beyond list range
so gotta use
methods: append, insert
(http://docs.python.org/tutorial/datastructures.html)
eg.: a.append(1000)
to find size of list: len(a)
Sunday, November 28, 2010
iphone + flash cs4 + AIR 2.5 SDK
1) downloaded AIR 2.5 SDK
2) followed instructions on forum: http://forums.adobe.com/thread/745398
/******************************
Quit Flash CS4 Professional if it is open.
Navigate to the Flash CS4 installation folder. The default location on Windows is "C:\Program Files\Adobe\Adobe Flash CS4\" and on Mac OS "/Applications/Adobe Flash CS4/"
Within the "Adobe Flash CS4" folder you should see a folder called "AIK1.5". If this folder is not present repeat step #1.
Rename the folder "AIK1.5" to "AIK1.5 OLD" or delete it if you do not need to save a copy of it.
Make a new folder called "AIK1.5"
Download the Adobe AIR 2 SDK from the labs website and uncompress the contents of the folder to the new "AIK1.5" folder you just created.
Copy the "airglobal.swc" file located within the "Adobe Flash CS4/AIK1.5/frameworks/libs/air/" folder into the "Adobe Flash CS4/Common/Configuration/ActionScript 3.0/AIR1.5/" folder.
**************************************/
3) File > New > Actionscript 3 (AIR)
4) Save and Ctrl + Enter
5) Properties > AIR settings > Use custom application descriptor file. point to generated app.xml in folder where FLA is saved
6) modify app.xml:
namespace 1.5 to 2
<application xmlns="http://ns.adobe.com/air/application/2.0">
add "autoOrients", "icons" tags, etc
7) Ctrl + Enter again to run the application
8) use PFI to create IPA.
9) Install on iphone and test.
tested working.
2) followed instructions on forum: http://forums.adobe.com/thread/745398
/******************************
Quit Flash CS4 Professional if it is open.
Navigate to the Flash CS4 installation folder. The default location on Windows is "C:\Program Files\Adobe\Adobe Flash CS4\" and on Mac OS "/Applications/Adobe Flash CS4/"
Within the "Adobe Flash CS4" folder you should see a folder called "AIK1.5". If this folder is not present repeat step #1.
Rename the folder "AIK1.5" to "AIK1.5 OLD" or delete it if you do not need to save a copy of it.
Make a new folder called "AIK1.5"
Download the Adobe AIR 2 SDK from the labs website and uncompress the contents of the folder to the new "AIK1.5" folder you just created.
Copy the "airglobal.swc" file located within the "Adobe Flash CS4/AIK1.5/frameworks/libs/air/" folder into the "Adobe Flash CS4/Common/Configuration/ActionScript 3.0/AIR1.5/" folder.
**************************************/
3) File > New > Actionscript 3 (AIR)
4) Save and Ctrl + Enter
5) Properties > AIR settings > Use custom application descriptor file. point to generated app.xml in folder where FLA is saved
6) modify app.xml:
namespace 1.5 to 2
<application xmlns="http://ns.adobe.com/air/application/2.0">
add "autoOrients", "icons" tags, etc
7) Ctrl + Enter again to run the application
8) use PFI to create IPA.
9) Install on iphone and test.
tested working.
Saturday, November 27, 2010
iphone + air 2.5 sdk + Flash Builder
File > New > Flex Project
Next > Next > last dialog
Main application file > replace .mxml with .as
Finish
.as created. class extends Sprite
open app.xml
set visible to true:
<application><initialWindow><visible>true</visible></initialWindow></application>
F11 to debug
empty window should appear
Project > Properties > Flex Compiler > options/arguments: -default-size 320 480
Next > Next > last dialog
Main application file > replace .mxml with .as
Finish
.as created. class extends Sprite
open app.xml
set visible to true:
<application><initialWindow><visible>true</visible></initialWindow></application>
F11 to debug
empty window should appear
Project > Properties > Flex Compiler > options/arguments: -default-size 320 480
Sunday, November 21, 2010
3dsmax: COM classes
create .NET classes
register assembly (DLL) to COM
Python:
reference:
http://techarttiki.blogspot.com/2008/03/calling-python-from-maxscript.html
http://oreilly.com/catalog/pythonwin32/chapter/ch12.html
python COM server
then compile and run this class...
in 3DS max > MAXScript Listener:
but have to reload 3DS max whenever the COM class is changed
register assembly (DLL) to COM
Python:
reference:
http://techarttiki.blogspot.com/2008/03/calling-python-from-maxscript.html
http://oreilly.com/catalog/pythonwin32/chapter/ch12.html
python COM server
class PythonUtilities:
_public_methods_ = [ 'AreaOfCircle' ]
_reg_progid_ = "PythonDemos.Utilities"
# NEVER copy the following ID
# Use "print pythoncom.CreateGuid()" to make a new one.
_reg_clsid_ = "{968B74C1-5B12-47CE-93DF-EE2C1418A542}"
def AreaOfCircle(self, radius):
return 3.14159 * radius * radius
# Add code so that when this script is run by
# Python.exe, it self-registers.
if __name__=='__main__':
print "Registering COM server..."
import win32com.server.register
win32com.server.register.UseCommandLine(PythonUtilities)
then compile and run this class...
in 3DS max > MAXScript Listener:
comObj = createOLEObject "PythonDemos.Utilities"
a = comObj.AreaOfCircle(10)
but have to reload 3DS max whenever the COM class is changed
Saturday, November 20, 2010
3dsmax: UI
-- UI
rollout addition "Addition of two numbers"
(
-- UI elements
edittext text1 "First number"
edittext text2 "Second number"
button b "Add"
label lbl "Result"
-- event handlers
on b pressed do
(
a1 = text1.text as float
a2 = text2.text as float
c = a1 + a2
lbl.text = c as string
)
)
in MAXScript listener:
-- create a dialog 320 x 240
createDialog addition 320 240
math operator: +, -, *, /
% = mod number1 to number 2
+=, -=, *=, /=
3dsmax: loops, array, struct, as
-- do-while loop
i = 0
do
(
b = box()
b.pos.x = i * 10
--print i
i = i +1
)while (i <a)
-- while loop
i = 0
while(i < a) do
(
print i
i = i+1
)
-- array
arr = #(1, 2, 3, 4)
-- one-based index
print arr[3]
-- struct
struct Fan
(
-- member variables
speed,
radius,
isOn,
-- member function
function setSpeed spd=
(
speed = spd
),
function getSpeed=
(
return speed
),
-- special: calling function when object is constructed
-- can only call function AFTER it is created. eg.: setSpeed()
speed = setSpeed(1)
)
-- initiating structure
f = Fan()
f.radius = 10
f.setSpeed(3)
-- using "as" command
str = "The fan speed is " + fan.getSpeed() as string
Friday, November 19, 2010
3ds max: MAXScript basics
comments:
-- single line comment
/* multi-line comment */
variables. simple. no need to declare. eg.: a = 3
F11 - Script listener. something like Output panel in flash. but it allows u to key in scripts directly
(.) dot operator = object properties
($) superscript = can use it to reference an object using pathname. eg.: $Sphere01.
point3 data type
eg.:
FunctionName keyword1:value1 keyword2:value2
5 /9 = 0. so if need decimal place, must use 5.0/9 or 5 / 9.0 or 5.0 / 9.0
custom function:
returns fah automatically if without 'return fah'
pass by value default
pass by reference using (&) symbol
if-then-else
eg.:
example 2
for loop
eg.:
do-while loop
do
(
statements(s)
)
while(conditions)
while-do loop
while(conditions) do
(
statement(s)
)
-- single line comment
/* multi-line comment */
variables. simple. no need to declare. eg.: a = 3
F11 - Script listener. something like Output panel in flash. but it allows u to key in scripts directly
(.) dot operator = object properties
($) superscript = can use it to reference an object using pathname. eg.: $Sphere01.
point3 data type
eg.:
newpos = point3 10 0 0function parameter in any order
b.pos = newpos
FunctionName keyword1:value1 keyword2:value2
5 /9 = 0. so if need decimal place, must use 5.0/9 or 5 / 9.0 or 5.0 / 9.0
custom function:
function celsiusToFahrenheit celsius =
(
fah = 5.0/9 * (celsius - 32)
return fah
)
returns fah automatically if without 'return fah'
pass by value default
pass by reference using (&) symbol
if-then-else
eg.:
if(zz > 100) then messagebox "hot"
example 2
function testIF a=and, or operator. literally use "and" and "or"
(
if(a > 0) then
(
messagebox "more than zero"
)
else if(a == 0) then
(
messagebox "equal to zero"
)
else
(
messagebox "less than zero"
)
)
for loop
eg.:
function testFor a=
(
for i=1 to a do
(
b = box()
b.pos.x = i * 10
)
)
do-while loop
do
(
statements(s)
)
while(conditions)
while-do loop
while(conditions) do
(
statement(s)
)
Sunday, November 14, 2010
CSS: clear:both
assume using a container,
inside it a header,
then a left content, right side bar
then a footer
"
Clearing Method
Because all the columns are floated, this layout uses a clear:both declaration in the .footer rule. This clearing technique forces the .container to understand where the columns end in order to show any borders or background colors you place on the .container. If your design requires you to remove the .footer from the .container, you'll need to use a different clearing method. The most reliable will be to add a <br class="clearfloat" /> or <div class="clearfloat"></div> after your final floated column (but before the .container closes). This will have the same clearing effect.
"
Sample:
with CLEAR:BOTH
container
header
left content
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
right sidebar
footer
without CLEAR:BOTH (Different browsers, eg.: IE, safari, chrome, firefox, will have different rendering)
container
header
left content
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
right sidebar
footer
Wednesday, October 13, 2010
Flash Builder 4 + iphone packager
1) create actionscript project
2) code AS
3) compile > test > SWF
3a) Create application.xml (refer to below)
4) PFI + .mobileprovision + .p12 + all necessary files > IPA
eg.:
pfi.bat -package -target ipa-test -provisioning-profile "MyApp.mobileprovision" -storetype pkcs12 -keystore "iphone_dev.p12" HelloWorld.ipa application.xml MyApp.swf
Default.png icons [and other files or folders]
5) install .mobileprovision in itunes if not done so. File > Add to library. sync iphone
6) add IPA to itunes. sync.
application.xml:
<?xml version="1.0" encoding="utf-8"?>
<application xmlns="http://ns.adobe.com/air/application/2.0">
<id>com.myDomain.MyApp</id>
<filename>HelloWorld</filename>
<name>HelloWorld</name>
<version>1.0</version>
<initialWindow>
<content>MyApp.swf</content>
<fullScreen>true</fullScreen>
<autoOrients>false</autoOrients>
<aspectRatio>portrait</aspectRatio>
<renderMode>cpu</renderMode>
</initialWindow>
<icon>
<image512x512>icons/icon512.png</image512x512>
<image57x57>icons/icon57.png</image57x57>
<image29x29>icons/icon29.png</image29x29>
</icon>
</application>
2) code AS
3) compile > test > SWF
3a) Create application.xml (refer to below)
4) PFI + .mobileprovision + .p12 + all necessary files > IPA
eg.:
pfi.bat -package -target ipa-test -provisioning-profile "MyApp.mobileprovision" -storetype pkcs12 -keystore "iphone_dev.p12" HelloWorld.ipa application.xml MyApp.swf
Default.png icons [and other files or folders]
5) install .mobileprovision in itunes if not done so. File > Add to library. sync iphone
6) add IPA to itunes. sync.
application.xml:
<?xml version="1.0" encoding="utf-8"?>
<application xmlns="http://ns.adobe.com/air/application/2.0">
<id>com.myDomain.MyApp</id>
<filename>HelloWorld</filename>
<name>HelloWorld</name>
<version>1.0</version>
<initialWindow>
<content>MyApp.swf</content>
<fullScreen>true</fullScreen>
<autoOrients>false</autoOrients>
<aspectRatio>portrait</aspectRatio>
<renderMode>cpu</renderMode>
</initialWindow>
<icon>
<image512x512>icons/icon512.png</image512x512>
<image57x57>icons/icon57.png</image57x57>
<image29x29>icons/icon29.png</image29x29>
</icon>
</application>
Tuesday, October 05, 2010
iPhone development: Objective C
hmm.. property has to be defined after interface
eg.:
@interface MyViewController : UIViewController {
UITextField *textField;
UILabel *label;
NSString *string;
}
@property (nonatomic, retain) IBOutlet UITextField *textField;
@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, copy) NSString *string;
- (IBAction) changeGreeting: (id) sender;
NOT
@property (nonatomic, retain) IBOutlet UITextField *textField;
@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, copy) NSString *string;
- (IBAction) changeGreeting: (id) sender;
@interface MyViewController : UIViewController {
UITextField *textField;
UILabel *label;
NSString *string;
}
to use these in the .m files
must use @synthesize
eg.:
@synthesize textField;
@synthesize label;
@synthesize string;
eg.:
@interface MyViewController : UIViewController {
UITextField *textField;
UILabel *label;
NSString *string;
}
@property (nonatomic, retain) IBOutlet UITextField *textField;
@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, copy) NSString *string;
- (IBAction) changeGreeting: (id) sender;
NOT
@property (nonatomic, retain) IBOutlet UITextField *textField;
@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, copy) NSString *string;
- (IBAction) changeGreeting: (id) sender;
@interface MyViewController : UIViewController {
UITextField *textField;
UILabel *label;
NSString *string;
}
to use these in the .m files
must use @synthesize
eg.:
@synthesize textField;
@synthesize label;
@synthesize string;
Sunday, August 22, 2010
Flash: RSS + spring model
RSS:
http://www.straitstimes.com/STI/STIFILES/rss/break_lifestyle.xml
http://feeds.feedburner.com/StraitsTimesInteractive-Lifestyle
Demo: http://psalmhundred.net/experiment/rss_elastic.html
http://www.straitstimes.com/STI/STIFILES/rss/break_lifestyle.xml
http://feeds.feedburner.com/StraitsTimesInteractive-Lifestyle
Demo: http://psalmhundred.net/experiment/rss_elastic.html
Monday, July 26, 2010
PHP: yahoo finance to xml
wrote a simple PHP script to get quotes data from yahoo finance and format it into XML format.
sample: http://psalmhundred.net/experiment/stocks.php?s=adbe,goog,aapl,msft
OR
references:
http://www.gummy-stuff.org/Yahoo-data.htm
sample: http://psalmhundred.net/experiment/stocks.php?s=adbe,goog,aapl,msft
OR
references:
http://www.gummy-stuff.org/Yahoo-data.htm
Sunday, July 25, 2010
Flash & XML: namespace
sample RSS feed: http://weather.yahooapis.com/forecastrss?w=1062605&u=c
to access elements that are using namespace.
eg.:
gotta use the Namespace class and the :: operator
eg.:
to access elements that are using namespace.
eg.:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<channel>
...
<item>
...
<yweather:condition text="Partly Cloudy" code="30" temp="31" date="Sun, 25 Jul 2010 7:00 pm SGT" />
...
</item>
...
</channel>
</rss>
gotta use the Namespace class and the :: operator
eg.:
var xml:XML = new XML(loader.data);
var ns:Namespace = xml.namespace("yweather");
trace(xml.channel.item.ns::condition.@text);
Friday, July 23, 2010
Wednesday, July 21, 2010
Novint Falcon used in Flash
Getting x, y, z coordinates and buttons status:
Using Flash to output force feedback to haptic device:
Using Flash to output force feedback to haptic device:
Tuesday, July 20, 2010
winsock 2: recv with select
needed to use recv in synchronous mode. but it is a blocking call.
so google a bit and found select.
code segment:
so google a bit and found select.
code segment:
fd_set sockets;
TIMEVAL waitTime;
void Receive()
{
// gotta call select() to check if there is incoming packet
sockets.fd_count = 1;
sockets.fd_array[0] = ClientSocket;
// time to expire for select call. since it is blocking too.
waitTime.tv_sec = 0; // seconds
waitTime.tv_usec = 100; // micro seconds
// check if any of the listening sockets has incoming data
// returns number of sockets in fd_set that has incoming data
int result = select(NULL, &sockets, NULL, NULL, &waitTime);
int iResult = result;
if(result > 0)
{
// blocking call
iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
if(iResult > 0)
{
printf("Bytes received: %d\n", iResult);
printf("Recv: %s\n", recvbuf);
}
else if(iResult == 0)
{
//printf("Nothing received\n");
}
else
{
printf("recv failed: %d\n", WSAGetLastError());
}
}
return iResult;
}
Saturday, July 17, 2010
libxml2: XML parsing using C/C++
http://www.xmlsoft.org/
require some modification:
xmlversion.h
iconv.dll required. got it at: http://www.gnupg.org/download/iconv.en.html
require some modification:
xmlversion.h
/**
* LIBXML_ICONV_ENABLED:
*
* Whether iconv support is available
*/
#if 0 // instead of 1
#define LIBXML_ICONV_ENABLED
#endif
iconv.dll required. got it at: http://www.gnupg.org/download/iconv.en.html
xmlTextReaderPtr reader;
char xml[200] = "<root><child1><child2 attr=\"123\" attr2=\"test\">hello world</child2></child1></root>";
printf("%s\n", xml);
cout << "Read XML from memory...\n";
reader = xmlReaderForMemory(xml, strlen(xml), "", NULL, 0);
if (reader != NULL) {
// loop to read nodes
int ret;
const xmlChar *name, *value;
ret = xmlTextReaderRead(reader);
while(ret == 1)
{
name = xmlTextReaderConstName(reader);
value = xmlTextReaderConstValue(reader);
printf("%s=%s\n", name, value);
// attributes
ret = xmlTextReaderHasAttributes(reader);
if(ret == 1)
{
// has attributes
attrName = xmlCharStrdup("attr");
attrValue = xmlTextReaderGetAttribute(reader, attrName);
int attr = atoi((const char *) attrValue);
printf("attr=%d\n", attr);
}
ret = xmlTextReaderRead(reader);
}
cout << "Freeing XML reader...\n";
xmlFreeTextReader(reader);
}
Monday, June 28, 2010
Wednesday, June 02, 2010
OpenGL: Stereoscopic rendering
Source: http://www.orthostereo.com/geometryopengl.html
Example:
Example:
GLvoid display(GLvoid)
{
glDrawBuffer(GL_BACK); //draw into both back buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear color and depth buffers
glDrawBuffer(GL_BACK_LEFT); //draw into back left buffer
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); //reset modelview matrix
gluLookAt(-IOD/2, //set camera position x=-IOD/2
0.0, // y=0.0
0.0, // z=0.0
0.0, //set camera "look at" x=0.0
0.0, // y=0.0
screenZ, // z=screenplane
0.0, //set camera up vector x=0.0
1.0, // y=1.0
0.0); // z=0.0
glPushMatrix();
{
glTranslatef(0.0, 0.0, depthZ); //translate to screenplane
drawscene();
}
glPopMatrix();
glDrawBuffer(GL_BACK_RIGHT); //draw into back right buffer
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); //reset modelview matrix
gluLookAt(IOD/2, 0.0, 0.0, 0.0, 0.0, screenZ, //as for left buffer with camera position at:
0.0, 1.0, 0.0); // (IOD/2, 0.0, 0.0)
glPushMatrix();
{
glTranslatef(0.0, 0.0, depthZ); //translate to screenplane
drawscene();
}
glPopMatrix();
glutSwapBuffers();
}
Subscribe to:
Posts (Atom)