cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div id="content">
<canvas id="stage" width="800" height="800"></canvas>
</div>
            
          
!
            
              body {
	background-color: #000;
	margin: 0;
	padding: 0;
	height: 100%;
}
#content {
  width: 100%;
  text-align: center;
}
#stage {
  margin: 0 auto;
}
            
          
!
            
              $('document').ready(function() {
	
	var jq_window = $(window);
	var jq_canvas = $("#stage");

	var canvas = jq_canvas[0];
	var context = canvas.getContext("2d");
	
	var canvas_width_org = jq_canvas.width();
	var canvas_height_org = jq_canvas.height();
	
	var canvas_left, canvas_top;
	
	var canvas_width, canvas_height;
	
	var win_width, win_height;
	
	setPointSize();
	
	jq_window.resize(function(e){
		setPointSize();
	});
	
	var center_x = canvas_width / 2 - canvas_left;
	var center_y = canvas_height / 2 - canvas_top;

	jq_canvas.click(function(e){
		center_x = e.pageX - canvas_left;
		center_y = e.pageY - canvas_top;
		});

	var DOTS_MAX = 50; 
	var DEG2RAG = Math.PI / 180;
	var CIRCLE_RAD = 360 * DEG2RAG;
	
	function RotationDot() {
		this.distance = Math.random() * (canvas_width / 3) + (canvas_width / 20); 
		this.angle = Math.random() * 360;
		this.x = Math.cos(this.angle * DEG2RAG) * this.distance;
		this.y = Math.sin(this.angle * DEG2RAG) * this.distance;
		this.r = Math.random() * 10; 
		this.step = Math.random() * 3 + 1; 

		this.color = "rgb(255, 255, 255)";
	}
	RotationDot.prototype.move = function(){
		
		this.angle += this.step;
		if(this.angle > 360){
			this.angle = 0;
		}
		this.x = Math.cos(this.angle * DEG2RAG) * this.distance;
		this.y = Math.sin(this.angle * DEG2RAG) * this.distance;
	};
	RotationDot.prototype.draw = function(context){

		context.fillStyle = this.color;
		context.beginPath();
		context.arc(this.x + center_x, this.y + center_y, this.r, 0, CIRCLE_RAD, true);
		context.closePath();
		context.fill();
	};
	
	var dots = new Array();
	for(var i=0; i<DOTS_MAX; i++){
		
		dots.push(new RotationDot);
	}
	
 	var interval = 40;
	setInterval(function(){
		
			context.fillStyle = "rgba(0,0,0,0.1)";
			context.beginPath();
			context.rect(0, 0, canvas_width, canvas_height);
			context.closePath();
			context.fill();

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

				var dot = dots[i];
				dot.move();
				dot.draw(context);
			}
		},			
		interval);
				
	function setPointSize(){

		win_width = jq_window.width();
		win_height = jq_window.height();
		
		canvas_width = canvas_width_org;
		canvas_height = canvas_height_org;

		if( canvas_width_org > win_width){
			canvas_width = win_width;
		}
		if( canvas_height_org > win_height){
			canvas_height = win_height;
		}
		
		jq_canvas.width(canvas_width);
		jq_canvas.height(canvas_height);
		jq_canvas.attr("width", canvas_width);
		jq_canvas.attr("height", canvas_height);

		canvas_left = jq_canvas.offset().left;
		canvas_top = jq_canvas.offset().top;
	}
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console