Closed Thread Icon

Topic awaiting preservation: December 20lines Javascript Contest - Colors - Comments (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=24275" title="Pages that link to Topic awaiting preservation: December 20lines Javascript Contest - Colors - Comments (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: December 20lines Javascript Contest - Colors - Comments <span class="small">(Page 1 of 1)</span>\

 
poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 12-02-2004 14:12

This month's theme is: Colors.

The colors can be animated, static, ugly, pretty, interactive, ... I just want to see some colors on more time before a snow coat covers the Asylum.

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>


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.


Examples of possible entries :

  • plasmas,
  • color scheme generator,
  • Dutch Color Scheme generator,
  • Fireworks,
  • Mondrians,
  • ...



As usual, try to submit your comments here, and your entries in December 20lines Javascript Contest - Colors - Entries
I hope you'll enjoy this topic.

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 12-02-2004 16:18

[edit: grr, double postified. sorry. :X ]

(Edited by Iron Wallaby on 12-02-2004 16:19)

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 12-02-2004 16:18

Oh, great topic! I'd like to get started immediately, but I'm not sure if I'll be able. I DO know that I will have time towards the end of the month, so I can at least jump on it then.

Question: is SVG allowed in 20 liners? Or does nobody really care?

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 12-05-2004 16:20

I don't know about the other inmates but I'd prefer an SVG entry rather than no entry.

Honestly I don't know well SVG, but since it's scripted with pure ecmascript I guess it's fair to submit some SVG entries. In a certain way, the rendering part is an improved version of XHTML+CSS.

So if you really feel like playing with SVG, go for it.

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 12-09-2004 08:48

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 12-09-2004 08:59

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 12-09-2004 16:03

Oh, do the rules disallow multiple declarations in a single line? Whoops. Well then, in that case, let me recode it to be completely legal in the strictest sense of the term, eh?

Allow me to clarify my stance on "cheating." When someone does a line like that, the contest is no longer about making something interesting in 20 lines of code, it is about cramming as much as you can into into any given line of code (which is technically an infinite amount).

However, I agree with your point, that multiple declarations and the use of commas flit around that too... so I guess I'll just have to challenge myself a bit more, eh?

[EDIT: Still 20 lines, no longer with multiple declarations tied together. You wil notice that one line pushes an array; since there is no other way to do that, I consider that array completely fair game. ]

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

(Edited by Iron Wallaby on 12-09-2004 16:16)

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 12-09-2004 16:29

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 12-09-2004 16:43

Nice entry Iron Wallaby!
It looks cool with the inverted depth

I've never done any scripts like that, will see if I can match it, got lots of other projects going on...

On threads, I'think it'll be easier with one thread each month. Will be easier to keep track of new posts/entries that way...

On 'cheating', I use blabla = 15615+(myblabla2 = 16516) when I need the value later on but sometimes it's neccessary to do blabla = 15615+0*(myblabla2 = 16516), or atleast really hard to get around.
Anyway, as long as (myblabla2 = 16516) returns a number I think it's ok.
The question is if 0*isNaN(any expression) is getting away too cheap?
I admit I had to use isNaN() to get my fishy entry to work in FireFox but it worked w/o it in IE though.
Don't know any other way to do store the same value (or a second value that depends on the first one) in two variables using object.setAttribute('attrib',384654)....

Btw, there's also a way to compress most nested loops to one line.

for(i=0;i<=5;function(){for(j=(i++);j<=5;j++){alert((i-1)+" "+j)}}())

As far as I know this can be done with as many loops as you need, as long as you can put all your other code inside the for-statement(s)...
Don't think if it's very optimized since it creates a new function each iteration lol

/TwoD

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 12-09-2004 16:51

I don't think that places the for loops in one line, since each function body is counted (according to the rules, unless I'm mistaken) as a separate line of code.

code:
for(i=0;i<=5;function(){ /*1*/
for(j=(i++);j<=5;j++){ /*2*/
alert((i-1)+" "+j) /*3*/
}
}())



setAttribute is, I would think, be a fair way to set multiple pieces of data in one line, since you're basically constructing a string that happens to have the handy side effect of doing, say, 3 things at once. However, it doesn't seem to work in MSIE, for me anyway.

I don't have problems with anyone else using shortcuts, since this is done for fun. I'd rather see a 30 line entry than none at all, so sense in being pedantic. However, since I use it as a learning experience, I will attempt to cram a nifty effect into 20 strict lines, since I am anal.

InI: I understand how tough it is to be doing so much work, it's usually about 12/24 6/7 study and work for me. I am regaining time as college comes to a close, hence why I can devote time to other things.

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

(Edited by Iron Wallaby on 12-09-2004 16:53)

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 12-10-2004 02:21

Holy crap, shingebis, that is unbelievable. I've seen people do PNG's (their code was so crappy, however, I couldn't make heads or tails of it), but not GIF's, and not so quickly either (or in so little code!!)

I have been thoroughly beaten. *bows before you* I will toy with it later when I have time, maybe IE isn't too far off.

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 12-10-2004 06:39

Alright I haven't been involved but I'd consider lines like such

setInterval("run();collideSprite()"


as more than one line.. Even though it's within the one line, calling two functions within a setInterval ( or setTimeout ) seems like two lines. It's basically like doing something like:

exec("run();run2();run3()....

(but like I said I haven't competed and can't really call )



.:[ Never resist a perfect moment ]:.

TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 12-10-2004 08:22

Just noticed I forgot a small part in that example..

In the function body, the for-statement counts as one line, and the alert is another line. But I could have combined them to

code:
for(j=(i++);j<=5;alert((i-1)+" "+(j++)))


,right?

That makes

code:
for(i=0;i<=5;function(){ /*1*/
for(j=(i++);j<=5;alert((i-1)+" "+(j++))){ /*2*/
}())



The function declaration doesn't count as one line, so it doesn't matter if I combine it with the inner loop body, does it?

code:
for(i=0;i<=5; /*1*/
function(){for(j=(i++);j<=5;alert((i-1)+" "+(j++))){}()/*2*/
)



And if I can combine the alert line and the inner for-loop above, I should be able to do the same here.

code:
for(i=0;i<=5;function(){for(j=(i++);j<=5;alert((i-1)+" "+(j++))){}())/*1*/
{}



Anyway, I'm just wondering what you think about this. I'm not planing to use it since it gets very confusing when you are writing real scripts....

/TwoD

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 12-10-2004 08:34

I think the trouble is this part here:

code:
for(j=(i++);j<=5;alert((i-1)+" "+(j++)))


I would say that is still 2 lines (though, it could easily be argued the other way), since you're technically not reducing anything. However, it gets complicated if you do, say...

code:
for(i = 0; i++ < 20; alert(j)) j = i * i + 47;


Would this be considered two lines, or three? You could argue for both.

My reasoning is, that if you allow a little leeway, it opens the door to anything (especially in JS, where functions are first-class). So I prefer to take the strictest approach possible.

However, it seems to me that we're bickering over a worthless point. Less talk, more code, as they say!

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 12-10-2004 10:35

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 12-10-2004 13:02

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 12-13-2004 09:17

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 12-13-2004 11:35

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

liorean
Bipolar (III) Inmate

From: Umeå, Sweden
Insane since: Sep 2004

posted posted 12-22-2004 01:33

Well, you could do things like this:

code:
var
str="expression1§expression2§....§expression93";
eval(str.replace(/§/g,';'));




Reallly, it's hard to be fair in line counting, because among other things, whitespace is freely distributable. You could always go for the same things as the semicolon insertion rules (they are pretty fair when it comes to statements), but then list expressions would flourish.

Consider something like this potential one-liner:

code:
fn1(
b?
(b=!b,fn2(s)):
(b=!b,fn3(s)),
c,
b2||fn4(s));


There's a lot of things going on in there, and I would have a hard time telling you how many of your "lines" that goes in there. The easiest way to count something like that is to factor out all inner expressions, in which case we would find something like this:

code:
var
tmp=b, // #1
tmp2,
tmp3;
b=!b; // #2

// Should each result of a conditional expression be considered a line?
// That way it would be consistent with the if..else statement.

tmp2=tmp?
fn2(s): // #3?
fn3(s); // #3 or #4?
tmp3=b2||fn4(s); //#4 or #5?
fn(tmp2,c,tmp3); //#5 or #6?

However, that same factoring out would also make many cases of simple math expressions several lines.

--
var Liorean = {
prototype: ProgrammingTheoryGuru.prototype,
abode: "http://web-graphics.com/",
profile: "http://codingforums.com/member.php?u=5798"};

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 12-22-2004 13:23

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 12-22-2004 15:48

If InI's entry isn't considered to be 20 lines, then my winning entry (The fishtank AI) sure isn't either....
Allthough since there's usually not more than a few entries, and the contest doesn't have any real prizes,
I believe it's up to each contestant to do most of the judging considering linecount.
However I agree with InI that the entries should be more closely examined if they are good enough to be the winner.

/TwoD

Hugh
Paranoid (IV) Inmate

From: Dublin, Ireland
Insane since: Jul 2000

posted posted 12-25-2004 22:26

Grumble: I used Mozilla, ran perfect. tho I do have a nice machine as of late.

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-26-2004 11:42

aha. thanks.
good to know!

« BackwardsOnwards »

Show Forum Drop Down Menu