Posted on

A square for array structure

There is a handy short cut! Tell me if you have a great terrific idea. Of course, the goal of the code is not to slow down the system but increase and give more capabilities to run other code at the same time. PERFORMANCE EFFICIENCY is the primary objective. ha. this is my first time to use “…”. Its really interesting..
function square(w:uint,h:uint, count:uint,...kr):Array
{

trace(kr);
var ob:Array=[];
for (var i :uint =0; i<un_w; i++)
{
for (var c :uint =0; c<un_h; c++)
{
if (count==0)
{

break;
} else
{
ob[count]=[i*diff,c*diff];
count--;
}
}
}

return ob;
}

Advertisements

About Kemo

I am just an ordinary person in the garden.

3 responses to “A square for array structure

  1. heskeyo ⋅

    I fixed some error and change [for] to [while]. Please test it and tell me if this one get some improvement.

    function mixArray_while(array:Array):Array
    {
    var _length:Number = array.length,mixed:Array = array.slice(),rn:Number,it:Number,el:Object;
    while (it < _length)
    {
    el = mixed[it];
    mixed[it] = mixed[rn = it + random(_length - it)];
    mixed[rn] = el;
    it++;
    }
    return mixed;
    }
    function square(w:uint,h:uint, count:uint,...kr):Array
    {

    var ob:Array = [],i:uint,c:uint;
    op:Array;
    while (i<un_w)
    {
    while (c<un_h)
    {
    if (count == 0)
    {
    break;
    }
    ob[count] = [i * diff,c * diff];
    count--;
    c++;
    }
    i++;
    }
    if (kr[0] == "random")
    {
    op = ob;
    ob = mixArray_while(op);
    }
    trace(kr);
    return ob;
    }

  2. heskeyo ⋅

    Final fix up!!

    function square_array(un_w:uint,un_h:uint, count:uint,...kr:Array):Array
    {
    var krCount:uint = kr.length;
    var ob:Array = [],i:uint,c:uint,op:Array,j:uint = count;
    square:while (c<un_h)
    {
    i = 0;
    while (i<un_w)
    {
    if (count == 0)
    {
    break square;
    }
    ob[j - count] = [i,c];
    i++;
    count--;
    }
    c++;
    }
    //trace("====end loop111====");
    switch (krCount)
    {
    case 1 :
    if (kr[0] == "random")
    {
    op = ob;
    ob = mixArray_while(op);
    }
    break;
    }
    return ob.reverse();
    }

    function mixArray_while(array:Array):Array
    {
    var _length:uint = array.length,mixed:Array = array.slice(),rn:uint = 0,it:uint = 0,el:Object;
    while (it < _length)
    {
    el = mixed[it];
    rn = it + Math.floor(Math.random()*(_length - it));
    mixed[it] = mixed[rn];
    mixed[rn] = el;
    it++;
    }
    return mixed;
    }
    var lol = square_array(6,6,8,"random");
    trace(lol);
    trace("length:"+lol.length);

  3. I truly love your blog.. Great colors & theme.
    Did you create this web site yourself? Please reply back as I’m looking to create my own website and want to find out where you got this from or what the theme is named. Appreciate it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s