Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite رسم extension to work from a web worker
- Loading branch information
Showing
3 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
var canvas = document.createElement("canvas") | ||
document.body.appendChild(canvas); | ||
|
||
var Rasm = null; | ||
|
||
interpreter["رسم:ابدأ-رسم"] = function(args) { | ||
Rasm = new Processing(canvas); | ||
Rasm.size(args.w, args.h); | ||
Rasm.background(255, 255, 255) | ||
} | ||
|
||
interpreter["رسم:خط"] = function(args) { | ||
Rasm.line(args.x1, args.y1, args.x2, args.y2); | ||
} | ||
|
||
interpreter["رسم:نقطة"] = function(args) { | ||
Rasm.point(args.x, args.y); | ||
} | ||
|
||
interpreter["رسم:إهليلج"] = function(args) { | ||
Rasm.ellipse(args.x, args.y, args.w, args.h); | ||
} | ||
|
||
interpreter["رسم:دائرة"] = function(args) { | ||
Rasm.ellipse(args.x, args.y, args.r, args.r); | ||
} | ||
|
||
interpreter["رسم:مستطيل"] = function(args) { | ||
Rasm.rect(args.x, args.y, args.w, args.h); | ||
} | ||
|
||
interpreter["رسم:مربع"] = function(args) { | ||
Rasm.rect(args.x, args.y, args.s, args.s); | ||
} | ||
|
||
interpreter["رسم:ضجة"] = function(args) { | ||
Rasm.noise(args.r, args.g, args.b); | ||
} | ||
|
||
interpreter["رسم:تحجيم"] = function(args) { | ||
Rasm.scale(args.x, args.y, args.z); | ||
} | ||
|
||
interpreter["رسم:انزلاق"] = function(args) { | ||
Rasm.translate(args.x, args.y, args.z); | ||
} | ||
|
||
interpreter["رسم:دوران"] = function(args) { | ||
Rasm.rotate(args.x, args.y, args.z); | ||
} | ||
|
||
interpreter["رسم:لون"] = function(args) { | ||
Rasm.color(args.r, args.g, args.b); | ||
} | ||
|
||
interpreter["رسم:خلفية"] = function(args) { | ||
Rasm.background(args.r, args.g, args.b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var stubs = [ | ||
{ name: "ابدأ-رسم", params: ['w', 'h'] }, | ||
{ name: "خط", params: ['x1', 'y1', 'x2', 'y2'] }, | ||
{ name: "نقطة", params: ["x", "y"] }, | ||
{ name: "إهليلج", params: ["x", "y", "w", "h"] }, | ||
{ name: "دائرة", params: ["x", "y", "r"] }, | ||
{ name: "مستطيل", params: ["x", "y", "w", "h"] }, | ||
{ name: "مربع", params: ["x", "y", "s"] }, | ||
{ name: "ضجة", params: ["r", "g", "b"] }, | ||
{ name: "تحجيم", params: ["x", "y", "z"] }, | ||
{ name: "انزلاق", params: ["x", "y", "z"] }, | ||
{ name: "دوران", params: ["x", "y", "z"] }, | ||
{ name: "لون", params: ["r", "g", "b"] }, | ||
{ name: "خلفية", params: ["r", "g", "b"] } | ||
] | ||
|
||
var workerMethods = {} | ||
|
||
stubs.forEach(function(m) { | ||
workerMethods[m.name] = function() { | ||
var data = {} | ||
for (var i = 0; i < m.params.length; i++) | ||
data[m.params[i]] = arguments[i]; | ||
postMessage({type: "رسم:" + m.name, data: data}) | ||
} | ||
}); | ||
|
||
workerMethods["ارسم"] = function(fn) { | ||
setInterval(fn, 1000); | ||
} | ||
|
||
Qlb.globalEnvironment.merge(workerMethods); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters