oisrex

| ارسال هاAnswers : | 747 |
| عضویتRegistration date : | 4 /8 /1393 |
| حمایت کردهThanks : | 231 |
| حمایت شدهThanked : | 886 |
|
نقاشی با canvas
سلام شما با این کد میتونید یه نقاشی شانسی بکشید این با کلیک کار میکنه: کد:
<script type="text/javascript" >onclick=function(){ var canvas=document.getElementById('C'); r=Math.floor(Math.random() *250); g=Math.floor(Math.random() *250); b=Math.floor(Math.random() *250); m=Math.floor(30+ Math.random() *300); n=Math.floor(30+ Math.random() *300); if(canvas.getContext){ var ctx=canvas.getContext('2d'); ctx.save(); ctx.shadowOffsetX=5; ctx.shadowOffsetY=5; ctx.shadowBlur=10; ctx.shadowColor='rgb('+r+','+b+','+g+')'; ctx.fillStyle='rgb('+r+','+b+','+g+')'; ctx.fillRect(n,200,200,100); ctx.restore(); ctx.beginPath(); ctx.arc(m,150,m,m,Math.PI*2,false); ctx.lineWidth=2; ctx.strokeStyle='rgb('+r+','+b+','+g+')'; ctx.stroke(); ctx.beginPath(); ctx.moveTo(m,m); ctx.lineTo(n,10); ctx.lineTo(100,10); ctx.lineTo(n,200); ctx.closePath(); ctx.lineWidth=2; ctx.strokeStyle='rgb('+r+','+b+','+g+')'; ctx.stroke(); ctx.font="Bold 17px Arial"; ctx.fillStyle="#008600"; ctx.fillText("منبع: moisrex.rozblog.com",10,315); } } </script> <canvas id="C" width="700" height="500" > Your web browser does not support canvas! </canvas> این پس از هر بار لود صفحه... کد:
<script type="text/javascript" >onload=function(){ var canvas=document.getElementById('C'); r=Math.floor(Math.random() *250); g=Math.floor(Math.random() *250); b=Math.floor(Math.random() *250); m=Math.floor(30+ Math.random() *300); n=Math.floor(30+ Math.random() *300); if(canvas.getContext){ var ctx=canvas.getContext('2d'); ctx.save(); ctx.shadowOffsetX=5; ctx.shadowOffsetY=5; ctx.shadowBlur=10; ctx.shadowColor='rgb('+r+','+b+','+g+')'; ctx.fillStyle='rgb('+r+','+b+','+g+')'; ctx.fillRect(n,200,200,100); ctx.restore(); ctx.beginPath(); ctx.arc(m,150,m,m,Math.PI*2,false); ctx.lineWidth=2; ctx.strokeStyle='rgb('+r+','+b+','+g+')'; ctx.stroke(); ctx.beginPath(); ctx.moveTo(m,m); ctx.lineTo(n,10); ctx.lineTo(100,10); ctx.lineTo(n,200); ctx.closePath(); ctx.lineWidth=2; ctx.strokeStyle='rgb('+r+','+b+','+g+')'; ctx.stroke(); ctx.font="Bold 17px Arial"; ctx.fillStyle="#008600"; ctx.fillText("منبع: moisrex.rozblog.com",10,315); } } </script> <canvas id="C" width="700" height="500" > Your web browser does not support canvas! </canvas> اینم با فشردن کلید های صفحه کار میکنه: کد:
<script type="text/javascript" >onkeypress=function(){ var canvas=document.getElementById('C'); r=Math.floor(Math.random() *250); g=Math.floor(Math.random() *250); b=Math.floor(Math.random() *250); m=Math.floor(30+ Math.random() *300); n=Math.floor(30+ Math.random() *300); if(canvas.getContext){ var ctx=canvas.getContext('2d'); ctx.save(); ctx.shadowOffsetX=5; ctx.shadowOffsetY=5; ctx.shadowBlur=10; ctx.shadowColor='rgb('+r+','+b+','+g+')'; ctx.fillStyle='rgb('+r+','+b+','+g+')'; ctx.fillRect(n,200,200,100); ctx.restore(); ctx.beginPath(); ctx.arc(m,150,m,m,Math.PI*2,false); ctx.lineWidth=2; ctx.strokeStyle='rgb('+r+','+b+','+g+')'; ctx.stroke(); ctx.beginPath(); ctx.moveTo(m,m); ctx.lineTo(n,10); ctx.lineTo(100,10); ctx.lineTo(n,200); ctx.closePath(); ctx.lineWidth=2; ctx.strokeStyle='rgb('+r+','+b+','+g+')'; ctx.stroke(); ctx.font="Bold 17px Arial"; ctx.fillStyle="#008600"; ctx.fillText("منبع: moisrex.rozblog.com",10,315); } } </script> <canvas id="C" width="700" height="500" > Your web browser does not support canvas! </canvas> اینم با دابل کلیک کار میکنه: کد:
<script type="text/javascript" >ondblclick=function(){ var canvas=document.getElementById('C'); r=Math.floor(Math.random() *250); g=Math.floor(Math.random() *250); b=Math.floor(Math.random() *250); m=Math.floor(30+ Math.random() *300); n=Math.floor(30+ Math.random() *300); if(canvas.getContext){ var ctx=canvas.getContext('2d'); ctx.save(); ctx.shadowOffsetX=5; ctx.shadowOffsetY=5; ctx.shadowBlur=10; ctx.shadowColor='rgb('+r+','+b+','+g+')'; ctx.fillStyle='rgb('+r+','+b+','+g+')'; ctx.fillRect(n,200,200,100); ctx.restore(); ctx.beginPath(); ctx.arc(m,150,m,m,Math.PI*2,false); ctx.lineWidth=2; ctx.strokeStyle='rgb('+r+','+b+','+g+')'; ctx.stroke(); ctx.beginPath(); ctx.moveTo(m,m); ctx.lineTo(n,10); ctx.lineTo(100,10); ctx.lineTo(n,200); ctx.closePath(); ctx.lineWidth=2; ctx.strokeStyle='rgb('+r+','+b+','+g+')'; ctx.stroke(); ctx.font="Bold 17px Arial"; ctx.fillStyle="#008600"; ctx.fillText("منبع: moisrex.rozblog.com",10,315); } } </script> <canvas id="C" width="700" height="500" > Your web browser does not support canvas! </canvas> اینم پس از هر بار کلیک و برداشتن دکمه کلیک کار میکنه: کد:
<script type="text/javascript" >onmouseup=function(){ var canvas=document.getElementById('C'); r=Math.floor(Math.random() *250); g=Math.floor(Math.random() *250); b=Math.floor(Math.random() *250); m=Math.floor(30+ Math.random() *300); n=Math.floor(30+ Math.random() *300); if(canvas.getContext){ var ctx=canvas.getContext('2d'); ctx.save(); ctx.shadowOffsetX=5; ctx.shadowOffsetY=5; ctx.shadowBlur=10; ctx.shadowColor='rgb('+r+','+b+','+g+')'; ctx.fillStyle='rgb('+r+','+b+','+g+')'; ctx.fillRect(n,200,200,100); ctx.restore(); ctx.beginPath(); ctx.arc(m,150,m,m,Math.PI*2,false); ctx.lineWidth=2; ctx.strokeStyle='rgb('+r+','+b+','+g+')'; ctx.stroke(); ctx.beginPath(); ctx.moveTo(m,m); ctx.lineTo(n,10); ctx.lineTo(100,10); ctx.lineTo(n,200); ctx.closePath(); ctx.lineWidth=2; ctx.strokeStyle='rgb('+r+','+b+','+g+')'; ctx.stroke(); ctx.font="Bold 17px Arial"; ctx.fillStyle="#008600"; ctx.fillText("منبع: moisrex.rozblog.com",10,315); } } </script> <canvas id="C" width="700" height="500" > Your web browser does not support canvas! </canvas> اینم بعد از هر بار راست کلیک کار میکنه: کد:
<script type="text/javascript" >oncontextmenu=function(){ var canvas=document.getElementById('C'); r=Math.floor(Math.random() *250); g=Math.floor(Math.random() *250); b=Math.floor(Math.random() *250); m=Math.floor(30+ Math.random() *300); n=Math.floor(30+ Math.random() *300); if(canvas.getContext){ var ctx=canvas.getContext('2d'); ctx.save(); ctx.shadowOffsetX=5; ctx.shadowOffsetY=5; ctx.shadowBlur=10; ctx.shadowColor='rgb('+r+','+b+','+g+')'; ctx.fillStyle='rgb('+r+','+b+','+g+')'; ctx.fillRect(n,200,200,100); ctx.restore(); ctx.beginPath(); ctx.arc(m,150,m,m,Math.PI*2,false); ctx.lineWidth=2; ctx.strokeStyle='rgb('+r+','+b+','+g+')'; ctx.stroke(); ctx.beginPath(); ctx.moveTo(m,m); ctx.lineTo(n,10); ctx.lineTo(100,10); ctx.lineTo(n,200); ctx.closePath(); ctx.lineWidth=2; ctx.strokeStyle='rgb('+r+','+b+','+g+')'; ctx.stroke(); ctx.font="Bold 17px Arial"; ctx.fillStyle="#008600"; ctx.fillText("منبع: moisrex.rozblog.com",10,315); } } </script> <canvas id="C" width="700" height="500" > Your web browser does not support canvas! </canvas> اینم با حرکت ماوس روی canvas نقاشی میکشه: (باحال ترینشون اینه) کد:
<script type="text/javascript" >onmousemove=function(){ var canvas=document.getElementById('C'); r=Math.floor(Math.random() *250); g=Math.floor(Math.random() *250); b=Math.floor(Math.random() *250); m=Math.floor(30+ Math.random() *300); n=Math.floor(30+ Math.random() *300); if(canvas.getContext){ var ctx=canvas.getContext('2d'); ctx.save(); ctx.shadowOffsetX=5; ctx.shadowOffsetY=5; ctx.shadowBlur=10; ctx.shadowColor='rgb('+r+','+b+','+g+')'; ctx.fillStyle='rgb('+r+','+b+','+g+')'; ctx.fillRect(n,200,200,100); ctx.restore(); ctx.beginPath(); ctx.arc(m,150,m,m,Math.PI*2,false); ctx.lineWidth=2; ctx.strokeStyle='rgb('+r+','+b+','+g+')'; ctx.stroke(); ctx.beginPath(); ctx.moveTo(m,m); ctx.lineTo(n,10); ctx.lineTo(100,10); ctx.lineTo(n,200); ctx.closePath(); ctx.lineWidth=2; ctx.strokeStyle='rgb('+r+','+b+','+g+')'; ctx.stroke(); ctx.font="Bold 17px Arial"; ctx.fillStyle="#008600"; ctx.fillText("منبع: moisrex.rozblog.com",10,315); } } </script> <canvas id="C" width="700" height="500" > Your web browser does not support canvas! </canvas> با تشکر مردم از بس کد گذاشتم :دی
|