فيديو المحاضرة
فيديو المحاضرة
بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.
رسوم متحركة
أمثلة كود
أمثلة قصيرة وبسيطة
كل مثال وراه زرار «شغّل خطوة بخطوة»: بيعلّم على السطر اللي بيتنفّذ ويطبع الناتج زي ما بيتنفّذ بالظبط. ده شرح تنفيذ الكود سطر بسطر، مش مترجم حقيقي جوه الصفحة.
المثال ١: خطوات الظهور التدريجي
const fps = 24, seconds = 0.5;const frames = Math.round(fps * seconds);const step = 1 / frames;console.log(frames + " frames");console.log(step.toFixed(3) + " opacity per frame");
المثال ٢: WAV ضد MP3 في الثانية
const wavBytes = 44100 * 2 * 2; // rate x channels x 2 bytesconst mp3Bytes = 128000 / 8; // 128 kbps to bytesconsole.log("WAV: " + (wavBytes / 1024).toFixed(1) + " KB/s");console.log("MP3: " + (mp3Bytes / 1024).toFixed(1) + " KB/s");console.log("ratio: " + (wavBytes / mp3Bytes).toFixed(1) + "x");
المثال ٣: الكشّاف بيغطي قد إيه؟
const stageW = 550, stageH = 400, r = 100;const spot = Math.PI * r * r;const stage = stageW * stageH;console.log((spot / stage * 100).toFixed(1) + "% of the stage");
اختبار قصير
اختبر فهمك
1. A mask effect needs at least how many layers on the timeline?
2. The spotlight effect comes from:
3. Which sound format can Flash import, per the notes?
4. Why put each sound on its own layer?
5. The main job of a special effect is to:
تمارين
جرّب بإيدك
التمرين 1
احسب عدد فريمات fade مدته 0.75 ثانية على 24 فريم في الثانية، وخطوة الـ opacity لكل فريم (3 أرقام عشرية)، واطبعهم.
Compute the frame count of a 0.75-second fade at 24 fps and the opacity step per frame (3 decimals), and print both.
Starter code:
const fps = 24, seconds = 0.75;// TODO: frames = round(fps * seconds), step = 1 / frames// TODO: print frames + " frames", then step with 3 decimals + " opacity per frame"
const fps = 24, seconds = 0.75; const frames = Math.round(fps * seconds); const step = 1 / frames; console.log(frames + " frames"); console.log(step.toFixed(3) + " opacity per frame");
Expected output
18 frames 0.056 opacity per frame
التمرين 2
اكتب دالة wavKBps(channels, rate) بترجّع الكيلوبايت في الثانية لصوت WAV خام 16-bit (رقمين عشريين)، واطبع wavKBps(2, 44100).
Write wavKBps(channels, rate) returning KB/s of raw 16-bit WAV (2 decimals), and print wavKBps(2, 44100).
Starter code:
function wavKBps(channels, rate) { // TODO: bytes per second = rate * channels * 2, return KB with 2 decimals}console.log(wavKBps(2, 44100) + " KB/s");
function wavKBps(channels, rate) {
const bytes = rate * channels * 2;
return (bytes / 1024).toFixed(2);
}
console.log(wavKBps(2, 44100) + " KB/s");
Expected output
172.27 KB/s
مشروع صغير في آخر المحاضرة
كشّاف بيلف على المسرح
الداتا: stage-550x400: مسرح من عندنا 550x400، وكشّاف دايرة نصف قطرها 100 بيمشي على خط أفقي.
License / source: Our own stage; Canvas clip() reference by MDN (link only, nothing copied). Reference page
الخطوات
- اعمل مسرح 550 في 400، ودايرة نصف قطرها 100 هي شبّاك الماسك.
- حرّك مركز الدايرة من x=100 لحد x=450 بخطوة 50، واحسب نسبة التغطية.
- اطبع كل موضع، وفي الآخر اطبع النسبة المئوية اللي الدايرة بتغطيها من المسرح.
Starter code:
const stageW = 550, stageH = 400, r = 100;// TODO: loop cx from 100 to 450 step 50 and print each center// TODO: print coverage = PI * r * r / (stageW * stageH) as a percent, 1 decimal
const stageW = 550, stageH = 400, r = 100;
for (let cx = 100; cx <= 450; cx += 50) {
console.log("spotlight at x=" + cx);
}
const cover = Math.PI * r * r / (stageW * stageH) * 100;
console.log("covers " + cover.toFixed(1) + "% of the stage");
Expected output
spotlight at x=100 spotlight at x=150 spotlight at x=200 spotlight at x=250 spotlight at x=300 spotlight at x=350 spotlight at x=400 spotlight at x=450 covers 14.3% of the stage
Credits: the topic order follows the course notes "Multimedia and Computer Graphics" by Dr. Muhammad Kashif Saeed (Applied College, Muhayil, King Khalid University), shared by the course owner. The explanations, diagrams, data and code in this lecture are our own; we copy nothing from the notes. Extra reference: Multimedia and Computer Graphics notes, Dr. Muhammad Kashif Saeed, King Khalid University (elc.kku.edu.sa) - own text, structure follows the notes.