Particle smoke

Developer
Size
2,887 Kb
Views
4,048

How do I make an particle smoke?

What is a particle smoke? How do you make a particle smoke? This script and codes were developed by Khalkeus on 11 November 2022, Friday.

Particle smoke Previews

Particle smoke - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>particle smoke</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src='https://cdnjs.cloudflare.com/ajax/libs/three.js/84/three.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Particle smoke - Script Codes CSS Codes

body, html{	margin: 0px;	padding: 0px;	overflow: hidden;
}

Particle smoke - Script Codes JS Codes

var camera, renderer, scene, e, mouse;
// Initial setup
window.onload = function(){	init();
}
function init(){	mouse = [window.innerWidth/2, window.innerHeight/2];	renderer = new THREE.WebGLRenderer({antialias: true});	scene = new THREE.Scene();	camera = new THREE.PerspectiveCamera(20, window.innerWidth/window.innerHeight, 0.1, 1000);	renderer.setSize(window.innerWidth, window.innerHeight);	document.body.appendChild(renderer.domElement);	camera.position.z = 10;	camera.position.y = .5;	var light = new THREE.DirectionalLight(0xffffff);	light.position.set(-5, 10, 5);	scene.add(light)	scene.background = new THREE.Color(0x000000);	canvas = document.querySelector('#b canvas');	e = new Explosion(0, 0, 0, 100);	render();
}
window.onresize = function(){	camera.aspect = window.innerWidth/window.innerHeight;	camera.updateProjectionMatrix();	renderer.setSize(window.innerWidth, window.innerHeight);
}
window.onmousemove = function(e){	mouse = [e.clientX, e.clientY];
}
// Utility functions
function randomFloat(a, b){	var r = (Math.random() * (b - a) + a);	return r;
}
function partToHex(part){	var h = part.toString(16);	return h.length == 1 ? "0" + h : h;
}
// Explosion stuff
function ExplosionSphere(x, y, z, scaleSpeed, initScale, atom, velocity){	this.scaleSpeed = scaleSpeed;	this.active = true;	this.obj = atom.clone();	this.velocity;	this.maxSize;	this.age = 0;	this.init = function(x, y, z, scaleSpeed, initScale, velocity){	this.active = true;	this.scaleSpeed = scaleSpeed;	this.velocity = velocity;	this.maxSize = 1;	this.age = 0;	this.obj.rotation.set(randomFloat(0, Math.PI), randomFloat(0, Math.PI), randomFloat(0, Math.PI));	this.obj.position.set(x, y, z);	this.obj.scale.set(initScale, initScale, initScale);	}	this.init(x, y, z, scaleSpeed, initScale, velocity);	this.update = function(){	if(this.active){	if(this.obj.scale.x > this.maxSize || this.age > 100){	this.deactivate();	}	this.obj.scale.x *= this.scaleSpeed;	this.obj.scale.y *= this.scaleSpeed;	this.obj.scale.z *= this.scaleSpeed;	this.obj.position.x += this.velocity[0];	this.obj.position.y += this.velocity[1];	this.obj.position.z += this.velocity[2];	this.age++;	}	}	this.deactivate = function(){	this.active = false;	if(e != undefined){	this.init(e.obj.position.x, e.obj.position.y, 0, this.scaleSpeed, randomFloat(.1, 1), this.velocity);	}else{	this.init(0, 0, 0, this.scaleSpeed, randomFloat(.1, 1), this.velocity);	}	}
}
function Explosion(x, y, z, size){	this.x = x;	this.y = y;	this.z = z;	this.size = size;	this.radius = .5;	this.speed = .005;	this.p = new THREE.Vector3();	this.d;	this.dis;	this.obj = new THREE.Group();	this.atom = new THREE.Mesh(new THREE.IcosahedronGeometry(.1, 2), new THREE.MeshLambertMaterial({color: 0xffffff, emissive: 0x999999, side: THREE.FrontSide}));	this.atoms = [];	this.update = function(){	this.p.set((mouse[0]/window.innerWidth) * 2 - 1, (mouse[1]/window.innerHeight ) * 2 - 1, .5);	this.p.unproject(camera);	this.d = this.p.sub(camera.position).normalize();	this.dis = -camera.position.z/this.d.z;	this.pos = camera.position.clone().add(this.d.multiplyScalar(this.dis));	this.obj.position.x = this.pos.x;	this.obj.position.y = -this.pos.y + 1;	for(var i = 0; i < this.atoms.length; i++){	this.atoms[i].update();	}	}	this.init = function(){	for(var i = 0; i < this.size; i++){	this.atoms.push(new ExplosionSphere(0, 0, 0, randomFloat(1.001, 1.01), randomFloat(.1, 1), this.atom, [randomFloat(-this.speed, this.speed), randomFloat(this.speed * 2, this.speed * 5), randomFloat(-this.speed, this.speed)]));	scene.add(this.atoms[i].obj)	}	scene.add(this.obj);	for(var i = 0; i < 100; i++){	this.update();	}	}	this.init();
}
// Rendering and updating
function render(){	e.update();	renderer.render(scene, camera);	requestAnimationFrame(render);
}
Particle smoke - Script Codes
Particle smoke - Script Codes
Home Page Home
Developer Khalkeus
Username khalkeus
Uploaded November 11, 2022
Rating 3
Size 2,887 Kb
Views 4,048
Do you need developer help for Particle smoke?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Khalkeus (khalkeus) Script Codes
Create amazing marketing copy with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!