Using Amber to program graphics interactively

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Using Amber to program graphics interactively

Chris Marsh
Hi! I am new to Amber, and to Smalltalk. I'm looking forward to learning it, but I'm trying to understand what can be achieved, and what might be a suitable learning project.

I was very impressed to see this well-structured javascript animation framework: http://labs.hyperandroid.com/static/caat/

Would this translate well into Amber? Would it then enable me to code graphics interactively, seeing the results as I create objects?

If so, this could be a very powerful and enjoyable way to play with programming and graphics. But are there other intentions in that direction for Amber, such as implementing the 'Morph'-style graphics of Pharo (forgive my ignorance here).

I'd appreciate any opinions.
Reply | Threaded
Open this post in threaded view
|

Re: Using Amber to program graphics interactively

Kevin Driedger-4
A previous thread touched on something similar:

Kevin


On Thu, Nov 24, 2011 at 1:54 PM, Chris Marsh <[hidden email]> wrote:
Hi! I am new to Amber, and to Smalltalk. I'm looking forward to learning it, but I'm trying to understand what can be achieved, and what might be a suitable learning project.

I was very impressed to see this well-structured javascript animation framework: http://labs.hyperandroid.com/static/caat/

Would this translate well into Amber? Would it then enable me to code graphics interactively, seeing the results as I create objects?

If so, this could be a very powerful and enjoyable way to play with programming and graphics. But are there other intentions in that direction for Amber, such as implementing the 'Morph'-style graphics of Pharo (forgive my ignorance here).

I'd appreciate any opinions.

Reply | Threaded
Open this post in threaded view
|

Re: Using Amber to program graphics interactively

abergel
In reply to this post by Chris Marsh
Indeed, quite impressive.

Alexandre


On 24 Nov 2011, at 15:54, Chris Marsh wrote:

> Hi! I am new to Amber, and to Smalltalk. I'm looking forward to learning it, but I'm trying to understand what can be achieved, and what might be a suitable learning project.
>
> I was very impressed to see this well-structured javascript animation framework: http://labs.hyperandroid.com/static/caat/
>
> Would this translate well into Amber? Would it then enable me to code graphics interactively, seeing the results as I create objects?
>
> If so, this could be a very powerful and enjoyable way to play with programming and graphics. But are there other intentions in that direction for Amber, such as implementing the 'Morph'-style graphics of Pharo (forgive my ignorance here).
>
> I'd appreciate any opinions.

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.





Reply | Threaded
Open this post in threaded view
|

Re: Using Amber to program graphics interactively

Chris Marsh
In reply to this post by Kevin Driedger-4
Kevin, thanks for pointing me to the thread highlighting Morphic.js and how it could be integrated with Amber. Does this mean that most Amber programmers would be more inclined to use the familiar Morphic classes to create animations and games, rather than a scenegraph model like CAAT?

I've been looking at the Morphic classes and personally find the object model of CAAT easier to grasp and intuitively more appealing.
Reply | Threaded
Open this post in threaded view
|

Re: Using Amber to program graphics interactively

Kevin Driedger-4
I cannot speak to the scene graph modelling but I suspect Morphic has been mentioned due to the Smalltalk heritage. 

Some other pointers on integrating js libs have been mentioned on the list as well.... if you can't find in a search I'll take a look



On Thu, Nov 24, 2011 at 2:26 PM, Chris Marsh <[hidden email]> wrote:
nally find the object model of CAAT easier to grasp and intuitively more appealing.

Reply | Threaded
Open this post in threaded view
|

Re: Using Amber to program graphics interactively

Hannes Hirzel
I would say that it is worthwhile to give integrating
http://labs.hyperandroid.com/static/caat/ a try. The Amber Smalltalk
objects _are_ JavaScript objects. You can have Amber Smalltalk methods
call JavaScript as the 'language of the Virtual Machine'. And the
methods of a JavaScript object may be called with a Smalltalk method.
See the presentation for an explanation.

--Hannes

On 11/24/11, Kevin Driedger <[hidden email]> wrote:

> I cannot speak to the scene graph modelling but I suspect Morphic has been
> mentioned due to the Smalltalk heritage.
>
> Some other pointers on integrating js libs have been mentioned on the list
> as well.... if you can't find in a search I'll take a look
>
>
>
> On Thu, Nov 24, 2011 at 2:26 PM, Chris Marsh <[hidden email]> wrote:
>
>> nally find the object model of CAAT easier to grasp and intuitively more
>> appealing.
>
Reply | Threaded
Open this post in threaded view
|

Re: Using Amber to program graphics interactively

Chris Marsh
Thanks for the encouragement. This was the bit I haven't grasped - I thought I'd have to create interface classes and methods to call the JavaScript functions. But it's transparent? How do the arguments map? Sorry for the obvious questions, but I've looked through the Group, and on on the site, and have missed the explanation of how this works.
Reply | Threaded
Open this post in threaded view
|

Re: Using Amber to program graphics interactively

gokr
In reply to this post by Chris Marsh
The idea is indeed to be able to use js libs without any glue at all. The nodejs examples (TrivialServer for example) do this for example. There is one detail that is a non obvious trick and that is how we call js function foo(x, y) and we do it like this:

someObject foo: x bar: y

...where bar could have been banana: or whatever. ;)

We should make a wiki page about these things.

regards, Göran



-- Sent from my Palm Pre 2, wohoo!


On Nov 25, 2011 18:56, Chris Marsh <[hidden email]> wrote:

Thanks for the encouragement. This was the bit I haven't grasped - I thought I'd have to create interface classes and methods to call the JavaScript functions. But it's transparent? How do the arguments map? Sorry for the obvious questions, but I've looked through the Group, and on on the site, and have missed the explanation of how this works.
Reply | Threaded
Open this post in threaded view
|

Re: Using Amber to program graphics interactively

Andy Burnett
Thanks for the example Göran, I was struggling to get my head about how that was done.

Could you do one other act of simplification for me? I would like to see the simplest possible example - in Amber - of how one would load a JS library - assume it is one that google, or someone, hosts. And, then call one of its functions.

Cheers
Andy

2011/11/25 Göran Krampe <[hidden email]>
The idea is indeed to be able to use js libs without any glue at all. The nodejs examples (TrivialServer for example) do this for example. There is one detail that is a non obvious trick and that is how we call js function foo(x, y) and we do it like this:

someObject foo: x bar: y

...where bar could have been banana: or whatever. ;)

We should make a wiki page about these things.

regards, Göran



-- Sent from my Palm Pre 2, wohoo!


On Nov 25, 2011 18:56, Chris Marsh <[hidden email]> wrote:

Thanks for the encouragement. This was the bit I haven't grasped - I thought I'd have to create interface classes and methods to call the JavaScript functions. But it's transparent? How do the arguments map? Sorry for the obvious questions, but I've looked through the Group, and on on the site, and have missed the explanation of how this works.

Reply | Threaded
Open this post in threaded view
|

Re: Using Amber to program graphics interactively

Nicolas Petton
On Fri, 2011-11-25 at 14:02 -0500, Andy Burnett wrote:
> Thanks for the example Göran, I was struggling to get my head about
> how that was done.
>
>
> Could you do one other act of simplification for me? I would like to
> see the simplest possible example - in Amber - of how one would load a
> JS library - assume it is one that google, or someone, hosts. And,
> then call one of its functions.

Hi!

You can simply load it in the head of the page. To call it, here's an
example with the jQuery library.

Call the global jQuery function (which is in fact attached to window):

in JS:
jQuery('div')
or:
window.jQuery('div')

in Amber:
window jQuery: 'div'

if in amber you do:
Transcript show: jQuery

you'll see that jQuery is a block closure (a function in JS). This means
you can also do:

jQuery value: 'div'

While it's not really elegant, it can help you understand the
relationship between Amber and JavaScript.

Also note that amber allows you to inspect, print, etc JavaScript
objects like if they were Smalltalk objects.

Cheers,
Nico

>
>
> Cheers
> Andy
>
> 2011/11/25 Göran Krampe <[hidden email]>
>         The idea is indeed to be able to use js libs without any glue
>         at all. The nodejs examples (TrivialServer for example) do
>         this for example. There is one detail that is a non obvious
>         trick and that is how we call js function foo(x, y) and we do
>         it like this:
>        
>         someObject foo: x bar: y
>        
>         ...where bar could have been banana: or whatever. ;)
>        
>         We should make a wiki page about these things.
>        
>         regards, Göran
>        
>        
>        
>         -- Sent from my Palm Pre 2, wohoo!
>        
>        
>         ______________________________________________________________
>         On Nov 25, 2011 18:56, Chris Marsh <[hidden email]>
>         wrote:
>        
>        
>         Thanks for the encouragement. This was the bit I haven't
>         grasped - I thought I'd have to create interface classes and
>         methods to call the JavaScript functions. But it's
>         transparent? How do the arguments map? Sorry for the obvious
>         questions, but I've looked through the Group, and on on the
>         site, and have missed the explanation of how this works.
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Using Amber to program graphics interactively

Andy Burnett
Hi Nico,

That's great.  And, just to get things completely straight in my mind, you are saying that there is no specific Amber method for loading a JS library dynamically. I.e. I can't do 

Smalltalk loadLibrary: '<URL of library>'.

Instead, I just hard code it as a <script> call like a normal html page, and then start using Amber to instantiate the objects, right?

Cheers
Andy

On Fri, Nov 25, 2011 at 17:16, Nicolas Petton <[hidden email]> wrote:
On Fri, 2011-11-25 at 14:02 -0500, Andy Burnett wrote:
> Thanks for the example Göran, I was struggling to get my head about
> how that was done.
>
>
> Could you do one other act of simplification for me? I would like to
> see the simplest possible example - in Amber - of how one would load a
> JS library - assume it is one that google, or someone, hosts. And,
> then call one of its functions.

Hi!

You can simply load it in the head of the page. To call it, here's an
example with the jQuery library.

Call the global jQuery function (which is in fact attached to window):

in JS:
jQuery('div')
or:
window.jQuery('div')

in Amber:
window jQuery: 'div'

if in amber you do:
Transcript show: jQuery

you'll see that jQuery is a block closure (a function in JS). This means
you can also do:

jQuery value: 'div'

While it's not really elegant, it can help you understand the
relationship between Amber and JavaScript.

Also note that amber allows you to inspect, print, etc JavaScript
objects like if they were Smalltalk objects.

Cheers,
Nico

>
>
> Cheers
> Andy
>
> 2011/11/25 Göran Krampe <[hidden email]>
>         The idea is indeed to be able to use js libs without any glue
>         at all. The nodejs examples (TrivialServer for example) do
>         this for example. There is one detail that is a non obvious
>         trick and that is how we call js function foo(x, y) and we do
>         it like this:
>
>         someObject foo: x bar: y
>
>         ...where bar could have been banana: or whatever. ;)
>
>         We should make a wiki page about these things.
>
>         regards, Göran
>
>
>
>         -- Sent from my Palm Pre 2, wohoo!
>
>
>         ______________________________________________________________
>         On Nov 25, 2011 18:56, Chris Marsh <[hidden email]>
>         wrote:
>
>
>         Thanks for the encouragement. This was the bit I haven't
>         grasped - I thought I'd have to create interface classes and
>         methods to call the JavaScript functions. But it's
>         transparent? How do the arguments map? Sorry for the obvious
>         questions, but I've looked through the Group, and on on the
>         site, and have missed the explanation of how this works.
>
>



Reply | Threaded
Open this post in threaded view
|

Re: Using Amber to program graphics interactively

Nicolas Petton
On Fri, 2011-11-25 at 17:31 -0500, Andy Burnett wrote:

> Hi Nico,
>
>
> That's great.  And, just to get things completely straight in my mind,
> you are saying that there is no specific Amber method for loading a JS
> library dynamically. I.e. I can't do
>
>
> Smalltalk loadLibrary: '<URL of library>'.
>
>
> Instead, I just hard code it as a <script> call like a normal html
> page, and then start using Amber to instantiate the objects, right?

Yep, but if you want to add one, it can be easily done (in a
web-browser, this won't work on node):

Smalltalk>>loadLibrary: aString
    [:html | html script src: aString] appendToJQuery: ('body' asJQuery)

then do:

Smalltalk current loadLibrary:
'http://http://amber-lang.net/amber/js/amber.js'

Another way to do it would be to use jQuery.getScript() that would allow
you to execute a block when your script is loaded:

Smalltalk>>loadLibrary: aString onSuccess: aBlock
    jQuery getScript: aString success: aBlock

Smalltalk>>loadLibrary: aString
    self loadLibrary: aString onSuccess: []

and yes, my example is quite stupid :)

Cheers,
Nico

>
>
> Cheers
> Andy
>
> On Fri, Nov 25, 2011 at 17:16, Nicolas Petton
> <[hidden email]> wrote:
>         On Fri, 2011-11-25 at 14:02 -0500, Andy Burnett wrote:
>         > Thanks for the example Göran, I was struggling to get my
>         head about
>         > how that was done.
>         >
>         >
>         > Could you do one other act of simplification for me? I would
>         like to
>         > see the simplest possible example - in Amber - of how one
>         would load a
>         > JS library - assume it is one that google, or someone,
>         hosts. And,
>         > then call one of its functions.
>        
>         Hi!
>        
>         You can simply load it in the head of the page. To call it,
>         here's an
>         example with the jQuery library.
>        
>         Call the global jQuery function (which is in fact attached to
>         window):
>        
>         in JS:
>         jQuery('div')
>         or:
>         window.jQuery('div')
>        
>         in Amber:
>         window jQuery: 'div'
>        
>         if in amber you do:
>         Transcript show: jQuery
>        
>         you'll see that jQuery is a block closure (a function in JS).
>         This means
>         you can also do:
>        
>         jQuery value: 'div'
>        
>         While it's not really elegant, it can help you understand the
>         relationship between Amber and JavaScript.
>        
>         Also note that amber allows you to inspect, print, etc
>         JavaScript
>         objects like if they were Smalltalk objects.
>        
>         Cheers,
>         Nico
>        
>         >
>         >
>         > Cheers
>         > Andy
>         >
>         > 2011/11/25 Göran Krampe <[hidden email]>
>         >         The idea is indeed to be able to use js libs without
>         any glue
>         >         at all. The nodejs examples (TrivialServer for
>         example) do
>         >         this for example. There is one detail that is a non
>         obvious
>         >         trick and that is how we call js function foo(x, y)
>         and we do
>         >         it like this:
>         >
>         >         someObject foo: x bar: y
>         >
>         >         ...where bar could have been banana: or whatever. ;)
>         >
>         >         We should make a wiki page about these things.
>         >
>         >         regards, Göran
>         >
>         >
>         >
>         >         -- Sent from my Palm Pre 2, wohoo!
>         >
>         >
>         >
>         ______________________________________________________________
>         >         On Nov 25, 2011 18:56, Chris Marsh
>         <[hidden email]>
>         >         wrote:
>         >
>         >
>         >         Thanks for the encouragement. This was the bit I
>         haven't
>         >         grasped - I thought I'd have to create interface
>         classes and
>         >         methods to call the JavaScript functions. But it's
>         >         transparent? How do the arguments map? Sorry for the
>         obvious
>         >         questions, but I've looked through the Group, and on
>         on the
>         >         site, and have missed the explanation of how this
>         works.
>         >
>         >
>        
>        
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Using Amber to program graphics interactively

Nicolas Petton
In reply to this post by gokr
On Fri, 2011-11-25 at 19:57 +0100, Göran Krampe wrote:
>
> We should make a wiki page about these things.

Indeed, I created one:
https://github.com/NicolasPetton/amber/wiki/From-smalltalk-to-javascript-and-back

Cheers,
Nico