Skip to content

Instantly share code, notes, and snippets.

@tsak
Last active May 21, 2020 07:17
Show Gist options
  • Save tsak/70c6d8db0222531d00d3d5f15c722c55 to your computer and use it in GitHub Desktop.
Save tsak/70c6d8db0222531d00d3d5f15c722c55 to your computer and use it in GitHub Desktop.
Source of https://draw.tsak.net/drawer.swf. This draws a painting app and then lets the user draw a painting and send the movements to the backend.
movie 'drawer.swf' {
// flash 6, total frames: 1, frame rate: 12 fps, 640x480 px, compressed
frame 1 {
function pushSave(action) {
_root.picture.pic.push(action + '#');
}
colDist = 10;
colWidth = 8;
lineWidth = 1;
actCol = 0;
picture = new LoadVars();
picture.pic = new Array();
hex = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
_root.createEmptyMovieClip('drawingBoard', 1);
with (drawingBoard) {
lineStyle(1, 0, 100);
moveTo(1, 1);
lineTo(639, 1);
lineTo(639, 479);
lineTo(1, 479);
lineTo(1, 1);
moveTo(58, 1);
lineTo(58, 479);
c = 0;
d = 1;
i = 1;
while (i <= 64) {
if (i == 1) {
this_col = '0x000000';
} else {
if (i == 2) {
this_col = '0xFFFFFF';
} else {
this_col = '0x' + hex[Math.round(Math.random() * 15)] + hex[Math.round(Math.random() * 15)] + hex[Math.round(Math.random() * 15)] + hex[Math.round(Math.random() * 15)] + hex[Math.round(Math.random() * 15)] + hex[Math.round(Math.random() * 15)];
}
}
++c;
++e;
createEmptyMovieClip('colsel' + i, e);
this_colMC = eval('colsel' + i);
with (this_colMC) {
lineStyle(1, 0, 100);
beginFill(this_col);
moveTo(c * colDist, d * colDist);
lineTo(c * colDist + colWidth, d * colDist);
lineTo(c * colDist + colWidth, d * colDist + colWidth);
lineTo(c * colDist, d * colDist + colWidth);
lineTo(c * colDist, d * colDist);
endFill();
}
this_colMC.col = this_col;
this_colMC.onPress = function () {
_root.drawingBoard.paper.lineStyle(_root.lineWidth, this.col);
_root.actCol = this.col;
_root.pushSave('s_' + _root.lineWidth + '_' + this.col);
};
if (c > 3) {
c = 0;
++d;
}
++i;
}
i = 1;
while (i < 10) {
createEmptyMovieClip('line' + i, i + e);
this_linMC = eval('line' + i);
with (this_linMC) {
lineStyle(1, 0, 100);
beginFill(16777215);
moveTo(10, i * 20 + 202);
lineTo(50, i * 20 + 202);
lineTo(50, i * 20 + 218);
lineTo(10, i * 20 + 218);
lineTo(10, i * 20 + 202);
endFill();
lineStyle(i, 0, 100);
moveTo(12 + i, i * 20 + 210);
lineTo(48 - i, i * 20 + 210);
}
this_linMC.line = i;
this_linMC.onPress = function () {
_root.drawingBoard.paper.lineStyle(this.line, _root.actCol);
_root.lineWidth = this.line;
_root.pushSave('s_' + this.line + '_' + _root.actCol);
};
++i;
}
createEmptyMovieClip('saveButton', i + e + 3);
with (saveButton) {
lineStyle(1, 0, 100);
beginFill(16777215);
moveTo(10, 460);
lineTo(50, 460);
lineTo(50, 470);
lineTo(10, 470);
lineTo(10, 460);
endFill();
createTextField('mytext', 1, 10, 456, 40, 20);
with (mytext) {
multiline = false;
wordWrap = false;
border = false;
selectable = false;
text = 'save';
}
myformat = new TextFormat();
with (myformat) {
color = 0;
bullet = false;
bold = true;
underline = false;
font = 'Arial';
size = 11;
align = 'center';
}
mytext.setTextFormat(myformat);
}
saveButton.onPress = function () {
_root.picture.send(_root.host + 'index.php', '', 'POST');
};
createEmptyMovieClip('clearButton', i + e + 4);
with (clearButton) {
lineStyle(1, 0, 100);
beginFill(16777215);
moveTo(10, 440);
lineTo(50, 440);
lineTo(50, 450);
lineTo(10, 450);
lineTo(10, 440);
endFill();
createTextField('mytext', 1, 10, 436, 40, 20);
with (mytext) {
multiline = false;
wordWrap = false;
border = false;
selectable = false;
text = 'clear';
}
myformat = new TextFormat();
with (myformat) {
color = 0;
bullet = false;
bold = true;
underline = false;
font = 'Arial';
size = 11;
align = 'center';
}
mytext.setTextFormat(myformat);
}
clearButton.onPress = function () {
getURL('index.php?mode=draw');
};
createEmptyMovieClip('paperMask', i + e + 2);
with (paperMask) {
lineStyle(1, 16777215, 0);
beginFill(16711680);
moveTo(59, 2);
lineTo(639, 2);
lineTo(639, 479);
lineTo(59, 479);
lineTo(59, 2);
}
createEmptyMovieClip('paper', i + e + 1);
paper.lineStyle(1, 0, 100);
_root.pushSave('s_1_0x000000');
paper.setMask(paperMask);
}
myListener = new Object();
myListener.onMouseDown = function () {
_root.drawingBoard.paper.moveTo(_root.drawingBoard.paper._xmouse, _root.drawingBoard.paper._ymouse);
_root.pushSave('m_' + _root.drawingBoard.paper._xmouse + '_' + _root.drawingBoard.paper._ymouse);
_root.drawing = true;
};
myListener.onMouseMove = function () {
if (_root.drawing) {
_root.drawingBoard.paper.lineTo(_root.drawingBoard.paper._xmouse, _root.drawingBoard.paper._ymouse);
_root.pushSave('l_' + _root.drawingBoard.paper._xmouse + '_' + _root.drawingBoard.paper._ymouse);
}
};
myListener.onMouseUp = function () {
_root.drawing = false;
};
Mouse.addListener(myListener);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment