cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

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
Loading ..................

Console