xxxxxxxxxx
//複製最後一行即可
let inkGraphics,fishGraphics
let shapes = [{"x":-38,"y":-1},{"x":-63,"y":-37},{"x":-67,"y":-78},{"x":-25,"y":-106},{"x":29,"y":-108},{"x":53,"y":-82},{"x":50,"y":-38},{"x":35,"y":-1},{"x":37,"y":10},{"x":99,"y":50},{"x":94,"y":67},{"x":73,"y":67},{"x":27,"y":13},{"x":31,"y":32},{"x":58,"y":70},{"x":54,"y":86},{"x":34,"y":83},{"x":16,"y":21},{"x":12,"y":42},{"x":19,"y":92},{"x":3,"y":98},{"x":-8,"y":86},{"x":-3,"y":24},{"x":-20,"y":71},{"x":-36,"y":99},{"x":-55,"y":91},{"x":-54,"y":65},{"x":-18,"y":22},{"x":-62,"y":59},{"x":-86,"y":80},{"x":-96,"y":69},{"x":-96,"y":59},{"x":-64,"y":33},{"x":-37,"y":12},{"x":-119,"y":52},{"x":-132,"y":37},{"x":-112,"y":18},{"x":-39,"y":0}]
var fishImg
function preload(){
fishImg = loadImage("fish.png")
fish2Img = loadImage("fish2.png")
// fish3Img = loadImage("fish3.png")
fish4Img = loadImage("fish4.png")
}
var fishArray = []
var fishArray2 = []
// var fishArray3 = []
var fishArray4 = []
function setup() {
createCanvas(windowWidth, windowHeight);
fishGraphics= createGraphics(width,height)
inkGraphics= createGraphics(width,height)
background(12,152,186)
for(var i=0;i<45;i++){
let fish = new Fish({
p: createVector(random(width),random(height)),
v: createVector(random(0,1),0),
scale: random(0.5,1),
img: fishImg
})
let fish2 = new Fish2({
p: createVector(random(width),random(height)),
v: createVector(-random(0,1),0),
scale: random(0.4,1),
img: fish2Img
})
// let fish3 = new Fish3({
// p: createVector(random(width),random(height)),
// v: createVector(-random(0,1),0),
// scale: random(0.3,1),
// img: fish3Img
// })
let fish4 = new Fish4({
p: createVector(random(width),random(height)),
v: createVector(-random(0,1),0),
scale: random(0.3,1),
img: fish4Img
})
fishArray.push(fish)
fishArray2.push(fish2)
// fishArray3.push(fish3)
fishArray4.push(fish4)
}
}
function draw() {
background(20, 52, 181+frameCount)
// imageMode(CENTER)
// for(let fish of fishArray){
// fish.update()
// fish.draw()
// }
for(let fish2 of fishArray2){
fish2.update()
fish2.draw()
}
// for(let fish3 of fishArray3){
// fish3.update()
// fish3.draw()
// }
for(let fish4 of fishArray4){
fish4.update()
fish4.draw()
}
if (mouseIsPressed){
inkGraphics.noStroke()
for(var i=0;i<10;i++){
inkGraphics.fill(0,random(100,255))
inkGraphics.ellipse(
mouseX+random(100,-250)*random(),
mouseY+random(-30,30),
random(40))
}
}
// fishGraphics.image(fishImg,0,0)
for(let fish of fishArray){
fish.update()
fish.draw()
}
// fishGraphics.fill('blue')
// fishGraphics.rect(mouseX,mouseY,20,20)
image(fishGraphics,0,0)
push()
//想放的位置
translate(mouseX,mouseY)
noStroke()
fill(255,50,50)
beginShape()
//把點抓出來畫
for(let p of shapes){
curveVertex(p.x,p.y)
}
endShape(CLOSE)
//加眼睛XD
fill(255)
noStroke()
ellipse(-30,-60,35)
ellipse(20,-60,35)
fill(0)
ellipse(-30+sin(frameCount/20)*5,-60,15)
ellipse(20+sin(frameCount/20)*5,-60,15)
//加嘴巴
strokeWeight(7);
stroke(30);
fill(150)
ellipse(-10,-20,30,30)
pop()
image(inkGraphics,0,0)
}
function mousePressed() {
inkGraphics.noStroke()
}