渲染对象实例中的颜色不正确,我在整个世界中绝对不知道为什么



我得到的只是与RGB(0,255,255(的一个小平方,我希望'r'与日志成比例(betterlog是log函数(base,answers(= exponent

一切

var ln = function(g){
    var n=g;
    n=abs(n);
    if(n>1){
        n=1/n;
    }
    var x=n-1;
    var output = x;
    var i;
    for(i = 2; i < 99; i++){
        if (i%2 === 0){
            output -= pow(x,i)/i;
        }
        if (i%2 === 1){
            output += pow(x,i)/i;
        }
    }
    return output;
};
var betterLog = function(a,b){
    var output = ln(b)/ln(a);
    return output;
};

var v=475;
var block = function(){
  this.render = function(){
    var stupidColor=(betterLog(2,v)*20);
    fill(stupidColor, 255, 255);
    rect(20,20,20,20);
  };
};
var newCrap = new block();

var draw = function() {
    newCrap.render(v);
};

如果它正确或不呈现JS的呈渲染,则仅是RGB(0,255,255(IDK,并且它只是不需要工作,而无需任何错误本身

您只需要将Math对象添加到您的功能

var ln = function(g){
    var n=g;
    n=Math.abs(n);
    if(n>1){
        n=1/n;
    }
    var x=n-1;
    var output = x;
    var i;
    for(i = 2; i < 99; i++){
        if (i%2 === 0){
            output -= Math.pow(x,i)/i;
        }
        if (i%2 === 1){
            output += Math.pow(x,i)/i;
        }
    }
    return output;
};
var betterLog = function(a,b){
    var output = ln(b)/ln(a);
    return output;
};
var canvas = document.querySelector('canvas');
var ctx = canvas.getContext('2d');
var fill = function(r,g,b,a){
  ctx.fillStyle = 'rgba('+r+','+g+','+b+','+a||1+')';
};
var rect = function(x,y,w,h){
  ctx.fillRect(x,y,w,h);
};
var v=475;
var block = function(){
  this.render = function(v){
    var stupidColor=(betterLog(2,v)*20);
    fill(stupidColor, 255, 255);
    console.log({stupidColor});
    rect(20,20,20,20);
  };
};
var newCrap = new block();
var draw = function() {
    newCrap.render(v);
};
draw();
<canvas></canvas>

相关内容

  • 没有找到相关文章

最新更新