var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeig dịch - var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeig Việt làm thế nào để nói

var SCREEN_WIDTH = window.innerWidt

var SCREEN_WIDTH = window.innerWidth,
SCREEN_HEIGHT = window.innerHeight,
mousePos = {
x: 400,
y: 300
},

// create canvas
canvas = document.createElement('canvas'),
context = canvas.getContext('2d'),
particles = [],
rockets = [],
MAX_PARTICLES = 400,
colorCode = 0;

// init
$(document).ready(function() {
document.body.appendChild(canvas);
canvas.width = SCREEN_WIDTH;
canvas.height = SCREEN_HEIGHT;
setInterval(launch, 800);
setInterval(loop, 1000 / 50);
});

// update mouse position
$(document).mousemove(function(e) {
e.preventDefault();
mousePos = {
x: e.clientX,
y: e.clientY
};
});

// launch more rockets!!!
$(document).mousedown(function(e) {
for (var i = 0; i < 5; i++) {
launchFrom(Math.random() * SCREEN_WIDTH * 2 / 3 + SCREEN_WIDTH / 6);
}
});

function launch() {
launchFrom(mousePos.x);
}

function launchFrom(x) {
if (rockets.length < 10) {
var rocket = new Rocket(x);
rocket.explosionColor = Math.floor(Math.random() * 360 / 10) * 10;
rocket.vel.y = Math.random() * -3 - 4;
rocket.vel.x = Math.random() * 6 - 3;
rocket.size = 8;
rocket.shrink = 0.999;
rocket.gravity = 0.01;
rockets.push(rocket);
}
}

function loop() {
// update screen size
if (SCREEN_WIDTH != window.innerWidth) {
canvas.width = SCREEN_WIDTH = window.innerWidth;
}
if (SCREEN_HEIGHT != window.innerHeight) {
canvas.height = SCREEN_HEIGHT = window.innerHeight;
}

// clear canvas
context.fillStyle = "rgba(0, 0, 0, 0.05)";
context.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

var existingRockets = [];

for (var i = 0; i < rockets.length; i++) {
// update and render
rockets[i].update();
rockets[i].render(context);

// calculate distance with Pythagoras
var distance = Math.sqrt(Math.pow(mousePos.x - rockets[i].pos.x, 2) + Math.pow(mousePos.y - rockets[i].pos.y, 2));

// random chance of 1% if rockets is above the middle
var randomChance = rockets[i].pos.y < (SCREEN_HEIGHT * 2 / 3) ? (Math.random() * 100 = 0 || distance < 50 || randomChance) {
rockets[i].explode();
} else {
existingRockets.push(rockets[i]);
}
}

rockets = existingRockets;

var existingParticles = [];

for (var i = 0; i < particles.length; i++) {
particles[i].update();

// render and save particles that can be rendered
if (particles[i].exists()) {
particles[i].render(context);
existingParticles.push(particles[i]);
}
}

// update array with existing particles - old particles should be garbage collected
particles = existingParticles;

while (particles.length > MAX_PARTICLES) {
particles.shift();
}
}

function Particle(pos) {
this.pos = {
x: pos ? pos.x : 0,
y: pos ? pos.y : 0
};
this.vel = {
x: 0,
y: 0
};
this.shrink = .97;
this.size = 2;

this.resistance = 1;
this.gravity = 0;

this.flick = false;

this.alpha = 1;
this.fade = 0;
this.color = 0;
}

Particle.prototype.update = function() {
// apply resistance
this.vel.x *= this.resistance;
this.vel.y *= this.resistance;

// gravity down
this.vel.y += this.gravity;

// update position based on speed
this.pos.x += this.vel.x;
this.pos.y += this.vel.y;

// shrink
this.size *= this.shrink;

// fade out
this.alpha -= this.fade;
};

Particle.prototype.render = function(c) {
if (!this.exists()) {
return;
}

c.save();

c.globalCompositeOperation = 'lighter';

var x = this.pos.x,
y = this.pos.y,
r = this.size / 2;

var gradient = c.createRadialGradient(x, y, 0.1, x, y, r);
gradient.addColorStop(0.1, "rgba(255,255,255," + this.alpha + ")");
gradient.addColorStop(0.8, "hsla(" + this.color + ", 100%, 50%, " + this.alpha + ")");
gradient.addColorStop(1, "hsla(" + this.color + ", 100%, 50%, 0.1)");

c.fillStyle = gradient;

c.beginPath();
c.arc(this.pos.x, this.pos.y, this.flick ? Math.random() * this.size : this.size, 0, Math.PI * 2, true);
c.closePath();
c.fill();

c.restore();
};

Particle.prototype.exists = function() {
return this.alpha >= 0.1 && this.size >= 1;
};

function Rocket(x) {
Particle.apply(this, [{
x: x,
y: SCREEN_HEIGHT}]);

this.explosionColor = 0;
}

Rocket.prototype = new Particle();
Rocket.prototype.constructor = Rocket;

Rocket.prototype.explode = function() {
var count = Math.random() * 10 + 80;

for (var i = 0; i < count; i++) {
var particle = new Particle(this.pos);
var angle = Math.random() * Math.PI * 2;

// emulate 3D effect by using cosine and put more particles in the middle
var speed = Math.cos(Math.random() * Math.PI / 2) * 15;

particle.vel.x = Math.cos(angle) * speed;
particle.vel.y = Math.sin(angle) * speed;

particle.size = 10;

particle.gravity = 0.2;
particle.resistance = 0.92;
particle.shrink = Math.random() * 0.05 + 0.93;

particle.flick = true;
particle.color = this.explosionColor;

particles.push(particle);
}
};

Rocket.prototype.render = function(c) {
if (!this.exists()) {
return;
}

c.save();

c.globalCompositeOperation = 'lighter';

var x = this.pos.x,
y = this.pos.y,
r = this.size / 2;

var gradient = c.createRadialGradient(x, y, 0.1, x, y, r);
gradient.addColorStop(0.1, "rgba(255, 255, 255 ," + this.alpha + ")");
gradient.addColorStop(1, "rgba(0, 0, 0, " + this.alpha + ")");

c.fillStyle = gradient;

c.beginPath();
c.arc(this.pos.x, this.pos.y, this.flick ? Math.random() * this.size / 2 + this.size / 2 : this.size, 0, Math.PI * 2, true);
c.closePath();
c.fill();

c.restore();
};
0/5000
Từ: -
Sang: -
Kết quả (Việt) 1: [Sao chép]
Sao chép!
var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight, mousePos = { x: 400, y: 300 }, // create canvas canvas = document.createElement('canvas'), context = canvas.getContext('2d'), particles = [], rockets = [], MAX_PARTICLES = 400, colorCode = 0;// init$(document).ready(function() { document.body.appendChild(canvas); canvas.width = SCREEN_WIDTH; canvas.height = SCREEN_HEIGHT; setInterval(launch, 800); setInterval(loop, 1000 / 50);});// update mouse position$(document).mousemove(function(e) { e.preventDefault(); mousePos = { x: e.clientX, y: e.clientY };});// launch more rockets!!!$(document).mousedown(function(e) { for (var i = 0; i < 5; i++) { launchFrom(Math.random() * SCREEN_WIDTH * 2 / 3 + SCREEN_WIDTH / 6); }});function launch() { launchFrom(mousePos.x);}function launchFrom(x) { if (rockets.length < 10) { var rocket = new Rocket(x); rocket.explosionColor = Math.floor(Math.random() * 360 / 10) * 10; rocket.vel.y = Math.random() * -3 - 4; rocket.vel.x = Math.random() * 6 - 3; rocket.size = 8; rocket.shrink = 0.999; rocket.gravity = 0.01; rockets.push(rocket); }}function loop() { // update screen size if (SCREEN_WIDTH != window.innerWidth) { canvas.width = SCREEN_WIDTH = window.innerWidth; } if (SCREEN_HEIGHT != window.innerHeight) { canvas.height = SCREEN_HEIGHT = window.innerHeight; } // clear canvas context.fillStyle = "rgba(0, 0, 0, 0.05)"; context.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
var existingRockets = [];

for (var i = 0; i < rockets.length; i++) {
// update and render
rockets[i].update();
rockets[i].render(context);

// calculate distance with Pythagoras
var distance = Math.sqrt(Math.pow(mousePos.x - rockets[i].pos.x, 2) + Math.pow(mousePos.y - rockets[i].pos.y, 2));

// random chance of 1% if rockets is above the middle
var randomChance = rockets[i].pos.y < (SCREEN_HEIGHT * 2 / 3) ? (Math.random() * 100 <= 1) : false;

/* Explosion rules
- 80% of screen
- going down
- close to the mouse
- 1% chance of random explosion
*/
if (rockets[i].pos.y < SCREEN_HEIGHT / 5 || rockets[i].vel.y >= 0 || distance < 50 || randomChance) {
rockets[i].explode();
} else {
existingRockets.push(rockets[i]);
}
}

rockets = existingRockets;

var existingParticles = [];

for (var i = 0; i < particles.length; i++) {
particles[i].update();

// render and save particles that can be rendered
if (particles[i].exists()) {
particles[i].render(context);
existingParticles.push(particles[i]);
}
}

// update array with existing particles - old particles should be garbage collected
particles = existingParticles;

while (particles.length > MAX_PARTICLES) {
particles.shift();
}
}

function Particle(pos) {
this.pos = {
x: pos ? pos.x : 0,
y: pos ? pos.y : 0
};
this.vel = {
x: 0,
y: 0
};
this.shrink = .97;
this.size = 2;

this.resistance = 1;
this.gravity = 0;

this.flick = false;

this.alpha = 1;
this.fade = 0;
this.color = 0;
}

Particle.prototype.update = function() {
// apply resistance
this.vel.x *= this.resistance;
this.vel.y *= this.resistance;

// gravity down
this.vel.y += this.gravity;

// update position based on speed
this.pos.x += this.vel.x;
this.pos.y += this.vel.y;

// shrink
this.size *= this.shrink;

// fade out
this.alpha -= this.fade;
};

Particle.prototype.render = function(c) {
if (!this.exists()) {
return;
}

c.save();

c.globalCompositeOperation = 'lighter';

var x = this.pos.x,
y = this.pos.y,
r = this.size / 2;

var gradient = c.createRadialGradient(x, y, 0.1, x, y, r);
gradient.addColorStop(0.1, "rgba(255,255,255," + this.alpha + ")");
gradient.addColorStop(0.8, "hsla(" + this.color + ", 100%, 50%, " + this.alpha + ")");
gradient.addColorStop(1, "hsla(" + this.color + ", 100%, 50%, 0.1)");

c.fillStyle = gradient;

c.beginPath();
c.arc(this.pos.x, this.pos.y, this.flick ? Math.random() * this.size : this.size, 0, Math.PI * 2, true);
c.closePath();
c.fill();

c.restore();
};

Particle.prototype.exists = function() {
return this.alpha >= 0.1 && this.size >= 1;
};

function Rocket(x) {
Particle.apply(this, [{
x: x,
y: SCREEN_HEIGHT}]);

this.explosionColor = 0;
}

Rocket.prototype = new Particle();
Rocket.prototype.constructor = Rocket;

Rocket.prototype.explode = function() {
var count = Math.random() * 10 + 80;

for (var i = 0; i < count; i++) {
var particle = new Particle(this.pos);
var angle = Math.random() * Math.PI * 2;

// emulate 3D effect by using cosine and put more particles in the middle
var speed = Math.cos(Math.random() * Math.PI / 2) * 15;

particle.vel.x = Math.cos(angle) * speed;
particle.vel.y = Math.sin(angle) * speed;

particle.size = 10;

particle.gravity = 0.2;
particle.resistance = 0.92;
particle.shrink = Math.random() * 0.05 + 0.93;

particle.flick = true;
particle.color = this.explosionColor;

particles.push(particle);
}
};

Rocket.prototype.render = function(c) {
if (!this.exists()) {
return;
}

c.save();

c.globalCompositeOperation = 'lighter';

var x = this.pos.x,
y = this.pos.y,
r = this.size / 2;

var gradient = c.createRadialGradient(x, y, 0.1, x, y, r);
gradient.addColorStop(0.1, "rgba(255, 255, 255 ," + this.alpha + ")");
gradient.addColorStop(1, "rgba(0, 0, 0, " + this.alpha + ")");

c.fillStyle = gradient;

c.beginPath();
c.arc(this.pos.x, this.pos.y, this.flick ? Math.random() * this.size / 2 + this.size / 2 : this.size, 0, Math.PI * 2, true);
c.closePath();
c.fill();

c.restore();
};
đang được dịch, vui lòng đợi..
Kết quả (Việt) 2:[Sao chép]
Sao chép!
var SCREEN_WIDTH = window.innerWidth,
SCREEN_HEIGHT = window.innerHeight,
mousePos =
{x: 400,
y:
300}, // tạo ra vải canvas = document.createElement ('vải'), context = canvas.getContext ('2d') , hạt = [], tên lửa = [], MAX_PARTICLES = 400, Colorcode = 0; // init $ (document) .ready (function () {document.body.appendChild (vải); canvas.width = SCREEN_WIDTH; canvas. height = SCREEN_HEIGHT; setInterval (ra mắt, 800); setInterval (loop, 1000-1050);}); // vị trí cập nhật chuột $ (document) .mousemove (function (e) {e.preventDefault (); mousePos = {x : e.clientX, y: e.clientY};}); // khởi động nhiều tên lửa !!! $ (document) .mousedown (function (e) {for (var i = 0; i <5; i ++) {launchFrom (Math.random () * SCREEN_WIDTH * 2/3 + SCREEN_WIDTH / 6);}}); chức năng khởi động () {launchFrom (mousePos.x);} function launchFrom (x) {if (rockets.length <10) { var = tên lửa Rocket mới (x); rocket.explosionColor = Math.floor (Math.random () * 360/10) * 10; rocket.vel.y = Math.random () * -3 - 4; rocket.vel .x = Math.random () * 6-3; rocket.size = 8; rocket.shrink = 0,999; rocket.gravity = 0,01; rockets.push (tên lửa);}} chức năng loop () {// cập nhật kích thước màn hình if (SCREEN_WIDTH = window.innerWidth!) {canvas.width = SCREEN_WIDTH = window.innerWidth;} if (SCREEN_HEIGHT = window.innerHeight!) {canvas.height = SCREEN_HEIGHT = window.innerHeight;} // rõ ràng vải context.fillStyle = "rgba (0, 0, 0, 0.05)"; context.fillRect (0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); var existingRockets = []; for (var i = 0; i <rockets.length; i ++) {// cập nhật và đưa ra tên lửa [i] .update (); rocket [i] .render (context); // tính toán khoảng cách với Pythagoras var khoảng cách = Math.sqrt (Math.pow (mousePos.x - tên lửa [ i] .pos.x, 2) + Math.pow (mousePos.y - tên lửa [i] .pos.y, 2)); // cơ hội ngẫu nhiên 1% nếu tên lửa là ở trên giữa var randomChance = tên lửa [i ] .pos.y <(SCREEN_HEIGHT * 2/3)? (Math.random () * 100 <= 1): false; / * quy tắc Explosion - 80% của màn hình - đi xuống - gần với chuột - 1% cơ hội bùng nổ ngẫu nhiên * / if (tên lửa [i] .pos. y <SCREEN_HEIGHT / 5 || rocket [i] .vel.y> = 0 || khoảng cách <50 || randomChance) {tên lửa [i] .explode ();} else {existingRockets.push (tên lửa [i]); }} rocket = existingRockets; var existingParticles = []; for (var i = 0; i <particles.length; i ++) {hạt [i] .update (); // vẽ lại và lưu các hạt có thể được trả lại nếu (hạt [i] .exists ()) {hạt [i] .render (context); existingParticles.push (hạt [i]);}} // cập nhật mảng với các hạt hiện có - hạt cũ cần được thu gom rác thải hạt = existingParticles; trong khi (particles.length> MAX_PARTICLES) {particles.shift ();}} chức năng Particle (pos) {this.pos = {x: pos? pos.x: 0, y: pos? pos.y: 0}; this.vel = {x: 0, y: 0}; this.shrink = .97; this.size = 2; this.resistance = 1; this.gravity = 0; this.flick = false; this.alpha = 1; this.fade = 0; this.color = 0;} Particle.prototype.update = function () {// áp dụng kháng this.vel.x * = this.resistance; this.vel. y * = this.resistance; // trọng lực xuống this.vel.y + = this.gravity; // vị trí cập nhật dựa trên tốc độ this.pos.x + = this.vel.x; this.pos.y + = này .vel.y; // co this.size * = this.shrink; // phai ra this.alpha - = this.fade;}; = function Particle.prototype.render (c) {if (! this.exists ( )) {return;} c.save (); c.globalCompositeOperation = 'nhẹ'; var x = this.pos.x, y = this.pos.y, r = this.size / 2; var Gradient = c. createRadialGradient (x, y, 0,1, x, y, r); gradient.addColorStop (0,1, "rgba (255.255.255," + this.alpha + ")"); gradient.addColorStop (0,8, "HSLA (" + này. màu + ", 100%, 50%," + this.alpha + ")"); gradient.addColorStop (1, "HSLA (" + this.color + ", 100%, 50%, 0,1)"); c .fillStyle = gradient; c.beginPath (); c.arc (this.pos.x, this.pos.y, this.flick? Math.random () * this.size: this.size, 0, Math.PI * 2, true); c.closePath (); c.fill (); c.restore ();}; Particle.prototype.exists = function () {return this.alpha> = 0.1 && this.size> = 1;}; chức năng Rocket (x) {Particle.apply (this, [{x: x, y: SCREEN_HEIGHT}]); this.explosionColor = 0;} Rocket.prototype = new Particle (); Rocket.prototype.constructor = Rocket; Rocket.prototype.explode = function () {var count = Math.random () * 10 + 80; for (var i = 0 ; i <count; i ++) {var hạt = Particle mới (this.pos); góc var = Math.random () * Math.PI * 2; // chước hiệu ứng 3D bằng cách sử dụng cosin và đặt hạt hơn ở giữa var tốc độ = Math.cos (Math.random () * Math.PI / 2) * 15; particle.vel.x = Math.cos (góc) * Tốc độ; particle.vel.y = Math.sin (góc) * Tốc độ ; particle.size = 10; particle.gravity = 0,2; particle.resistance = 0,92; particle.shrink = Math.random () * 0,05 + 0,93; particle.flick = true; particle.color = this.explosionColor; particles.push (hạt);}}; Rocket.prototype.render = function (c) {nếu {(this.exists ()) return;} c.save (); c.globalCompositeOperation = 'nhẹ'; var x = này. pos.x, y = this.pos.y, r = this.size / 2; var Gradient = c.createRadialGradient (x, y, 0,1, x, y, r); gradient.addColorStop (0,1, "rgba (255 , 255, 255, "+ this.alpha +") "); gradient.addColorStop (1," rgba (0, 0, 0, "+ this.alpha +") "); c.fillStyle = gradient; c. beginPath (); c.arc (this.pos.x, this.pos.y, this.flick? Math.random () * this.size / 2 + this.size / 2: this.size, 0, Math.PI * 2, true); c.closePath (); c.fill (); c.restore () ;};























































































































































































































































đang được dịch, vui lòng đợi..
 
Các ngôn ngữ khác
Hỗ trợ công cụ dịch thuật: Albania, Amharic, Anh, Armenia, Azerbaijan, Ba Lan, Ba Tư, Bantu, Basque, Belarus, Bengal, Bosnia, Bulgaria, Bồ Đào Nha, Catalan, Cebuano, Chichewa, Corsi, Creole (Haiti), Croatia, Do Thái, Estonia, Filipino, Frisia, Gael Scotland, Galicia, George, Gujarat, Hausa, Hawaii, Hindi, Hmong, Hungary, Hy Lạp, Hà Lan, Hà Lan (Nam Phi), Hàn, Iceland, Igbo, Ireland, Java, Kannada, Kazakh, Khmer, Kinyarwanda, Klingon, Kurd, Kyrgyz, Latinh, Latvia, Litva, Luxembourg, Lào, Macedonia, Malagasy, Malayalam, Malta, Maori, Marathi, Myanmar, Mã Lai, Mông Cổ, Na Uy, Nepal, Nga, Nhật, Odia (Oriya), Pashto, Pháp, Phát hiện ngôn ngữ, Phần Lan, Punjab, Quốc tế ngữ, Rumani, Samoa, Serbia, Sesotho, Shona, Sindhi, Sinhala, Slovak, Slovenia, Somali, Sunda, Swahili, Séc, Tajik, Tamil, Tatar, Telugu, Thái, Thổ Nhĩ Kỳ, Thụy Điển, Tiếng Indonesia, Tiếng Ý, Trung, Trung (Phồn thể), Turkmen, Tây Ban Nha, Ukraina, Urdu, Uyghur, Uzbek, Việt, Xứ Wales, Yiddish, Yoruba, Zulu, Đan Mạch, Đức, Ả Rập, dịch ngôn ngữ.

Copyright ©2025 I Love Translation. All reserved.

E-mail: