Tuesday, August 25, 2009

1st try at Python

# for comments
variables. easy.
concatenating strings a bit more troublesome.
eg.:
i = 1.23
s = "hello"
a = s + i
will give error
have to convert to string
a = s + str(i)

b = True
b = not b #store False. same as b = !b

if-else conditions
>>> if x < 0:
...      x = 0
...      print 'Negative changed to zero'
... elif x == 0:
...      print 'Zero'
... elif x == 1:
...      print 'Single'
... else:
...      print 'More'
...


while loop still ok. but must get used to the : at the back
eg.:
i = 0
while i<= 10: # : is equivalent of starting a curly brace {
   print i   # identation used to indicate within while loop
   i = i + 1 # what happened to ++, --?!

for loop v different.
>>> # Measure some strings:
... a = ['cat', 'window', 'defenestrate']
>>> for x in a:
...     print x, len(x)

OR
for i in range(10):
    print i # print 0, 1, 2,..., 9


functions
eg.:
def functionName():
  print "running in function"


classes and objects
class MyClass:
   property = 1 # static variable
   self.myVar = "hello" # instance variable
   def __init__(self, p): # contructor, self = this
         self.property = p

   def method1(self): # note the need for self, even with no arguments/parameters
      print "running method"
   @staticmethod
   def staticMethod2(args, arg2):
      print "call me by classname, eg.: MyClass.staticMethod2(1,2)"

x = MyClass() # instantiate
print x.property
x.method1()

class DerivedClass(MyClass): # inheritance
  newProperty = 2

class SubSubClass(Class1, Class2, Class3): # multiple inheritance supported
  # fields & methods


modules
save into separate .py files
and then import
using import hello (if module is hello.py)
or use from hello import *

Thursday, August 06, 2009

Flash 10: Matrix3D

rawData is set as column major order

hence, gotta transpose to row major

var v:Vector.<Number> = Vector.<Number>(
[1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16]);
var m:Matrix3D = new Matrix3D();
m.rawData = v;
/*
matrix is stored as
[1, 5, 9, 13]
[2, 6, 10, 14]
[3, 7, 11, 15]
[4, 8, 12, 16]
*/
m.transpose();
/*
matrix is stored as
[1, 2, 3, 4]
[5, 6, 7, 8]
[9, 10, 11, 12]
[13, 14, 15, 16]
*/

Monday, June 08, 2009

TBY appears on ST paper


ha. found this newspaper clipping while clearing my old office.
ST, Tech & Sci, H9, 28 Aug 2003

Thursday, June 04, 2009

Using Flex Library SWC with Flash CS3 FLA

Useful link: http://www.timwalling.com/2007/10/22/compiling-flash-cs3-compatible-swcs-with-flex/

It works.
1) manifest.xml
eg.:
<?xml version="1.0" encoding="utf-8"?>
<componentPackage>
<component id="OOPMLibrary" class="com.boon.OOPM" />
</componentPackage>

1b) Flex Library Compiler > Fill in Namespace URL and Manifest File

2) Compiler arguments: -compute-digest=false

3) put in the folder (WinXP): C:\Documents and Settings\{username}\Local Settings\Application Data\Adobe\Flash CS3\en\Configuration\Components

4) Flash CS3 > Components Panel > Reload (Menu)

Wednesday, May 20, 2009

Fireworks effect

Created a fireworks effect component.
FLA: fireworks_cs3.fla


Drag the fireworks component from the library to the Stage.
Modify the component parameters from the Component Inspector Panel. play around with different values for different effect.

parameters:
- burstVelMin/Max : min and max speed of the particles when fireworks explode. randomise. higher, faster
- colour: colour of fireworks
- drag: how fast the particles will slow down. lower number, slow down faster
- gravity: how fast the particle will fall downward. higher number, faster the drop
- numFramesToBurst: number of frames before the fireworks explode
- numParticles: number of particles when the the fireworks explode
- particleLifeSpan: number of frames before particles will disappear
- particleSizeGrowth: how fast the size of the particle will grow. higher number, bigger the growth
- trailDecay: how fast the trail will disappear. higher number, faster
- vx / vy: starting speed in x and y direction

Saturday, March 28, 2009

Mobile Assignment done during NTU course

Collection of images done for my mobile design assignment:


Wednesday, March 18, 2009

Tuesday, February 17, 2009

Flash webcam tracking experiment

Used the same logic in Touchless SDK. port it into Flash. tracking using colour histogram.
Use the mouse to drag and select an object to track.

Monday, January 26, 2009

Flash 10, 3D and BSP Tree

Used a Binary Space Partitioning (BSP) Tree to sort the order of the triangles to be drawn on the screen using Flash 10 3D API.

http://psalmhundred.net/experiment/flash3d/coffee_table_bsp/
BSP Tree Component: BSPTree.swc
Updated BSPTree.swc: 01 Feb 2009. Resolved some bugs.
02 Feb 2009. optimised code
24 Feb 2009. changed code. using timer-based instead of loops to add triangles to tree nodes. to avoid script timeout limit.

1) Import package
import dmp.*;
2) Create a BSPTree object
var tree:BSPTree = new BSPTree();
3) Add the vertices and uvt data of the model
tree.add(vertices, uvt);
4) Sort by model composite transform or by camera location
tree.sortByModelTransform(compositeM, outVertices, outUVT);
OR
tree.sortByCameraLoc(cameraLoc, outVertices, outUVT);
5) Transform & project outVertices and outUVT to draw model

Source:
BSP Tree library
BSP Tree sample program

Tuesday, January 20, 2009

Security Error 2148: while loading XML

http://adobeflash.wordpress.com/2007/01/13/error-2148-loading-xml-with-flex2-security-error/

adding the "-use-network=false" argument works in Flex Builder.

hmmm. strange. sometimes, it works without adding the argument.

Monday, January 19, 2009

OBJ to DMP format

A convertor I wrote using Actionscript 3.0 and Flex to convert from OBJ to a custom XML format i used for my students' assignment
link to OBJ format: http://en.wikipedia.org/wiki/Obj
Export from 3D tools, eg.: Maya, to OBJ format
Open the OBJ file in a text editor, eg.: Notepad. Copy and paste the data into this application. Enter the texture filename. and click "Convert"

Tuesday, January 06, 2009

3D in Flash 10

Loaded a COLLADA model from an external DAE file.
Use cursor keys, W,A,S,D and the mouse to manipulate the model.
Flash 10 player required. http://get.adobe.com/flashplayer/
Applied simple clipping, sorting of triangles.
Frame rate will drop when number of triangles is about 1K+.


http://psalmhundred.net/experiment/flash3d/TrianglesApp.html

Wednesday, November 26, 2008

Sunday, November 16, 2008

Flash AS3 Custom Component - parameters

If the parameters are modified during authoring time,
they are not ready til after the constructor is called.


package{
import flash.display.*;
import flash.events.*;
import flash.net.*;
public class Testing extends MovieClip{
[Inspectable]
public var id:Number = 0;
function Testing(){
this.addEventListener(MouseEvent.CLICK, mouseclick);
}
function mouseclick(e:MouseEvent):void{
trace("id" + id);
}
}
}

Tuesday, August 12, 2008

Elastic Flash Demo

Key in a number from 2-20 in the textbox and click the button to generate an elastic object. Use the mouse to drag the dots.

Tuesday, July 08, 2008

Microsoft.Win32.OpenFileDialog affect FileIO operation

Just found out that if I use the following code to retrieve a filename, the FileStream will be affected as the current directory will be set to where the filename was taken from, eg.: "My Documents", instead of the Application Path.

OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "All files (*.*)|*.*";
if ((bool)dialog.ShowDialog())
{
// store filename
}

// and later in the code
FileStream stream = new FileStream(
"mydata.bin", FileMode.Create);
BinaryWriter writer = new BinaryWriter(stream);
// write some data
stream.Close();
// "mydata.bin" will be saved in the current directory of OpenFileDialog

One solution will be to use the application path and extract the directory:
String path = System.Reflection.Assembly.GetExecutingAssembly().Location;

another will be to use RestoreDirectory property of the OpenFileDialog. set it to true.

Thursday, June 19, 2008

Flash 10 3D Demo - partial cube

NOT working. Flash 10 player has been updated to official release.

Requires Flash 10 (currently beta)
http://labs.adobe.com/downloads/flashplayer10.html

Demo of rotating cube(partial to see culling effect):
http://psalmhundred.net/experiment/flash3d/Flash10App.html

Flash 10 3D API - Utils3D.projectVectors(...)

Utils3D.projectVectors(m:Matrix3D, verts:Vector, projectedVerts:Vector, uvts:Vector) causes Flash player 10 beta to crash currently.

so just a workaround, a custom method to do similar thing:

public function projectVectors(projMatrix:Matrix3D, vert:Vector.<Number>,
v2D:Vector.<Number>, uvt:Vector.<Number>):void{

var temp:Vector.<Number> = new Vector.<Number>(vert.length);
projMatrix.transformVectors(vert, temp);
var z:Number = 0;
for(var i:int = 0; i<temp.length/3; i++){
z = temp[i*3+2];
z = focalLength / (focalLength+z);
// x' = f*x/(f+z), y' = f*y/(f+z)
v2D[i*2] = temp[i*3]*z;
v2D[i*2+1] = temp[i*3+1]*z;
// t = f/(f+z)
uvt[i*3+2] = z;
}
}

Thursday, April 12, 2007

WPF: Media Player

MediaPlayer player;
Uri uri = new Uri("pack://siteoforigin:,,,/music.mp3");
player = new MediaPlayer();
player.Open(uri);
player.Play();

Wednesday, April 11, 2007

WPF: setting cursor

eg:
void Page1_MouseMove(object sender, MouseEventArgs e)
{
e.MouseDevice.SetCursor(Cursors.Hand); //-- hand cursor
e.MouseDevice.SetCursor(Cursors.None); //-- none, invisible
}