-
Notifications
You must be signed in to change notification settings - Fork 0
/
frame-transitions.js
151 lines (136 loc) · 3.97 KB
/
frame-transitions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
load("sbbsdefs.js");
// Make transparent the parts of a frame that match a given char and attr
// By using `data_width` and `data_height`, we ensure we mask ALL characters,
// even those which are outside the bounds of the frame.
function maskFrame(theFrame,maskChar,maskAttr) {
var x, y, xl, yl;
xl = theFrame.data_width;
yl = theFrame.data_height;
for (x=0; x<xl; x++) {
for (y=0; y<yl; y++) {
var theChar = theFrame.getData(x,y);
// If this character matches, then delete the character attributes
// in order to make it act as transparent.
if (theChar.ch == maskChar && theChar.attr == maskAttr) {
// theFrame.setData(x,y,undefined,undefined);
theFrame.clearData(x,y);
}
}
}
}
// Make frame completely transparent
function emptyFrame(theFrame) {
var x, y, xl, yl;
xl = theFrame.width;
for (x=0; x<xl; x++) {
yl = theFrame.height;
for (y=0; y<yl; y++) {
// theFrame.setData(x,y,undefined,undefined);
theFrame.clearData(x,y);
}
}
}
// Fill an empty frame with particular character
function fillFrame(theFrame,theChar,theAttr) {
var x, y, xl, yl;
xl = theFrame.width;
for (x=0; x<xl; x++) {
yl = theFrame.height;
for (y=0; y<yl; y++) {
theFrame.setData(x,y,theChar,theAtrr)
}
}
}
// Dissolve entire frame
function dissolve(theFrame,color,delay) {
if (typeof(color) === "undefined") { color = BLACK; }
if (typeof(delay) === "undefined") { delay = 1; }
var x, y, xl, yl, pixelArray = [];
xl = theFrame.width;
yl = theFrame.height;
for (x=0; x<xl; x++) {
for (y=0; y<yl; y++) {
pixelArray.push([x,y]);
}
}
while( pixelArray.length > 0 ) {
var randomIndex = Math.floor(Math.random() * pixelArray.length);
var randomPixel = pixelArray.splice(randomIndex, 1);
// ascii(219) = solid block; 5 = Magenta
theFrame.setData(randomPixel[0][0],randomPixel[0][1],ascii(219),color);
theFrame.cycle();
// cycle sprites if there are any, so they remain on top layer.
if (typeof Sprite !== 'undefined') {
Sprite.cycle();
}
if (delay > 0) {
mswait(delay);
}
}
}
//Dissolve, wiping down from top
function wipeDown(theFrame,wipeSize,color,delay) {
if (typeof(wipeSize) === "undefined") { wipeSize = 2; }
if (typeof(color) === "undefined") { color = BLACK; }
if (typeof(delay) === "undefined") { delay = 1; }
var x, y, xl, yl, p, pixelArray = [];
xl = theFrame.width;
yl = theFrame.height;
for (y=0; y<yl; y+=wipeSize) {
for (p=0;p<wipeSize; p++) {
pixelArray[p] = [];
for (x=0; x<xl; x++) {
pixelArray[p].push(x);
}
}
while( pixelArray[0].length > 0 ) {
for (p=0;p<wipeSize; p++) {
var randomIndex = Math.floor(Math.random() * pixelArray[p].length);
var randomPixel = pixelArray[p].splice(randomIndex, 1);
// ascii(219) = solid block; 5 = Magenta
theFrame.setData(randomPixel,y+p,ascii(219),color);
theFrame.cycle();
// cycle sprites if there are any, so they remain on top layer.
if (typeof Sprite !== 'undefined') {
Sprite.cycle();
}
if (delay > 0) {
mswait(delay);
}
}
}
}
}
//Dissolve, wiping right from left
function wipeRight(theFrame,wipeSize,color,delay) {
if (typeof(wipeSize) === "undefined") { wipeSize = 5; }
if (typeof(color) === "undefined") { color = BLACK; }
if (typeof(delay) === "undefined") { delay = 1; }
var x, y, xl, yl, p, pixelArray = [];
xl = theFrame.width;
yl = theFrame.height;
for (x=0; x<xl; x+=wipeSize) {
for (p=0;p<wipeSize; p++) {
pixelArray[p] = [];
for (y=0; y<yl; y++) {
pixelArray[p].push(y);
}
}
while( pixelArray[0].length > 0 ) {
for (p=0;p<wipeSize; p++) {
var randomIndex = Math.floor(Math.random() * pixelArray[p].length);
var randomPixel = pixelArray[p].splice(randomIndex, 1);
// ascii(219) = solid block; 5 = Magenta
theFrame.setData(x+p,randomPixel,ascii(219),color);
theFrame.cycle();
// cycle sprites if there are any, so they remain on top layer.
if (typeof Sprite !== 'undefined') {
Sprite.cycle();
}
if (delay > 0) {
mswait(delay);
}
}
}
}
}