The egg hurts, JavaScript version badapple

Source: Internet
Author: User

Refer to the VIM version of the BadApple rewrite. Due to the large load data, may not be the speed of the children's shoes effect is not very good, more than a few times to refresh the good, ^_^.
Operating environment: Supports HTML5 Canvas browser.
? 1. Code:
$ (function () {
var badapple = {
Is_running:false,
data_index:0,
Data_count:67,
Is_loading: {},
Progress: $ (' #progress '),
Init:function () {
var me = this,
Stage = $ (' #stage '),
I

Me.data_matrix = [];
for (i = 0; i < Me.frame_row; ++i) {
Me.data_matrix[i] = Array (me.frame_col). Join ('). Split (');
}

Me.canvas = stage.get (0);
Me.ctx = Me.canvas.getContext (' 2d ');
Me.canvas.width = Me.frame_col * 7;
Me.canvas.height = Me.frame_row * 16;

Me.ctx.fillStyle = ' Rgba (0, 0, 0,. 05) ';
Me.ctx.fillRect (0, 0, me.canvas.width, me.canvas.height);
Me.ctx.fillStyle = ' #7E7E7E ';
Me.ctx.font = ' 12px monospace ';
},
Load_data:function (index, Count, FN) {
var me = this;
if (!me.is_loading[index]) {
Mark is loading
Me.is_loading[index] = true;
$.get (' Data/badapple/data_ ' + index + '. txt ', function (data) {
Finish loading
Me.is_loading[index] = null;
Me.data_index = index;
data = Data.split (' \ n ');
Update progress
Me.progress.html ((Index/me.data_count *). ToFixed (2) + '% ');

if (me.data) {
Me.data = Me.data.concat (data);
}
First time
else {
Me.data = data;
var rc = Data[0].split (");
Me.frame_row = parseint (rc[0]);
Me.frame_col = parseint (rc[1]);
$ (' #div_loading '). Remove ();
Me.init ();
}

if (Count > 1 && Index < me.data_count) {
Me.load_data (index + 1, count-1, FN);
}
else {
fn && fn ();
}
});
}
},
Draw_frame:function (data) {
var me = this, I;
for (i = 0; i < data.length; ++i) {
ME.DATA_MATRIX[DATA[I][0]-1][data[i][1]-1] = data[i][2];
}http://www.huiyi8.com/jianbihua/?
Me.ctx.clearRect (0, 0, me.canvas.width, me.canvas.height);
for (i = 0; i < Me.frame_row; ++i) {
Me.ctx.fillText (Me.data_matrix[i].join ("), 4, I * 14 + 16);
} Simple Strokes Daquan
},
Play:function () {
var me = this,
i = 0,
J
L
R
Me.is_running = true;
Me.interval | | (Me.interval = setinterval () (function () {
if (me.is_running && i < me.data.length) {
L = me.data[++i];
r = [];
if (l &&!/^\s*$/.test (l)) {
L = l.split (' | ');
for (j = 0; j < l.length; ++j) {
R[J] = L[j].split ('_');
}
}
Me.draw_frame (R);
Load data
if (i + > Me.data_index * &&
Me.data_index < Me.data_count) {
Me.load_data (Me.data_index + 1, 2);
}
}
}, 70));
},
Start:function () {
var me = this;
if (me.data) {
Me.play ();
}
else {
Me.load_data (0, 1, function () {
Me.play ();
});
}
},
Stop:function () {
This.is_running = false;
},
Terminal:function () {
This.stop ();
Clearinterval (This.interval);
}
};

$ (' #stage '). Click (function () {
Badapple.is_running?
Badapple.stop ():
Badapple.start ();
}). click ();
});
??

The egg hurts, JavaScript version badapple

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.