/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for creating fluid art particles
var FluidParticle = Container.expand(function () {
var self = Container.call(this);
// Create and attach a circular asset for the particle
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
blendMode: 1
});
// Change the color of the particle to blue
self.tint = 0x0000FF;
// Randomize initial properties
self.speedX = (Math.random() - 0.5) * 10;
self.speedY = (Math.random() - 0.5) * 10;
self.alpha = Math.random() * 0.5 + 0.5;
self.scale.set(Math.random() * 0.5 + 0.5);
// Update function to animate the particle
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
self.alpha -= 0.01;
if (self.alpha <= 0) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Array to keep track of all fluid particles
var particles = [];
// Function to create a burst of particles at a given position
function createParticleBurst(x, y) {
for (var i = 0; i < 20; i++) {
var particle = new FluidParticle();
particle.attachAsset('particle', {
color: Math.random() * 0xFFFFFF,
blendMode: 1
});
particle.x = x;
particle.y = y;
particles.push(particle);
game.addChild(particle);
}
}
// Handle touch or mouse down event to create fluid art
game.down = function (x, y, obj) {
this.swipeStart = {
x: x,
y: y
};
};
game.move = function (x, y, obj) {
if (this.swipeStart) {
var dx = x - this.swipeStart.x;
var dy = y - this.swipeStart.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 50) {
// Change the color of the particle each swipe
createParticleBurst(this.swipeStart.x, this.swipeStart.y);
this.swipeStart = {
x: x,
y: y
};
}
}
};
game.up = function (x, y, obj) {
this.swipeStart = null;
};
// Update function to animate particles
game.update = function () {
for (var i = particles.length - 1; i >= 0; i--) {
var particle = particles[i];
particle.update();
if (particle.alpha <= 0) {
particles.splice(i, 1);
}
}
}; /****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for creating fluid art particles
var FluidParticle = Container.expand(function () {
var self = Container.call(this);
// Create and attach a circular asset for the particle
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
blendMode: 1
});
// Change the color of the particle to blue
self.tint = 0x0000FF;
// Randomize initial properties
self.speedX = (Math.random() - 0.5) * 10;
self.speedY = (Math.random() - 0.5) * 10;
self.alpha = Math.random() * 0.5 + 0.5;
self.scale.set(Math.random() * 0.5 + 0.5);
// Update function to animate the particle
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
self.alpha -= 0.01;
if (self.alpha <= 0) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Array to keep track of all fluid particles
var particles = [];
// Function to create a burst of particles at a given position
function createParticleBurst(x, y) {
for (var i = 0; i < 20; i++) {
var particle = new FluidParticle();
particle.attachAsset('particle', {
color: Math.random() * 0xFFFFFF,
blendMode: 1
});
particle.x = x;
particle.y = y;
particles.push(particle);
game.addChild(particle);
}
}
// Handle touch or mouse down event to create fluid art
game.down = function (x, y, obj) {
this.swipeStart = {
x: x,
y: y
};
};
game.move = function (x, y, obj) {
if (this.swipeStart) {
var dx = x - this.swipeStart.x;
var dy = y - this.swipeStart.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 50) {
// Change the color of the particle each swipe
createParticleBurst(this.swipeStart.x, this.swipeStart.y);
this.swipeStart = {
x: x,
y: y
};
}
}
};
game.up = function (x, y, obj) {
this.swipeStart = null;
};
// Update function to animate particles
game.update = function () {
for (var i = particles.length - 1; i >= 0; i--) {
var particle = particles[i];
particle.update();
if (particle.alpha <= 0) {
particles.splice(i, 1);
}
}
};