Jump to bottom

Topic: 20 Liners - January 08 - Dynamics (Page 1 of 4) Pages that link to <a href="https://ozoneasylum.com/backlink?for=29836" title="Pages that link to Topic: 20 Liners - January 08 - Dynamics (Page 1 of 4)" rel="nofollow" >Topic: 20 Liners - January 08 - Dynamics <span class="small">(Page 1 of 4)</span>\

 
wrayal
Bipolar (III) Inmate

From: Cranleigh, Surrey, England
Insane since: May 2003

posted posted 01-03-2008 17:52

This month's theme is: Dynamics.

I know we've had similar competitions in the past, but we're all still getting our throwing arms back in and this allows for some variety. So this is dynamics in the loosest requirable sense.

quote:

A code monkey said once:
As usual, the main rule is to make your script in 20 lines of (effective) code.
Comas shouldn't be used to execute several instructions on the same line
See the code sample below to illustrate the basic rules :

code:
<script type="text/javascript">



/* */ document.body.onclick = function()

/* */ {

/* 01 */ val = prompt( 'enter a number' );

/* 02 */ for( i=0; i<10; i++ )

/* */ {

/* 03 */ alert( stupidFunction( val, i ) )

/* */ }

/* */ }



/* */ function stupidFunction( a, b )

/* */ {

/* 04 */ return a>b?a:b; // I said it was a stupid function

/* */ }



</script>

e]
The document.body.onclick = function() does not count as a line as it's not some effective code and the function call could be put in the BODY tag ( or anyother HTML tag ).
The declaration of the stupidFunction() does not count either for the same reasons.
The coma in the line /* 03 */ is ok, since it simply separates the parameters of a function.




Please branch out as much as you wish from the topic! (within reason...)

Examples of possible entries :

  • A pool game
  • Particles in the wind
  • An aerofoil simulator
  • A radoll?
  • Pinball
  • ....



Best of luck to all! Can't wait to see what you might come up with



[edit] Oh God...had an extra stupid moment. That should be, of course, "JANUARY 08" in the title, but it won't let me edit it. Also, that spurious "e]" shouldn't be there - I think this is a bug! [/edit]

(Edited by wrayal on 01-03-2008 17:55)

argo navis
Bipolar (III) Inmate

From: Switzerland
Insane since: Jul 2007

posted posted 01-03-2008 18:37

We can call that a "concept entry" and label it time machine

As for the constraints that rule the Asylum, and reinventing stuff... ~coughcough shall I say.

iron_wallaby
Nervous Wreck (II) Inmate

From:
Insane since: Dec 2007

posted posted 01-03-2008 22:35

Great concept. Totally all over this!

argo navis
Bipolar (III) Inmate

From: Switzerland
Insane since: Jul 2007

posted posted 01-04-2008 08:58



...

Everybody seems to be.

Cheers,

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 01-04-2008 11:47

+1 and I should have more time in January.

wrayal
Bipolar (III) Inmate

From: Cranleigh, Surrey, England
Insane since: May 2003

posted posted 01-04-2008 14:48

Yay! Another competitor ^_^ I wonder if there are any around who only frequent the general forum but used to participate back in the day? Also, I was a fan of restricting to 20 lines - adds to the challenge. But maybe if the winner each month wants to set the line limit in addition to the topic for the following month?

Wrayal

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 01-04-2008 18:42

Settings the line/size limit is cool too.

Just make sure I don't get to set the next contest or you guys might end up with a 256b limit or something nuts like that



(Edited by poi on 01-04-2008 18:43)

iron_wallaby
Nervous Wreck (II) Inmate

From:
Insane since: Dec 2007

posted posted 01-04-2008 21:38

First entry, woo! (Simulation of a growing tree counts as dynamics, right?)

http://www.lonelypinkelephants.com/random/jan08.html

Since I have a bunch of lines left, I may modify it to actually resemble a tree growing, instead of springing, fully-formed, from the ground.

Also, I'm very sorry about the slow frame rate... there's just too many DIVs! I might try playing with the Canvas tag, too...

(Edited by iron_wallaby on 01-04-2008 21:41)

argo navis
Bipolar (III) Inmate

From: Switzerland
Insane since: Jul 2007

posted posted 01-05-2008 12:44

Stunning. Stop being sorry and spend some of that time with Ms. Wallaby, you just raised the challenge *that* much.

wrayal
Bipolar (III) Inmate

From: Cranleigh, Surrey, England
Insane since: May 2003

posted posted 01-05-2008 14:43

IW: Very impressive Like the idea, the script...even love the design Also, it most certainly comes under dynamics, don't worry ^_^ It'll be interesting to see what you can do RE speed too :P

BTW guys, I know this isn't the normal topic of conversation on this board, but as we're considering diminutive code....I think you guys might be able to give some other coders a kicking here: http://sla.ckers.org/forum/read.php?2,18790,18790 Only got a week though, so be quick!

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 01-05-2008 17:09

Using canvas, with a couple drawImage() using an image that looks like a cone with a round bottom for the joints, it just should be super fast and look even better. You could probably even make it swing in the wind and add an image of foliage for good measure.

Well done and nice code too.

Arthurio
Paranoid (IV) Inmate

From: cell 3736
Insane since: Jul 2003

posted posted 01-07-2008 17:55

my humble try

not very dynamic, nothing special either but this is the best i could come up with right now ...
edit: bah ... disregard this entry ... i'll come up with something better

(Edited by Arthurio on 01-07-2008 19:44)

wrayal
Bipolar (III) Inmate

From: Cranleigh, Surrey, England
Insane since: May 2003

posted posted 01-07-2008 23:44

Arthurio: Don't put yourself down; I think it's quite funky ^_^ Though that said, the more entries the better. Just one thing, if you find yourself running out of lines, consider the '?' operator, it could cut the 4 lines concerning the origin of the explosion down to 2 (easily) or 1 (with a little cheeky fiddling :P)

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 01-07-2008 23:57

Nice.

One more way to cut down lines in event handling is to use the || operator to provide a fallback/default value, e.g:

code:
var x = Math.round(Math.random()*540)+50;
if (e.pageX)	
	x = e.pageX;
var y = Math.round(Math.random()*380)+50;
if (e.pageY)
	y = e.pageY;

becomes

code:
var x = (e||{}).pageX||Math.round(Math.random()*540)+50;
var y = (e||{}).pageY||Math.round(Math.random()*380)+50;

Notice the (e||{}) which fixes the JS error of trying to access a property of e when shoot() is called by the setInterval()

Also instead of clearing the explosion manually, you could constantly do a fillRect(0,0,540,480) in rgba(0,0,0,.2) for instance.

Hope that helps,



(Edited by poi on 01-08-2008 00:35)

Arthurio
Paranoid (IV) Inmate

From: cell 3736
Insane since: Jul 2003

posted posted 01-08-2008 02:26

thanks, I'm working on something new tho

Arthurio
Paranoid (IV) Inmate

From: cell 3736
Insane since: Jul 2003

posted posted 01-08-2008 23:06

and here it is

proudly presenting ...

colorful bouncy bubbles with user interaction and sloppy collision detection! all in 19 lines

http://www.kaarellumi.com/asylum/html/dyn4.htm

Arthurio
Paranoid (IV) Inmate

From: cell 3736
Insane since: Jul 2003

posted posted 01-09-2008 15:10

about rules ... is
try {a[i] = b;} catch (e) {}
one line or more?

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 01-09-2008 16:10

I'd say 3.

code:
/* 01 */    try
/*    */    {
/* 02 */        a[i] = b;
/*    */    }
/* 03 */    catch( e )
/*    */    {
/*    */        // ...
/*    */    }

But don't worry, people won't bite your head off if you post a 25 liner. Are you sure you need to catch the exception anyway ? can't you check if b is valid or provide a default value.



Speaking of line count, I'm looking into chained function calls à la jQuery. How do you guys feel about them ?



(Edited by poi on 01-09-2008 16:12)

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 01-10-2008 05:27

Ok, so how many lines do you guys count for this very specific methods currier ?

code:
/* A */    for( chainThat in {methodA:1,methodB:1} )
/*   */    {
/* B */        anObject.prototype[chainThat] = function( func )
/*   */        {
/* C */            return function()
/*   */            {
/* D */                return func.apply( this, arguments )||this;
/*   */            }
/* E */        }( anObject.prototype[chainThat] );
/*   */    }

  • 5 ?

  • 4 since the line E is the just calling the anonymous function declared in B and hence is part of the declaration of anObject.prototype[chainThat] ?

  • less ?



That shouldn't make much difference obviously but I'm curious.



(Edited by poi on 01-10-2008 05:30)

argo navis
Paranoid (IV) Inmate

From: Switzerland
Insane since: Jul 2007

posted posted 01-10-2008 08:22

What's with getting all feely?-)
I'd say 5, because
>> line E is the just calling the anonymous function declared in B

The line of code is "just calling an anonymous function" - just calling, I don't care it's anonymous,
it is a "call" so the line has an action of it's own. I'd therefore count it as valid.

Oh, and jquery seems as nice as widely spread, and surprise! It's not
really compatible with many browsers out there. Go figure..

iron_wallaby
Nervous Wreck (II) Inmate

From:
Insane since: Dec 2007

posted posted 01-10-2008 11:15

I count 4 lines, though I DO consider the technique similar to using a comma to put an extra line of code in.

If you want to be fair, count it 5.

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 01-10-2008 11:24

Fair enough. At worst I could mangle the loop to make it more 4-line-ish.

argo navis: FWIW I'm not using jQuery.

argo navis
Paranoid (IV) Inmate

From: Switzerland
Insane since: Jul 2007

posted posted 01-10-2008 11:26

I am not saying you do : I am just witnessing that many large companies use a js lib that does not care much about backwards compatibility.
So I mark that down as "let's focus on forward compatibility" for myself.

Arthurio
Paranoid (IV) Inmate

From: cell 3736
Insane since: Jul 2003

posted posted 01-11-2008 10:53

Candle flame in 10 lines

link

argo navis
Paranoid (IV) Inmate

From: Switzerland
Insane since: Jul 2007

posted posted 01-11-2008 10:59

Excellent Arthurio, you're getting the hang of it : it's a GAME - so, much like relationships, it's not about winning and losing,
it's about experience and growth - a social activity for a Mad Scientists society ,)

Although I like your second entry, on this laptop, which is reaching the end of it's lifecycle (~5 years), it's sluggish - certainly
because of the alpha blending recommended by p01 : makes for a sweet motion blur, but my machine cannot stand it.

(And of course, remember that a challenge is a great gift in such settings)

Arthurio
Paranoid (IV) Inmate

From: cell 3736
Insane since: Jul 2003

posted posted 01-11-2008 11:36

Thanks but ... awww ... you're so full of yourself

quote:

argo navis said:
you're getting the hang of it : it's a GAME - so, much like relationships, it's not about winning and losing,it's about experience and growth - a social activity for a Mad Scientists society
...
(And of course, remember that a challenge is a great gift in such settings)



It's my love for programming that I'm trying to express and js is something new and exciting to me especially as an art form. This is why I've posted 3 entries. No need to tell me that it's a game. I've long taken part and enjoyed the various forms of semi-competitive entertainment here at asylum.

You're a smart guy but don't try to act as if you were the only one

Please don't take offense. (...ahh ... why does this always sound so hypocritical

argo navis
Paranoid (IV) Inmate

From: Switzerland
Insane since: Jul 2007

posted posted 01-11-2008 11:54

I happen to know my worth, bite me.

AND...
I am the initiator of this contest historically - the guy who brought it up first AND resurrected it - simply : I don't hold it as a duty
or a title, but talks like this (quote from you ten posts above) :

quote:

not very dynamic, nothing special either but this is the best i could come up with right now ...
edit: bah ... disregard this entry ... i'll come up with something better



Sound very much like the middle of puberty.

quote:

Please don't take offense. (...ahh ... why does this always sound so hypocritical



Sound very much like the next stage of puberty when you can't take constructive criticism as constructive, and feel like
the most powerful being on earth and having to prove your worth.

Reality check : you're not, and I don't claim to be myself, but instead of sounding whiney and bitching at me right there and then,
you could take and use the advice - then you'd prove your worth without sounding like a dumb ass.

I recommend do in the future as far as I am concerned - and don't worry, I will refrain from giving you pearls
if all you can do with them is wave your shineys back at me.

(aw, why do comments like this sound so BLUNTLY HONEST).

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 01-11-2008 12:03

Can we all behave like Gentlemen and ladies here ?

Arthurio: Nice colors. How does it perform with more pixels ?

argo navis
Paranoid (IV) Inmate

From: Switzerland
Insane since: Jul 2007

posted posted 01-11-2008 12:08

No prob, poi, to me it's "over" - but it's important to set boundaries early on also in relationships,
I don't like giving positive feedback (can someone point out something negative in my above comment?)
and receiving such an arrogant response publicly, period - I will NOT deal with it on these terms.

If any comment not directed towards javascript code is to be posted, feel free to mail it instead, argo.navis, yahoo email.

Arthurio
Paranoid (IV) Inmate

From: cell 3736
Insane since: Jul 2003

posted posted 01-11-2008 13:27

argo navis: wow what a reaction. Sorry I offended you but I really couldn't see any constructive criticism in the sentences that I quoted. Other than that you said that my 2. entry was sluggish. Yeah, I know. I think we much missed our intended tones of our initial posts as it so often happens on the internet. I hope you can forgive me one day.

poi: It gets progressively worse I tested it with 20x20 and 30x30 and I didn't get very good results but I'll give it a few more tries. The 2 main problems that I can think of are that many of the 'pixels' are wasted and recalculated even though they remain black and the 2. problem is the extensive use of Math.atan and Math.sin for calculating the color values and the shape of the flame.

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 01-11-2008 13:37

Arthurio: you sure it's the calculation itself ? In my experience the bottleneck is usually the rendering engine. If you don't mind dropping IE compatibility, you could generate a BMP image using a data: URI*. I tested a fire effect using the one-zillion-DIV technique versus the BMP data: URI . The later was almost 20x faster.

*: see GIF/PNG generation with JS?



(Edited by poi on 01-11-2008 13:39)

argo navis
Paranoid (IV) Inmate

From: Switzerland
Insane since: Jul 2007

posted posted 01-11-2008 13:42

Do not lend me intentions or distort them - you called me "full of yourself", don't try that again out of a humorous comment which yours was NOT,
and you have not adressed my question directly "by the way".

Reminder, the question was : can you see anything negative in the above comment?
What exactly?

It's not a matter of forgiveness or anger - I have experience in the field, you can benefit from it or keep petting yourself over
small circles that bounce around sluggishly, this depends entirely on HOW you choose to welcome advice.

So, now that you've displayed passive agressivity towards me, and keep twisting my words, care to answer my question and make a point?
Because that is the line between a self proclaimed "smart guy" and a man, fwiw.

(Edited by argo navis on 01-11-2008 13:46)

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 01-11-2008 13:47
quote:
Reminder, the question was : can you see anything negative in the above comment?
What exactly?

Can be bothered to check, but the comment you made right after this quote wasn't exactly positive.

Anyway. Can all put on our happy face ? it's friday, we're here to make cool tiny scripts and have fun, right.



(Edited by poi on 01-11-2008 13:49)

argo navis
Paranoid (IV) Inmate

From: Switzerland
Insane since: Jul 2007

posted posted 01-11-2008 13:50

I AM here for that and you are not adressing my question either.
I refuse being called names, and since the kid did that publicly, I am forced to adress his arrogance publicly.

>> I hope you can forgive me one day.
If you do make a clear apology, OR you demonstrate I started off insutling you, yes.

Arthurio
Paranoid (IV) Inmate

From: cell 3736
Insane since: Jul 2003

posted posted 01-11-2008 13:52

poi: no I'm not sure. It was just a guess. I guess I don't care much about IE compatibility with those kinds of things

Here's a better resolution and cropped version of my candle flame: link

(Edited by Arthurio on 01-11-2008 13:55)

argo navis
Paranoid (IV) Inmate

From: Switzerland
Insane since: Jul 2007

posted posted 01-11-2008 14:02

No real improvement there, just a different decoration : a more realistic flame looks like this, posted a few years ago.

The sine movement in yours shows - it's a bit too simple - the colors are ok though, I second poi on that.

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 01-11-2008 14:04

^ oh, that's the fire I tested against BMP data: URI

argo navis
Paranoid (IV) Inmate

From: Switzerland
Insane since: Jul 2007

posted posted 01-11-2008 14:21

So, to wrap it up Arthurio : there is a third option for you to regain my respect.

Demonstrate in actions you are worthy of entering the top three, rather than sine waving squares ,) Good luck!

Arthurio
Paranoid (IV) Inmate

From: cell 3736
Insane since: Jul 2003

posted posted 01-11-2008 14:22

argo navis: I apologize for improperly apologizing for reacting to a post of yours that was insulting to me. I have hard time putting this into English but I couldn't let you off with a post that in ways (imo falsely) implied my inferior understanding of this particular form of entertainment and of things that in no way concern the thread nor my entries. I've read your post a few more times now and I see now that although your post seemed insulting to me It was obviously not in your heart to mean harm and this is why I'm apologizing for my harsh reaction.

argo navis
Paranoid (IV) Inmate

From: Switzerland
Insane since: Jul 2007

posted posted 01-11-2008 14:28

Peace out : I do sound cocky and arrogant and full of myself (because my smile and my heart do not show up on the web - just the words),
you're not wrong about the fact I can come across as disturbingly pompous (it never is my intent though), but what I really mean is :

"you're GOOD and we all KNOW since we have seen your interest for javascript
many times now with good to great results- I remeber some fractal explorer for example,
and I remember it off the top of my head. This is worthy of me trying to help you GET BETTER as much as I CAN."

This doesn't imply I am better than you at any given point - I may be more experienced but that's it.
I do not feel I am better than any of my human fellows - I feel human beings are amazing.

It's all cleared to me, really, but it still is a good chance for you, now that you found yourself enjoying the contest,
to really shine - you DO have all it takes, this never was a question to me.

So cheers, happiness, and let's all enjoy what comes next.

[1] 2 3 4Next Page »



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu