Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with class assignment

    Hello
    We have the assignment of taking this code and making some modifications to it. I don't know nearly as much as the rest of the class does about scripting so I was wondering if anyone had any suggestions of what I can do and how to go about doing it that would be great!

    The script basically just makes some heart graphics float around the screen
    Heres the script:

    <SCRIPT LANGUAGE="JavaScript1.2">

    var no = 12; // number of hearts
    var speed = 10; // smaller number moves the hearts faster
    var heart = "http://javascript.internet.com/img/heart/heart.gif";
    var flag;

    var dx, xp, yp; // coordinate and position variables
    var am, stx, sty; // amplitude and step variables
    var i, doc_width = 800, doc_height = 600;

    dx = new Array();
    xp = new Array();
    yp = new Array();
    amx = new Array();
    amy = new Array();
    stx = new Array();
    sty = new Array();
    flag = new Array();
    for (i = 0; i < no; ++ i) {
    dx[i] = 0; // set coordinate variables
    xp[i] = Math.random()*(doc_width-30)+10; // set position variables
    yp[i] = Math.random()*doc_height;
    amy[i] = 12+ Math.random()*20; // set amplitude variables
    amx[i] = 10+ Math.random()*40;
    stx[i] = 0.02 + Math.random()/10; // set step variables
    sty[i] = 0.7 + Math.random(); // set step variables
    flag[i] = (Math.random()>0.5)?1:0;

    document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
    document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
    document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\"");
    document.write(heart+ "\" border=\"0\"></div>");
    }

    function snow() {
    for (i = 0; i < no; ++ i) {
    if (yp[i] > doc_height-50) {
    xp[i] = 10+ Math.random()*(doc_width-amx[i]-30);
    yp[i] = 0;
    stx[i] = 0.02 + Math.random()/10;
    sty[i] = 0.7 + Math.random();
    flag[i]=(Math.random()<0.5)?1:0;
    doc_width = document.body.clientWidth;
    doc_height = document.body.clientHeight;
    }

    if (flag[i])
    dx[i] += stx[i];
    else
    dx[i] -= stx[i];

    if (Math.abs(dx[i]) > Math.PI) {
    yp[i]+=Math.abs(amy[i]*dx[i]);
    xp[i]+=amx[i]*dx[i];
    dx[i]=0;
    flag[i]=!flag[i];
    }

    document.getElementById(["dot"+i]).style.top = yp[i] + amy[i]*(Math.abs(Math.sin(dx[i])+dx[i]));
    document.getElementById(["dot"+i]).style.left = xp[i] + amx[i]*dx[i];
    }
    setTimeout("snow()", speed);
    }

    snow();
    // End -->
    </script>

  • #2
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have an idea! It only works in FF and Opera the moment and there are a few bugs to be sure and the coding might need some, shall we say, optimization. :) But I'll leave it as an exercise to fix those minor issues.

    www.exfer.net/test/hearts.html

    david_kw


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •