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

            
              body {
  position: fixed;
  top: 0px;
  left: 0px;
  right: 0px;
  display: block;
  margin: 0;
  padding: 0;
  bottom: 0px;
}
            
          
!
            
              ;(function(){
	var SPACE = 50;
	var SPEED = 20;
	var COLOR = '#B5EAE1';

	var target = document.getElementById('two-js-lab');
	var two;
	var stage_width = document.body.clientWidth;
	var stage_height = document.body.clientHeight;
	var col_line_arr = new Array;
	var row_line_arr = new Array;
	var params = {
		width : stage_width,
		height: stage_height
	};
	/*
	 * Line
	 */
	var Line = function(position,type) {
		var x1,x2,y1,y2;
		if (type === 'col') {
			// 縦
			this.x1 = this.x2 = position;
			this.y1 = this.point = position * -1;
			this.y2 = 0;
			// this.y2 = stage_height;
			this.end = stage_height;
		} else {
			// 横
			this.y1 = this.y2 = position;
			this.x1 = this.point = position * -1;
			this.x2 = 0;
			// this.x2 = stage_width;
			this.end = stage_width;
		}
		this.type = type;
		this.two = two.makeLine(this.x1, this.y1, this.x2, this.y2);
	};

	Line.prototype.drow = function() {
		this.point += SPEED;
		if (this.type === 'col') {
			this.y2 = this.point;
		} else {
			this.x2 = this.point;
		}
		this.two = two.makeLine(this.x1, this.y1, this.x2, this.y2);
	};

	/*
	 * initialize
	 */
	var initialize = function() {
		two = new Two(params).appendTo(target);
		col_line_set(SPACE);
		row_line_set(SPACE);
		
		two.bind('update',function() {
			two.clear();
			for (var i = 0; i < col_line_arr.length; i++) {
				col_line_arr[i].drow();
				col_line_arr[i].two.stroke = COLOR;
			}
			for (var i = 0; i < row_line_arr.length; i++) {
				row_line_arr[i].drow();
				row_line_arr[i].two.stroke = COLOR;
			}
			anime_ctrl();
		}).play();
	};
	var anime_ctrl = function() {
		var col_end = col_line_arr[col_line_arr.length-1].point;
		var row_end = row_line_arr[row_line_arr.length-1].point;
		if (col_end >= stage_height && row_end >= stage_width) {
			two.pause();
			two.unbind('update');
		}
	}
	/*
	 * col_line_set : 縦ライン
	 */
	var col_line_set = function(add_space) {
		add_space += 2;
		var line = new Line((add_space/2), 'col');
		col_line_arr.push(line);
		if ((add_space/2) <= stage_width) {
			col_line_set(add_space + SPACE);
		}
	};

	/*
	 * row_line_set - 横ライン
	 */
	var row_line_set = function(add_space) {
		add_space += 2;
		var line = new Line((add_space/2), 'row');
		row_line_arr.push(line);
		if ((add_space/2) <= stage_height) {
			row_line_set(add_space + SPACE);
		}
	};
	initialize();
})()
            
          
!
999px
Loading ..................

Console