/    Sign up×
Community /Pin to ProfileBookmark

unorthodox use thingie question

hi!

i have quite some experience at programming (c, asm, various basics), but i’m new to javascript. i’m currently trying to create an ultra-low resolution (80×50 in this version) framebuffer of sorts for animation that i would like to run at ~4 fps. all in all i have two problems:

  • 1.

    below is the code for drawing one frame. when drawing many frames, how do i make it draw them at the same spot (ie. overwrite the previous frame and not draw below it)?

  • 2.

    how would i speed it up?

  • thankful for any help.

    ———-8<———-

    function rnd(n)
    {
    ____return Math.round(Math.random() * n);
    }

    var piccel = Array(4000);
    var col = Array(“#000000”, “#009900”);

    for(i=0; i<4000; i++) piccel[i] = rnd(1);

    s = “<table width=640px height=400px cellpadding=0 cellspacing=0 border=0>”;

    for(y=0, i=0; y<50; y++){
    ____s += “<tr>”;
    _
    __
    _for(x=0; x<80; x++, i++){
    _
    _______s += “<td bgcolor=”” + col[piccel[i]] + “”></td>”
    _
    __
    _}
    _
    ___s += “</tr>”
    }

    s += “</table>”;

    document.write(s);

    to post a comment
    JavaScript

    1 Comments(s)

    Copy linkTweet thisAlerts:
    @David_HarrisonJan 27.2004 — First off, what's with all of the underscores? If you want to layout your code asis then use some [ code ][ /code ] tags (but without the spaces).

    Rather then write table cells onto the page, what I've done is waited intil the page has loaded to run the script. Then the script changes the background colour of and element in that page. I have set the size of the element to 20px by 20px rather than 8px by 8px that you had, this just makes it a bit easier to see.

    Most of the code I have used is pretty simple, the function runs itself every 250 milliseconds providing that i<4000.

    [upl-file uuid=13038ab6-a99f-4a95-a81f-798cd8179c9c size=727B]box of colour.txt[/upl-file]
    ×

    Success!

    Help @boy_dead spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.19,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...