User:Joak/canvas1: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<canvas id="c1" showsrc>  
<canvas id="c1" showsrc>  
function unit () {
something
  // a single housing unit
  ctx.strokeRect(0, 0, 10, 10);
}
   
   
function street () {
function draw() {
   // a linear row of houses
   c = document.getElementById("c1");
  ctx.save();
   p = c.getContext('2d');
  var numhouses = Math.floor(Math.random()*15);
   drawer();
   for (c=0; c<numhouses; c++) {
    unit();
    ctx.translate(10, 0);
   }
  ctx.restore();
}
}
 
function city (l) {
function drawer() {
  // rows of streets
    r = 0;
  for (x=0; x<12; x++) {
    r = 3;
     street();
    x = 250;
    ctx.translate(0, 20);
    y = 250;
  }
    var positionx = x / 2;
    var positiony= y / 2;
 
    if( r < 3){
if(r == 3){
upordown = -0.02;
}
if(r == 0){
upordown = +0.02;
}
r=r+upordown;
}
r = Math.max(r, 0);
r = Math.min(r, 3);
r2 = map_range(r,0,3,3,0);
movement = 400*Math.sin(r);
movement2 =400*Math.sin(r2);
     var number1 = p.createRadialGradient(positionx,positiony,movement2,positionx,positiony,movement);
number1.addColorStop(0, '#000000');
  number1.addColorStop(1, '#FFFFFF');
 
  p.fillStyle = number1;
  p.clearRect(0,0,c.width,c.height);
  p.fillRect(0,0,x,y);
    setTimeout(drawer,10)
}
}
 
function draw() {
function map_range(value, low1, high1, low2, high2) {
  c = document.getElementById("c1");
    return low2 + (high2 - low2) * (value - low1) / (high1 - low1);
  ctx = c.getContext('2d');
  city();
}
}


</canvas>
</canvas>

Latest revision as of 12:22, 1 October 2012

<canvas id="c1" showsrc> something

function draw() {

 c = document.getElementById("c1");
 p = c.getContext('2d');
 drawer();

}

function drawer() {

   r = 0;
   r = 3;
   x = 250;
   y = 250;
   var positionx = x / 2;
   var positiony= y / 2;
   if( r < 3){

if(r == 3){ upordown = -0.02; } if(r == 0){ upordown = +0.02; } r=r+upordown; } r = Math.max(r, 0); r = Math.min(r, 3); r2 = map_range(r,0,3,3,0); movement = 400*Math.sin(r); movement2 =400*Math.sin(r2);

   var number1 = p.createRadialGradient(positionx,positiony,movement2,positionx,positiony,movement);
	number1.addColorStop(0, '#000000');
 	number1.addColorStop(1, '#FFFFFF');
 	
 	p.fillStyle = number1;
 	p.clearRect(0,0,c.width,c.height);
 	p.fillRect(0,0,x,y);
   setTimeout(drawer,10)

}

function map_range(value, low1, high1, low2, high2) {

   return low2 + (high2 - low2) * (value - low1) / (high1 - low1);

}

</canvas>