zoukankan      html  css  js  c++  java
  • CANVAS实现调色板 之 我的第一个随笔

    主题代码

     1 <canvas id="color"></canvas>
     2 
     3 
     4 <script>
     5 var color=document.getElementById("color");
     6 var context=color.getContext("2d");
     7 color.height=window.innerHeight;
     8 color.width=window.innerWidth;
     9 
    10 change=function(r0,g0,b0,r1,g1,b1,start_x,end_x){
    11 var r=r0,g=g0,b=b0;
    12 var cut;//颜色差值
    13 if(r0!=r1){
    14 cut=r1-r0;
    15 }
    16 if(g0!=g1){
    17 cut=g1-g0;
    18 }
    19 if(b0!=b1){
    20 cut=b1-b0;
    21 }
    22 
    23 //context.fillStyle="rgb("+r0+","+g0+","+b0+")";
    24 //context.fillRect(start_x,300,10,100);
    25 
    26 var inc=cut/(end_x-start_x);//step
    27 //console.log(inc);
    28 for (var i = 0; i < end_x-start_x; i++){
    29 if(r0!=r1){
    30 r=r+inc;
    31 }
    32 if(g0!=g1){
    33 g=g+inc;
    34 }
    35 if(b0!=b1){
    36 b=b+inc;
    37 }
    38 
    39 /*效果1*/
    40 // context.fillStyle="rgb("+Math.floor(r)+","+Math.floor(g)+","+Math.floor(b)+")"; 
    41 // context.fillRect(start_x+i,0,1,100);
    42 
    43 /*效果2*/
    44 for (var j = 0; j < 100; j++){
    45 // context.fillStyle="rgba("+Math.floor(r)+","+Math.floor(g)+","+Math.floor(b)+","+j/100*Math.random()+")";
    46 context.fillStyle="rgba("+Math.floor(r)+","+Math.floor(g)+","+Math.floor(b)+","+j/800+")"; 
    47 //console.log(j);
    48 context.fillRect(start_x+i,j*color.height/100,1,(j+1)*color.height/100);
    49 };
    50 
    51 //console.log(start_x+i,start_x+i+1);
    52 };
    53 //context.fillRect(end_x,200,10,100);
    54 // console.log(r,g,b);
    55 }
    56 var w=Math.ceil(color.width/6);
    57 
    58 change(206,11,11,206,11,206,0,w);
    59 change(206,11,206,11,11,206,w,2*w);
    60 change(11,11,206,11,206,206,2*w,3*w);
    61 change(11,206,206,11,206,11,3*w,4*w);
    62 change(11,206,11,206,206,11,4*w,5*w);
    63 change(206,206,11,206,11,11,5*w,6*w);
    64 
    65 
    66 </script>

    实现效果一

     

    实现效果二

  • 相关阅读:
    Visual C#创建和使用ActiveX组件
    ASP.NET2.0 缓存(Cache)技术介绍
    轻松配置Win 2003自带Mail服务器
    如何打印IFRAME中的内容
    FAT32转NTFS、NTFS无损转FAT32
    使用设计模式构建通用数据库访问类
    笑到肚子痛
    夫妻的简单生活
    哈工大学子的一首强诗&哈工大才女的绝顶回诗
    相爱时要做的20件事
  • 原文地址:https://www.cnblogs.com/mjy2wxy/p/10770654.html
Copyright © 2011-2022 走看看