PDA

View Full Version : nice and easy one :)


stealthelephant
10-13-2003, 07:00 PM
ur own matrix effects, all in actionscript if anyone dares

pom
10-14-2003, 07:09 AM
I've done one recently that can be seen (and downloaded) here:

http://www.kirupa.com/lab/matrix.htm

But I'll be glad to see your own implementations of it :)

stealthelephant
10-14-2003, 07:48 AM
how u get that font?
mine still a work in progress but it has normal letters :(

stealthelephant
10-14-2003, 07:54 AM
is it all in action script?

pom
10-14-2003, 12:40 PM
You can get that font pretty much anywhere (it's called katakana) and yes, it's all-code :)

stealthelephant
10-14-2003, 12:44 PM
all i can say is

muwahahahahahahhahaa
:D

pom
10-14-2003, 12:58 PM
:confused:

stealthelephant
10-14-2003, 01:05 PM
now i have the font :) and my version is starting to look a whole load better.

thats some pretty impressive AS u got there, mine is all in OO and there is a little more of it, nearly finished

vulcanpimp
10-15-2003, 01:09 PM
hey Pom that effect is v cool!!

thanks for the url as well as I hadn't spotted that page on senoculars site.

......can someone lend me a CDR so I can download Poms fla

pom
10-16-2003, 07:30 AM
That's not Senocular's site! :D It's Kirupa :cool: And what's a CDR?

senocular
10-16-2003, 09:21 AM
no, its my site.... I am kirupa too :cool:

McGiver
10-16-2003, 01:02 PM
lol
isn't there a little kirupa in all of us

vulcanpimp
10-16-2003, 01:06 PM
a CDR is a recordable compact disc - though I would usually use a CDRW(rewritable).

Just so I can save the fla and take it home - guess a floppy would do - but my computer doesn't have one of those

pom
10-17-2003, 09:25 AM
Kirupas wannabes... :rolleyes:

stealthelephant
10-17-2003, 12:09 PM
Kirupas ?

can i be 1 too?

pom
10-17-2003, 01:18 PM
There you go:stealthElephant = new Kirupa () ;
Kirupa.addListener (stealthElephant) ;
Kirupa ++ ;
trace (Kirupa) ; // returns 4 now, woohoo!

McGiver
10-17-2003, 01:30 PM
*debugging poms script* ;)
stealthElephant = new Kirupa () ;//<-this would make stealthElephant an new Kirupa. Which would mean we would have a clone of kirupa
Kirupa.addListener (stealthElephant) ;//that would make stealthElephant listen to himself
Kirupa ++ ;
trace (Kirupa) ; //returns 7718 at the moment! not 4
come on Pom! I know you are abled to do it better!

senocular
10-17-2003, 01:32 PM
and can you really post-increment a constructor function?

Kirupa ++ ;


:confused:









:D

McGiver
10-17-2003, 01:41 PM
I was not sure about that, so I left it out :D

stealthelephant
10-17-2003, 03:02 PM
its using pointers , the function is storing itself in memory, if he forgets to increment, the function will run again and over write my memory space :eek:

;) :p

McGiver
10-17-2003, 03:19 PM
And once again, we saved the world from one of Pom's insane scripts... :p

pom
10-19-2003, 09:41 AM
All right, thanks for helping me with my code problems. I think I've got it now :DKirupaStack = [] ;
Kirupa = function ( pname ) {
name = pname ;
}
myKirupa = new Kirupa ("StealthElephant") ;
KirupaStack.push (myKirupa) ;
trace (KirupaStack.length) ; // returns 4 now, woohoo!

pom
10-19-2003, 09:42 AM
Originally posted by senocular
and can you really post-increment a constructor function?

Kirupa ++ ;Sure! Actually, it's going to be implemented in Flash MX 2008 :D

senocular
10-19-2003, 12:35 PM
Bah! 2008? We can do it now. Lets see here.........


... yeah

Object.prototype.DefineIncrementalConstructor = function(name, definition){
var value = 0;
var constructor = function(){
definition.apply(this, arguments);
};
constructor.toString = function(){
return String(value);
};
constructor.valueOf = function(){
return Number(value);
};
this.addProperty(name, function(){
return constructor;
}, function(v){
value = v;
}
);
};

// Use
this.DefineIncrementalConstructor("Kirupa", function(name){ this.name = name; });

trace(Kirupa); // traces 0
myKirupa = new Kirupa ("StealthElephant");
trace(myKirupa.name); // traces "StealthElephant"
Kirupa++;
trace(Kirupa); // traces 1

:D

pom
10-19-2003, 03:54 PM
:rolleyes: Wished I could write nonsense as well as you Sen :D

Sorry for the Challenge hijacking, StealthElephant. But at least, now, you're officially a Kirupa, AND you can be incremented!

senocular
10-19-2003, 04:03 PM
its the curse of the Kirupa ;)




....

++

stealthelephant
10-20-2003, 06:58 AM
stealthelephant++;:cool:

kirupa
11-02-2003, 03:29 PM
I'm senocular :D

McGiver
11-02-2003, 04:30 PM
kirupa here?
I guess we can put both forums together in some months :p

junahu
11-03-2003, 09:55 AM
stealthelephant = kirupa

senocular
11-04-2003, 01:54 PM
Originally posted by kirupa
I'm senocular :D

lol

Johnwun
11-06-2003, 01:13 PM
Originally posted by senocular
Bah! 2008? We can do it now. Lets see here.........


Sorry to continue the tangent on this thread, but...

Damn, Sen, where did you learn to do that? I've been pouring over this code for half an hour, and I think I finally sort of figured out how it works, but I've never seen anything like it...
:confused:
Until now my Actionscript bible has been ASDG, but I've never seen Moock do anything like this.
What do you use for reference books?

Also, I'd never seen anyone use the "apply" method before... How does it differ from "call"? I read the Macromedia Reference on both, but it seems to me that they are functionally equivilant... Please explain if you have the time...

thanks,
-J

senocular
11-06-2003, 01:43 PM
1) I dont use any books

2) despite many requests, I dont plan on making one of my own ;)

3) apply is more or less exactly like call aside from one difference. That difference is that instead of sending arguments through a comma separated list following the object the function is used on, the arguments are passed all at once in the single argument following the object as an array. This makes apply not only good for calling functions in the scopes of other objects, but also converting arrays into argument lists for functions (which is dandy). So in that example I posted, apply is used to transfer the arguments array of the constructor call into the definition function as to have it act as the constructor using whatever arguments the constructor recieved. Call wouldnt have worked because we dont know how many arguments would be passed - different constructors can pass different number of arguments. Apply works great because the arguments array can be passed right in and have it correctly transfer all the arguments in that call to the function its being used on.

There are some other tricks going on in there using local function scope and the use of toString and valueOf... if you have any more questions, let me know and Ill see what I cant do to try to answer them :D

Johnwun
11-06-2003, 02:08 PM
Originally posted by senocular
There are some other tricks going on in there...

and then some!!!
Thanks for the quick and thorough response. I get it... Neat...


Now for the rest of it...

God.. Where to begin... It's like a poem, the more I look at it, the more hidden complexity I see...

Here you pass an entire (unnamed) function from within the function call... (Not obvious, but cool.)

this.DefineIncrementalCons("Kirupa", function (name) {
this.name = name;
});
That threw me for awhile... but I understand you are passing the nameless function to define how a "Kirupa" object behaves with the 'apply' in the DefineIncrementalConstructor...

And, yeah, ok, I am at a total loss how you are using cons.valueOf and cons.toString...

I dont see them explicitly called anywhere, but I'm guessing they are somehow related to the getter/setter functions in addProperty... Am I right?

senocular
11-06-2003, 02:24 PM
Ill just go through and explain the whole thing ;)

So first the idea: The idea is to have a variable that exists that can serve not only as an incremental value, but also as a constructor function.


...oops I have to go on a shoot now, Ill have to finish this up later this evening :o


;)

Johnwun
11-06-2003, 04:30 PM
A shoot? Good lord, you're a movie star too?

Ok, well, Hopefully I'll save you some time, and take a shot at explaining your code the way I see it.
You can see if I'm close... I think it goes something like this...


//this creates a new property of the "Object" object...
//which initializes a variable "value" to 0
//for each object this is called on.

Object.prototype.DefineIncrementalConstructor = function(name, definition) {
//initialize variable "value" to 0
var value = 0;
// creates a new "constructor" object
var constructor = function () {
// the next line defines the behavior
// of the "constructor" object,
// based on the function sent as a parameter.
// when "Kirupa" is created,
// the "arguments" array is passed a function as a parameter
// which defines a "Kirupa" objects "name" parameter...
// this executes when "myKirupa" is instantiated...
definition.apply(this, arguments);
};
//the object constructed (Kirupa) will now
//return the var "value" as a string when called as:
//Kirupa.toString();
//this is used internally when the Kirupa object gets incremented...
constructor.toString = function() {
return String(value);
};
//the object constructed (Kirupa) will now
//return the var "value" as a number when called as:
//Kirupa.valueOf();
//this is used internally when the Kirupa object gets incremented...
constructor.valueOf = function() {
return Number(value);
};
//addProperty just creates getter and setter functions for the object.
this.addProperty(name, function () {
// getter:
// returns the whole dang (Kirupa) object!!!
// I assume this works because the object gets
// evaluated internally using the valueOf() function
// when used as a number... i.e.;
// trace(Kirupa + 30); // is internally seen as:
// trace(Kirupa.valueOf() + 30);
// which should yeild the same result...
return constructor;
}, function (v) {
// setter:
// simply sets "value" to whatever is sent...
// no type checking, so I can set it to a string if I want...
// Kirupa = "cool website";
// trace(Kirupa);
value = v;
});
};
//-----------------------Use----------------------
//here we create a Kirupa object, which, when instantiated
//will be allowed a "name" parameter...
//"this" refers to _level0. I think... )
this.DefineIncrementalConstructor("Kirupa", function (name) {
this.name = name;
});
// and here's the new bouncing baby Kirupa...
trace(Kirupa); // traces Kirupa.toString(), or 0
//create a new "Kirupa" with a "name" parameter...
myKirupa = new Kirupa("StealthElephant");
trace(myKirupa.name); // traces "StealthElephant"
//I love this line...
// it is first using Kirupa's getter AND THEN using it's setter.
//broken apart, it would look like this...
//set Kirupa to Kirupa.valueOf() plus 1
Kirupa++;
trace(Kirupa); // traces Kirupa.toString(), or 1

That sound about right? I ran out of lines to comment, so thats GOTTA be it. Please fill in the gaps if I missed anything.

thanks for the mental exercise...
-J

senocular
11-06-2003, 05:13 PM
Thats about it ;)

Some things to note:

- The getter is always called when Kirupa is accessed. When it is accessed, the constructor function created in the DefineIncrementalConstructor call is returned. This function basically IS Kirupa. Its whats used to define new Kirupa instances but also has the added toString and valueOf methods defined for it to retrieve the value variable.

- The 'value' variable is a local variable in DefineIncrementalConstructor. It actually exists only from that function call, however, because toString, valueOf and the getter/setter functions are also defined in the DefineIncrementalConstructor call, they retain access to value even after DefineIncrementalConstructor has completed. And its this value thats used in Kirupa's "value" as you correctly noticed was obtained through toString and valueOf BUT through the access of the getter function which returns the constructor function. The setting of value is through the setter.
... really its the getter and setter functions defined in the addProperty that do the work while toString and valueOf direct the flow as needed.


Whenever Kirupa is accessed, the getter is run and constructor is returned.
Constructor is defined as a function so is a function unless access is forcibly trying to get a string or number value wherein toString or valueOf take over.
When toString and valueOf take over, the value variable is returned.
When ever Kirupa is assigned to be something, the setter is run and value is assigned.

So you have a property which cant be redefined because each definition its set to is automatically re-routed to its value variable and whos actual "value" is a determination between its real function value and toString (string representation) and valueOf (numeric representation).



Because addProperty is used, DefineIncrementalConstructor needed to act more or less just like addProperty only with one function. Thats why its an Object prototype - so all objects could use it if needed... the 'this' used when called was just whatever object (timeline) the code was in when run... which if in the main timeline would be _level0.

the definition.apply(this, arguments); line I think you nailed. the constructor function as a function just calls the function passed to be what it should be as a function. Apply is used to transfer the arguments (name from the function passed in DefineIncrementalConstructor) to the actual constructor (or definition) call.

:)

Johnwun
11-06-2003, 06:22 PM
look, a practical application... :) ... not...

to test this,
just tack this code at the bottom of the code listed above...

//----------------------misUse----------------------
this.DefineIncrementalConstructor("Senocular", function (name, bDay) {
this.name = name;
this.age = howOld(bDay);
function howOld(bDay) {
this.bday = bday.split("/");
this.date_da = new Date();
this.bday_da = new Date(this.bday[2], this.bday[0], this.bday[1]);
this.today_mo = date_da.getMonth();
this.today_day = date_da.getDate();
this.today_year = date_da.getFullYear();
this.age_year = today_year-bday_da.getFullYear();
if (this.today_mo<bday_da.getMonth()-1 || (this.today_mo == bday_da.getMonth()-1 && this.today_day<bday_da.getDate())) {
this.age_year -= 1;
}
return (this.age_year);
}
});
mySenocular = new Senocular("Kirupa", "9/27/1979");
trace("Next year, "+mySenocular.name+"'s creator will be "+(mySenocular.age+(Senocular++))+" years old.");


...dang I feel old...

McGiver
11-07-2003, 08:08 AM
lol@ sen
senfans++

junahu
11-07-2003, 09:32 AM
Soooo... what actually does this do (except confuse me beyond all rational thought)?

I did learn something from you people however so don't be disenheartened. I now know the logic behind 'going off on a tangent'.

(I apologise for the following babble but I need to kill some time before my next lesson. Also my understanding of tangents in mathematics are rusty at best)

a tangent being a straight line that touches a curve at one point. Using it the gradient of the curve at that point can be found. 'Going off on a tangent' therefor is when a progressive discussion which at one point the topic at that point is continued, thus leaving the main discussion behind to be suddenly reverted back to later when the tangent has run its course. From this I have guessed the following.

tangents are straight lines: if the topic of a tangent develops (becoming a curve) then it is a diversion.

a tangent of a tangent is impossible(tangents can only touch the line at one point):tangents cannot lead to more tangents.

(again I apologise for wasting post space with this grabage.
sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry .)