الرئيسية / مقرر الوسائط المتعددة / الفصل 2 الجزء 1

الفصل 2 (الجزء 1): Special effects: layers, masks and sound

Why effects, the mask layer and spotlight, and adding sound - with the modern canvas equivalent

على طول: المؤثرات الخاصة بتضيف إيه، وإيه هي طبقة الماسك والسبوت لايت، وإزاي الصوت بيتضاف، وإزاي نفس الأفكار بتتعمل بـ canvas النهاردة.

فيديو المحاضرة

فيديو المحاضرة

بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.

رسوم متحركة

الماسك والسبوت لايت

أمثلة كود

أمثلة قصيرة وبسيطة

كل مثال وراه زرار «شغّل خطوة بخطوة»: بيعلّم على السطر اللي بيتنفّذ ويطبع الناتج زي ما بيتنفّذ بالظبط. ده شرح تنفيذ الكود سطر بسطر، مش مترجم حقيقي جوه الصفحة.

المثال ١: خطوات الظهور التدريجي

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"

التمرين 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");

مشروع صغير في آخر المحاضرة

كشّاف بيلف على المسرح

الداتا: stage-550x400: مسرح من عندنا 550x400، وكشّاف دايرة نصف قطرها 100 بيمشي على خط أفقي.

License / source: Our own stage; Canvas clip() reference by MDN (link only, nothing copied). Reference page

الخطوات

  1. اعمل مسرح 550 في 400، ودايرة نصف قطرها 100 هي شبّاك الماسك.
  2. حرّك مركز الدايرة من x=100 لحد x=450 بخطوة 50، واحسب نسبة التغطية.
  3. اطبع كل موضع، وفي الآخر اطبع النسبة المئوية اللي الدايرة بتغطيها من المسرح.

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

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.