我有这个代码,其中有一个粒子对象和一个数组来保存它的所有实例。然后,我正在尝试创建一个函数来调用每个实例' draw()和update()函数。:
String Decrypt(String text, String key) throws Exception {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
byte[] keyBytes = Base64.decode(key.getBytes(), Base64.DEFAULT);
SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES");
byte[] b = new byte[keySpec.getEncoded().length];
System.arraycopy(keySpec.getEncoded(), 0, b, 0, b.length);
IvParameterSpec ivSpec = new IvParameterSpec(b);
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
byte[] results = cipher.doFinal(Base64.encode(text.getBytes("UTF-8"), Base64.DEFAULT));
String decoded = new String(cipher.doFinal(results), "UTF-8");
return decoded;
}
这是我的错误消息:var particles;
function setup() {
createCanvas(window.innerWidth, window.innerHeight);
particles = [];
for (var i = 0; i < 5; i++) {
particles.push(1);
}
};
function particle() {
this.x = random(0, width);
this.y = random(0, height);
};
particle.prototype.draw = function() {
noStroke();
fill(255, 0, 0);
rect(this.x, this.y, 20, 20);
};
particle.prototype.update = function() {
this.x+=random(-0.1, 0.1);
this.y+=random(-0.1, 0.1);
};
Array.prototype.run = function() {
for (var i = 0; i < this.length; i++) {
this[i].update();
this[i].draw();
}
};
function draw() {
background(255);
particles.run();
};
。如果我记录这个功能,那就是&#34;未定义&#34;。这是否与我将其声明为原型这一事实有关?我也知道修改Array对象通常是不好的做法,但到目前为止我还没有其他方法可以创建一个可以直接在数组上使用的函数。我没有使用除p5库以外的库或内容。什么是最有效/最干净的解决方案?
答案 0 :(得分:1)
我假设你真的希望粒子成为粒子的数组
注1:将<div id="modal" class="row">
<div class="col-md-12">
<p class="lead">
<span style="color:red">{{ $deleted->foo }}</span>
with quantity {{ $item['quantity'] }} has been removed, please select a replacement.
</p>
<div>
<select class="selectpicker" name="foo" id="foo">
@foreach($replacements as $replacement):
<option value="{{ $replacement->id }}">{{ $replacement->FOO}}</option>
@endforeach
</select>
{{ csrf_field() }}
<input type="hidden" name="qty" value="{{$item['quantity'] }}">
<input type="hidden" name="fooBar" value="{{ $fooBar }}">
</div>
<br>
<div class="input-group">
<span class="input-group-addon">Description:</span>
<input id="description" type="text" class="form-control" name="description" value="" />
</div>
<br><br>
</div>
</div>
添加到run
数组仅
注意2:将particles
更改为particle
- 仅出于“约定”原因
Particle
答案 1 :(得分:0)
您的setup()
函数正在创建一个数字数组,而不是particle
的数组。它应该是:
function setup() {
createCanvas(window.innerWidth, window.innerHeight);
particles = [];
for (var i = 0; i < 5; i++) {
particles.push(new particle);
}
};