第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

正在回答

1 回答

直接代碼發(fā)你吧

main.js

var can;

var ctx;


var w;

var h;


var padLeft = 100;

var padTop = 100;


var girlWidth = 600;

var girlHeight = 300;


var deltaTime;

var lastTime;


var girlPic = new Image();

var starPic = new Image();


var stars = [];

var num = 30;


var alive = 0;


var switchy = false;


function init() {

can = document.getElementById("canvas");

ctx = can.getContext("2d");


w = can.width;

h = can.height;


document.addEventListener('mousemove', mousemove, false);


girlPic.src = "src/girl.jpg";

starPic.src = "src/star.png";


for (var i = 0; i < num; i++) {

stars[i] = new starObj();

stars[i].init();

}


lastTime = Date.now();

gameLoop();

}


function gameLoop() {

window.requestAnimFrame(gameLoop);

var now = Date.now();

deltaTime = now - lastTime;

lastTime = now;


fillCanvas();

drawGirl();


drawStars();


aliveUpdate();

}


function fillCanvas() {

ctx.fillStyle = "#393550";

ctx.fillRect(0, 0, w, h);

}


function drawGirl() {

ctx.drawImage(girlPic, padLeft, padTop, girlWidth, girlHeight);

}


function mousemove(e) {

if (e.offsetX || e.layerX) {


var px = e.offsetX == undefined ? e.layerX : e.offsetX;

var py = e.offsetY == undefined ? e.layerY : e.offsetY;


if (px > padLeft && px < (padLeft + girlWidth) && py > padTop && py < (padTop + girlHeight)) {

switchy = true;

} else {

switchy = false;

}

}

}

stars.js


var starObj = function() {

this.x;

this.y;


this.ySpd;


this.picNo;


this.timer;


this.beta;

}


starObj.prototype.init = function() {

this.x = Math.random() * girlWidth + padLeft;

this.y = Math.random() * girlHeight + padTop;


this.ySpd = Math.random() * 0.6 - 0.3; //[0,2) [-1, 1)

this.xSpd = Math.random() * 0.2 - 0.1; //[0,2) [-1, 1)


this.picNo = Math.floor(Math.random() * 7);

this.timer = 0;


this.beta = Math.random() * Math.PI * 0.5;

}


starObj.prototype.update = function() {

this.xSpd = Math.random() * 0.2 - 0.1; //[0,2) [-1, 1)

this.x += this.xSpd;

this.y += this.ySpd;


if (this.x > (padLeft + girlWidth) || this.x < (padLeft - 10))

this.init();

else if (this.y > (padTop + girlHeight) || this.y < (padTop - 10))

this.init();


this.timer += deltaTime;

if (this.timer > 30) {

this.picNo += 1;

this.picNo %= 7;

this.timer = 0;

}

}


starObj.prototype.draw = function() {

this.beta += deltaTime * 0.005;

ctx.save();

ctx.globalAlpha = Math.sin(this.beta) * alive;

console.log(alive);

console.log(ctx.globalAlpha);

ctx.drawImage(starPic, this.picNo * 7, 0, 7, 7, this.x, this.y, 7, 7);

ctx.restore();

}




function drawStars() {

for (var i = 0; i < num; i++) {

stars[i].update();

stars[i].draw();

}

}


function aliveUpdate() {

if (switchy) {

alive += 0.03;

if (alive > 0.7) {

alive = 0.7;

}

} else {

alive -= 0.03;

if (alive < 0) {

alive = 0;

}

}

}


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
canvas實(shí)現(xiàn)星星閃爍特效
  • 參與學(xué)習(xí)       54188    人
  • 解答問題       123    個(gè)

使用HTML5實(shí)現(xiàn)輪播圖片上的序列幀,進(jìn)行拆分講解,逐步實(shí)現(xiàn)目標(biāo)

進(jìn)入課程

下載資源有問題呢

我要回答 關(guān)注問題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)