hue属性在paper.js中未定义

时间:2018-03-18 00:22:10

标签: javascript css if-statement animation paperjs

我需要删除newCircle.fillColor =" red&#34 ;;为了得到红色以外的颜色,但当我删除它时,它表示色调的属性是未定义的。

var circles = [];

function onKeyDown(event) {

var maxPoint = new Point(view.size.width, view.size.height);
var randomPoint = Point.random();
var point = maxPoint * randomPoint;
var newCircle = new Path.Circle(point,500)

if(event.key === "a"){
   bubbles.play();
   newCircle.fillColor = "#2c3e50";
   }

  else if(event.key === "b"){
  newCircle.fillColor = "#2c3e50";
  clay.play();
   }

  else if(event.key === "c"){
  newCircle.fillColor = "#00ff0f";
  confetti.play();
  }
  newCircle.fillColor = "red";
  circles.push(newCircle);
  }

 function onFrame(event){
 for(var i = 0; i < circles.length; i++){
  circles[i].fillColor.hue += 1;
  circles[i].scale(.9);
 }
 }

1 个答案:

答案 0 :(得分:0)

在if语句之前设置fillColor(如下面的代码片段)或者使用else语句。

var circles = [];

function onKeyDown(event) {
  var maxPoint = new Point(view.size.width, view.size.height);
  var randomPoint = Point.random();
  var point = maxPoint * randomPoint;
  var newCircle = new Path.Circle(point,500)

  newCircle.fillColor = "red";

  if(event.key === "a"){
     bubbles.play();
     newCircle.fillColor = "#2c3e50";
  }
  else if(event.key === "b"){
    newCircle.fillColor = "#2c3e50";
    clay.play();
  }
  else if(event.key === "c"){
    newCircle.fillColor = "#00ff0f";
    confetti.play();
  }

  circles.push(newCircle);
}

function onFrame(event){
  for(var i = 0; i < circles.length; i++){
    circles[i].fillColor.hue += 1;
    circles[i].scale(.9);
  }
}

我还建议使用switch语句并将if else部分移动到另一个函数。