FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   Language Comparison: P5/Python/DBN/ActionScript
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Language Comparison: P5/Python/DBN/ActionScript  (Read 535 times)
REAS


WWW
Language Comparison: P5/Python/DBN/ActionScript
« on: Jan 24th, 2003, 4:43pm »

I've posted an abbrieviated language comparison between a few languages at:
http://www.proce55ing.net/reference/compare/index.html
 
My understanding was that Python has many different drawing packages and none are included with the standard download so i didn't include Python graphic translations.
 
Can anyone take care of the ActionScript translation?
 
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: Language Comparison: P5/Python/DBN/ActionScrip
« Reply #1 on: Jan 25th, 2003, 6:17am »

hope this helps.
http://www.instituteofmedia.com/p5-actionscript/
« Last Edit: Jan 25th, 2003, 4:54pm by Martin »  
REAS


WWW
Re: Language Comparison: P5/Python/DBN/ActionScrip
« Reply #2 on: Jan 25th, 2003, 7:39pm »

Thank you Martin. Jim Qode sent us a list as well. It's currently posted at:
http://www.proce55ing.net/reference/compare/index.html  
 
There are many differences between the two lists. Can the two of you please explain the differences?
 
Best,
Casey
 
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: Language Comparison: P5/Python/DBN/ActionScrip
« Reply #3 on: Jan 26th, 2003, 6:29am »

hi casey,
 
the commands / methods i used are largely based on the actionscript dictionary which may be found at http://www.macromedia.com/support/flash/action_scripts/actionscript_dict ionary/
 
i'll go through the differences one by one...
 
+ color
 
background of the movie may be set using the setRGB method in flash. you can try the .fla found at http://www.virtual-fx.net/tutorials/html/setrgb.html as an example.
 
stroke is basically the same thing. changing the color of objects found in a movie ... http://www.kirupa.com/developer/actionscript/color.asp
 
+ shape
 
point can be achieved if you'd create your own function for this.
 
i used the values given for line.
 
there is no native method for rect() but you can create your own function. combining moveto and lineto may do the trick but it'll be a mess to change a value.
 
+ data
 
the 'var' action is used to declare variables as given by http://www.macromedia.com/support/flash/action_scripts/actionscript_dict ionary/actionscript_dictionary816.html though no real need. for formal.
 
no need to declare an array object. use [] directly. refer to http://www.macromedia.com/support/flash/action_scripts/actionscript_dict ionary/actionscript_dictionary026.html
 
do comes with while. so...
do {
// statements
} while ( 1 != 0 )
might just work. ... what i did was another while function that will infinitely loop as it is infinitely true (unless of course there are some changes made inside the {}).
 
+ structure
 
ah yes, you can add square(X) in the end. forgot to add that.
 
+ input
 
there are a lot of _xmouse actions. you can do it for textfield, button and movie. pls refer to http://www.macromedia.com/support/flash/action_scripts/actionscript_dict ionary/actionscript_dictionary584.html
 
same goes with _ymouse...
 
to use mousepressed as a boolean, just place a boolean inside the mousedown function. that'll do the trick.
 
others good for declaring object.
 
cheers!
 
XemonerdX

3701800137018001 WWW Email
Re: Language Comparison: P5/Python/DBN/ActionScrip
« Reply #4 on: Jan 26th, 2003, 7:39am »

A few comments on the ActionScript bit...
Quote:
background of the movie may be set using the setRGB method in flash.

This is not true, there is no direct way to access or change the movie's background using ActionScript. The example mentioned doesn't do this either, it uses a movieclip (an object) that is below all other objects and the color of this movieclip is changed, thus making it appear as if the movie's backgroundcolor has been changed.
 
'MovieClip.beginFill(0xFF9900,a)' is the ActionScript drawingAPI equivalent of fill(...), altho it also requires 'MovieClip.endFill()' after drawing the shape of the fill.
http://www.macromedia.com/support/flash/action_scripts/actionscript_dict ionary/actionscript_dictionary509.html
 
'MovieClip.lineStyle(x,0xFF9900,a)' is another one of the new drawingAPI methods available inside FlashMX to create lines from scratch thru code (which was not possible in previous versions of Flash where the user had to work with pre-defined movieclips etc). So both 'lineStyle' and 'setRGB' can be used as an equivalent of stroke.
http://www.macromedia.com/support/flash/action_scripts/actionscript_dict ionary/actionscript_dictionary535.html
 
Drawing a point in ActionScript can be as simple as:
this.lineStyle(1);
this.lineTo(0.5,0);
 
In ActionScript loop's like do {...} while(...) and while(...) {...} will *not* render each iteration onto the screen, therefore you will not see an 'animation' like you do with P5's void loop() {...}. Flash will run the loop for as long as it can (it gives a warning message after 15 secs tho) and will display the results *after* the loop has finished, halting *everything* visible inside the movie in the mean time. So this is hardly an equivalent. A more appropriate equivalent would be 'MovieClip.onEnterFrame' which runs a funtion every frame (the result of which is displayed on each frame)
http://www.macromedia.com/support/flash/action_scripts/actionscript_dict ionary/actionscript_dictionary546.html
 
Quote:
the 'var' action is used to declare variables as given by http://www.macromedia.com/support/flash/action_scripts/actionscript_dict ionary/actionscript_dictionary816.html though no real need. for formal.

Actually 'var' has a very real purpose & need. A variable declared inside a function using 'var' is local to that function and will not be available after the function has completed, a variable declared inside a function without using 'var' will continue to be available after the function has completed... Small example:
myFunc = function () {
    var var1 = "this is var1";
    var2 = "this is var2";
}
myFunc();
trace(var1); // output: undefined
trace(var2); // output: this is var2
http://www.macromedia.com/support/flash/action_scripts/actionscript_dict ionary/actionscript_dictionary816.html
 
Etc...
 
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: Language Comparison: P5/Python/DBN/ActionScrip
« Reply #5 on: Jan 26th, 2003, 10:23am »

i see i see. thanks for the tips/clarifications.
 
REAS


WWW
Re: Language Comparison: P5/Python/DBN/ActionScrip
« Reply #6 on: Jan 31st, 2003, 10:24am »

I have posted my attempted synthesis of all comments:
 
http://www.proce55ing.net/reference/compare/index.html  
 
Did I miss or mistake something?
« Last Edit: Jan 31st, 2003, 10:25am by REAS »  
Dara

WWW Email
Re: Language Comparison: P5/Python/DBN/ActionScrip
« Reply #7 on: Jan 31st, 2003, 10:58am »

hi,
 
Color>Fill for Action Script
 
beginFill (0x006699, alpha);
beginGradientFill(filltype, colors[], alphas, ratios, matrix);
 
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: Language Comparison: P5/Python/DBN/ActionScrip
« Reply #8 on: Jan 31st, 2003, 3:03pm »

hi casey, er... one thing. misspelled my name. hehe. thnks!
 
XemonerdX

3701800137018001 WWW Email
Re: Language Comparison: P5/Python/DBN/ActionScrip
« Reply #9 on: Feb 4th, 2003, 1:21am »

The AS-equivalent for the point(30,20) example is wrong, it should be:
lineStyle(x);
moveTo(x1,y1);
lineTo(x1+0.5,y1);
The '+0.5' does need to be added (it has to be at least 0.15, doesn't matter if it's added/substracted from the x or y component).
 
And like mentioned before in my previous reply, a loop made in AS ('do{...}' etc) will *not* render the result of each iteration, but only the result *after* the loop has finished completely, whereas 'void loop() {...}' *does* render each iteration in P5, so not sure if the equivalence works there... I would suggest 'onEnterFrame = function () {...}' which *does* render the result every time it is called in AS...
 
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: Language Comparison: P5/Python/DBN/ActionScrip
« Reply #10 on: Feb 4th, 2003, 8:44am »

logic of while(true){//stuff}; works ... hmm... i have an example up at www.instituteofmedia.com/diwa.html but i stopped it at 500... will make one that's infinite later.
 
JimQode

251091251091 Email
Re: Language Comparison: P5/Python/DBN/ActionScrip
« Reply #11 on: Feb 4th, 2003, 6:10pm »

about the point(30,20) subject:
 
moveTo(x1,y1);
lineTo(x1,y1);
 
doesnt draw anything in actionscript. and 0.15 (which is a smaller number than 0.5) draws a very faint dot because of the anti-aliasing algorithm of flash.
 
 

--- End Of Transmission ---
XemonerdX

3701800137018001 WWW Email
Re: Language Comparison: P5/Python/DBN/ActionScrip
« Reply #12 on: Feb 5th, 2003, 5:36pm »

Quote:

0.15 (which is a smaller number than 0.5) draws a very faint dot because of the anti-aliasing algorithm of flash.

This depends on the thickness set in the lineStyle statement, if you use thickness 2 the point is clearly visible.
The only reason I mentioned 0.15 is that AFAIK it is the smallest length possible for a line that will still be drawn on the screen, nothing gets drawn if you use for instance 0.14 (or less), even if you set the thickness to 255 (the maximum value).
Quote:

logic of while(true){//stuff}; works ...

Unless you have *some* sort of frame/time-based loop in your program (frame-loop, onEnterFrame, onClipEvent(enterFrame), setInterval, etc), a while-loop by itself will *not* render the results of each iteration on the screen, only the result of the last iteration of the while-loop before it exits... If you think you've managed to do it somehow, *please* share your code/method, cuz even on the FlashCoders list (which is the most hardcore AS-list) noone's ever done it, nor does anyone dispute the fact that it cannot be done.
« Last Edit: Feb 5th, 2003, 5:45pm by XemonerdX »  
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: Language Comparison: P5/Python/DBN/ActionScrip
« Reply #13 on: Feb 6th, 2003, 2:58pm »

precisely. come to think of it, flash has a 200,000 iteration limit... i guess this is a great limiting factor in flash (or is it?)
 
hack your own flash?
« Last Edit: Feb 6th, 2003, 2:59pm by Martin »  
XemonerdX

3701800137018001 WWW Email
Re: Language Comparison: P5/Python/DBN/ActionScrip
« Reply #14 on: Feb 7th, 2003, 11:29pm »

There are very easy ways of dealing with the 200,000 iterations problem (not to mention that doing 200,000 iterations in Flash slows most computers down to a grinding halt since Flash isn't a speed-freak unfortunately, so why even attempt, hehee), such as using a setInterval that calls a function that does for instance 1,000 of all the necessary calculations every time it calls the function, which also has the advantage the screen gets updated more frequently... There are more workarounds obviously...
 
The iteration limit is only a minor problem in Flash/ActionScript IMHO (and I *love* ActoinScript), cuz it's easy to deal... If only Flash had the speed of Java/P5 One can only dream I guess, hahaha...
 
Pages: 1 

« Previous topic | Next topic »