Web Analytics Made Easy -
StatCounter Help sorting function out - CodingForum

Announcement

Collapse
No announcement yet.

Help sorting function out

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help sorting function out

    OK I was digging around through old stuff that I saved that I found confusing and wanted to understand at a later date. I found P01's script and I wanted to pick it apart to better understand it.

    http://www.p01.org/releases/256b_mars_canvas/
    p01's code
    Code:
    <body onload=setInterval("S=Math.sin;with(R.getContext('2d'))for(fillRect(0,0,300,150,drawImage(R,9,2,282,148,0,3,300,150),fillStyle='rgba(99,0,42,.01)'),a+=x=88;x--;fillRect(x*4,75+S(a+x/27+S(x/9)*S(a*2-x/15))*20,4,3))fillStyle='#c60'",a=9)><canvas id=R>
    Here's my pick apart.
    Code:
    <script>
    S=Math.sin;
    var  a=9;
    var x=36;
    var xx=x
    function run(){
    
    xx-=1
    a+=x;
    
     
     
     R=document.getElementById("R");
     
     ctx=R.getContext('2d')
    ctx.fillStyle='rgba(99,0,42,.01)'
    ctx.fillRect(0,0,300,150)
    ctx.fillStyle='#cc6600'
    ctx.fillRect(x*4,75+S(a+xx/27+S(xx/9)*S(a*2-xx/15))*20,4,3)
    
     
    
    
    
    ctx.drawImage(R,9,2,282,148,0,3,300,150)
    
    
    
    
    //
    
    
    
    }
    ;setInterval("run()",9)
    </script>
    <canvas id="R"></canvas>
    I had to set the vars all wrong to get some output.
    What is that script doing ? LOL I can't follow it. Can you?

  • #2
    I'm getting close! I like this little script.check it out. Clcik on canvas to begin. dblclick to stop it and click more times to speed it up. Very cool!

    Code:
    <html><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
    <head>
    
    <style>
    #R {
    background-color: black; 
    border-color: #757575;
    border-style: solid;
    border-width: thin;
    }
    
    </style>
    
    <script>
    S=Math.sin;
    var  a=9;
    var x=88;
    var running=true
    function runit(){if (running==true){a-=x;run();}else{running=false;runit()}}
     
    function run(){
     R=document.getElementById("R");
    ctx=R.getContext('2d')
    ctx.fillStyle='rgba(99,0,42,.01)'
    ctx.fillRect(0,0,300,150)
    ctx.fillStyle='#cc6600'
    for(x=0;x<88;x++){a-=x;a*=-1;
    ctx.fillRect(x*4,75+S(a+x/27+S(x/9)*S(a*2-x/15))*20,4,3)
    }
    ctx.drawImage(R,9,2,282,148,0,3,300,150)
    if (running==true)setTimeout("runit()",9)
    }
    function stopit(){running=false;runit()}
    function startit(){running=true;runit()}
    
    </script>
    </head>
    <body><canvas id="R" onclick="startit()" ondblclick="stopit()" ></canvas></body></html>

    Comment


    • #3
      Pretty nice. Too bad it does nothing in MSIE; maybe MS will someday catch up.

      And whether it speeds up much depends on your processor speed. On my 4-year-old Athlon2600, it only speeds up once and then maybe a tiny bit more on next click, but no more after that.
      Be yourself. No one else is as qualified.

      Comment

      Working...
      X