Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              
            
          
!

CSS

            
              * {
	border: 0;
	box-sizing: border-box;
	margin: 0;
	padding: 0
}
body {
	overflow: hidden;
}
canvas {
	cursor: grab;
}
            
          
!

JS

            
              window.addEventListener("DOMContentLoaded",app);

function app() {
	var scene,
		renderer,
		axes,
		camera,
		camControls,
		GUI,

		textureLoader = new THREE.TextureLoader(),
		surfaceTexture,

		controls,
		particleOptions,
		tornadoOptions,
		particles = [],

		particle = {
			count: 30,
			size: 1,
			horzSpacing: 45,
			vertSpacing: 1,
			spread: 10
		},
		tornado = {
			reach: 1,
			rot: 0,
			pos: {
				x: 0,
				z: 0
			},
			speed: 4
		},
		showAxes = false,

		lightColor = 0xccccaa,
		skyColor = 0x989ba8;

	class Particle {
		constructor(name,y,dist = 0,rot = 0) {
			// main properties
			this.dist = dist;
			this.rot = rot;

			// model properties
			this.geo = new THREE.SphereGeometry(1,16,16);
			this.mat = new THREE.MeshLambertMaterial({
				color: 0x242424
			});
			this.mesh = new THREE.Mesh(this.geo, this.mat);
			this.mesh.name = name;
			this.mesh.position.set(
				dist * Math.sin(rot * Math.PI/180) + tornado.pos.x,
				y,
				dist * Math.cos(rot * Math.PI/180) + tornado.pos.y,
			);
			this.mesh.scale.x = particle.size;
			this.mesh.scale.y = particle.size;
			this.mesh.scale.z = particle.size;
			this.mesh.castShadow = true;

			scene.add(this.mesh);
		}
		incRotation(by) {
			this.rot -= by;

			if (this.rot <= 0)
				this.rot += 360;

			this.mesh.position.x = this.dist * Math.sin(this.rot * Math.PI/180) + tornado.pos.x;
			this.mesh.position.z = this.dist * Math.cos(this.rot * Math.PI/180) + tornado.pos.z;
		}
	}
	
	var init = () => {
			// I. Setup
			// A. Textures
			surfaceTexture = textureLoader.load("https://i.ibb.co/KrgXYY5/grass.jpg");

			// B. Scene
			scene = new THREE.Scene();
			camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
			renderer = new THREE.WebGLRenderer();
			renderer.setClearColor(new THREE.Color(skyColor));
			renderer.setSize(window.innerWidth, window.innerHeight);
			renderer.shadowMap.enabled = true;
			
			// C. Axes
			axes = new THREE.AxesHelper(8);
			
			// II. Lighting
			// A. Ambient
			var ambientLight = new THREE.AmbientLight(lightColor);
			scene.add(ambientLight);

			// B. Hemisphere
			var hemiLight = new THREE.HemisphereLight(lightColor,0xffffff,0.5);
			hemiLight.position.set(0,8,0);
			scene.add(hemiLight);
			
			// C. Point
			var pointLight = new THREE.PointLight(0xffffff,0.5);
			pointLight.position.set(0,128,0);
			pointLight.castShadow = true;
			pointLight.shadow.mapSize = new THREE.Vector2(512,512);
			scene.add(pointLight);

			// III. Objects
			// A. Surface
			var surfaceGeo = new THREE.PlaneGeometry(256,256),
				surfaceMat = new THREE.MeshLambertMaterial({
					color: 0xf1ffa8,
					map: surfaceTexture
				}),
				surface = new THREE.Mesh(surfaceGeo, surfaceMat);

			surfaceMat.map.wrapS = THREE.RepeatWrapping;
			surfaceMat.map.wrapT = THREE.RepeatWrapping;
			surfaceMat.map.repeat.set(32,32);

			surface.name = "Surface";
			surface.rotation.x = -0.5 * Math.PI;
			surface.position.set(0,0,0);
			surface.receiveShadow = true;
			scene.add(surface);

			// B. Particles
			for (let p = 0; p < particle.count; ++p) {
				particles.push(
					new Particle(
						"Particle" + (p + 1),
						(p + 1) * particle.vertSpacing,
						particle.spread * p/particle.count,
						p * particle.horzSpacing
					)
				);
			}

			// IV. Controls
			// A. Interface
			controls = {
				count: particle.count,
				size: particle.size,
				horzSpacing: particle.horzSpacing,
				vertSpacing: particle.vertSpacing,
				spread: particle.spread,
				reach: tornado.reach,
				speed: tornado.speed,
				showAxes: showAxes,
				resetCam: function() {
					camControls.reset();
				}
			};
			GUI = new dat.GUI({
				width: 300
			});
			particleOptions = GUI.addFolder("Particles");
			particleOptions.open();
			tornadoOptions = GUI.addFolder("Tornado");
			tornadoOptions.open();

			// B. Options
			particleOptions.add(controls,"count",1,150,1).name("Count").onChange(e => {
				particle.count = controls.count;
				let unchanged = particle.count == particles.length;

				// removing particles
				if (particle.count < particles.length) {
					let particlesToKill = particles.length - particle.count;

					while (particlesToKill--) {
						scene.remove(scene.getObjectByName("Particle" + particles.length));
						particles.pop();
					}

				// adding particles
				} else if (particle.count > particles.length) {
					let particlesToAdd = particle.count - particles.length;

					while (particlesToAdd--) {
						let tempTotal = particles.length + 1;

						particles.push(
							new Particle(
								"Particle" + tempTotal,
								tempTotal * particle.vertSpacing
							)
						);
					}
				}
				// refresh spread based on new count, otherwise prevent jerking if same
				if (!unchanged)
					particles.forEach(function(e,i){
						e.dist = particle.spread * i/particle.count;
						e.rot = i * particle.horzSpacing;
					});
			});
			particleOptions.add(controls,"size",0.1,2,0.01).name("Size").onChange(e => {
				particle.size = controls.size;

				particles.forEach(function(e,i){
					let scale = e.geo.parameters.radius * particle.size;
					e.mesh.scale.x = scale;
					e.mesh.scale.y = scale;
					e.mesh.scale.z = scale;
				});
			});
			particleOptions.add(controls,"horzSpacing",0,90,0.01).name("Horizontal Spacing").onChange(e => {
				particle.horzSpacing = controls.horzSpacing;

				particles.forEach(function(e,i){
					e.rot = (i - 1) * particle.horzSpacing;
				});
			});
			particleOptions.add(controls,"vertSpacing",0.1,2,0.01).name("Vertical Spacing").onChange(e => {
				particle.vertSpacing = controls.vertSpacing;

				particles.forEach(function(e,i){
					e.mesh.position.y = (i + 1) * particle.vertSpacing;
				});
			});
			particleOptions.add(controls,"spread",0,50,0.01).name("Spread").onChange(e => {
				particle.spread = controls.spread;

				particles.forEach(function(e,i){
					e.dist = particle.spread * i/particles.length;
				});
			});
			tornadoOptions.add(controls,"reach",0,4,0.01).name("Reach").onChange(e => {
				tornado.reach = controls.reach;
			});
			tornadoOptions.add(controls,"speed",0,10,0.5).name("Speed").onChange(e => {
				tornado.speed = controls.speed;
			});
			GUI.add(controls,"showAxes",false).name("Show Axes").onChange(e => {
				showAxes = controls.showAxes;

				showAxes ? scene.add(axes) : scene.remove(axes);
			});
			GUI.add(controls,"resetCam").name("Reset Camera");
			
			// V. Camera
			camera.position.set(0,75,75);
			//camera.lookAt(scene.position);
			
			// VI. Rendering
			document.body.appendChild(renderer.domElement);

			// VII. Camera Control
			camControls = new THREE.OrbitControls(camera,renderer.domElement);

		},
		update = () => {
			// particles
			particles.forEach(e => {
				e.incRotation(tornado.speed);
			});

			// tornado itself
			tornado.rot += tornado.speed;

			if (tornado.rot >= 360)
				tornado.rot = 0;

			tornado.pos.x = tornado.reach * Math.sin(tornado.rot * Math.PI/180);
			tornado.pos.z = tornado.reach * Math.cos(tornado.rot * Math.PI/180);

			// rendering
			render();
			requestAnimationFrame(update);
		},
		render = () => {
			renderer.render(scene,camera);
		},
		adjustScreen = () => {
			camera.aspect = window.innerWidth / window.innerHeight;
			camera.updateProjectionMatrix();
			renderer.setSize(window.innerWidth,window.innerHeight)
		}

	init();
	update();
	window.addEventListener("resize",adjustScreen);
}
            
          
!
999px

Console