رمز الصورة في هذا القسم ، سننظر في شفرة بسيطة لتحميل ومعالجة صورة رقمية. سنقوم هنا بمعالجة بكسل واحد في المرة الواحدة. في القسم التالي ، قم بالارتقاء للعمل على آلاف البكسل في وقت واحد. x.png x.png - صورة مثال صغيرة (10 × 10) تنسيق PNG ، مثل JPG صورة "x.png" بسيطة للغاية - إنها مربع أسود صغير جدًا مع وجود علامة "x" بيضاء في وسطها. PNG (رسومات الشبكة المحمولة) عبارة عن تنسيق للصور ، مثل JPG. هنا هو x.png: مثال رمز x.png برنامج ثلاثة خط image = new SimpleImage ("x.png") ؛ - تحميل إلى متغير image.setZoom (20)؛ - اضبط خيار التكبير / التصغير على 20 (10 ، 20 ، 30 ، ... أيا كان) طباعة (صورة)؛ - طباعة الصورة إلى اليمين ، كالعادة التكبير: كل بكسل يظهر حجم 20x هنا يقوم المثال الأول لرمز الصورة بتحميل الصورة x.png وطباعتها. قم بتشغيل الكود لمعرفة ما يفعله. حاول تغيير image.setZoom (20) لاستخدام الرقم 10 أو 30 بدلاً من ذلك. image = new SimpleImage ("x.png") ؛ image.setZoom (20)؛ طباعة (صورة)؛ pixel.setRed (255) مثال pixel = image.getPixel (0، 0)؛ - بكسل اليسار العلوي pixel.setRed (255)؛ - تعيين القيمة الحمراء لهذا بكسل image = new SimpleImage ("x.png") ؛ image.setZoom (20)؛ pixel = image.getPixel (0، 0)؛ pixel.setRed (255)؛ طباعة (صورة)؛ مجموعة بكسل الأحمر / الأخضر / الأزرق وظائف pixel.setRed (عدد)؛ - قم بتعيين القيمة الحمراء للبكسل ليكون الرقم المحدد (0.55) pixel.setGreen (عدد)؛ - ضبط القيمة الخضراء pixel.setBlue (عدد)؛ - ضبط القيمة الزرقاء جانبا: مرجع وظائف الصورة للرجوع إليها لاحقًا ، هناك صفحة مرجعية لوظائف الصور منفصلة تسرد في مكان واحد وظائف الصورة مثل pixel.setRed (عدد) نحن نستخدم هنا. التجارب على بكسل (0 ، 0) لنرى كيف image.getPixel (x، y) و pixel.setRed (عدد) وما إلى ذلك العمل ، سنحاول التجارب المذكورة أدناه (استخدم زر "عرض" لرؤية رمز الحل). image = new SimpleImage ("x.png") ؛ image.setZoom (20)؛ pixel = image.getPixel (0، 0)؛ pixel.setRed (255)؛ طباعة (صورة)؛ مثال لحل المشاكل اضبط البكسل (0 ، 0) ليصبح لونه أخضر. تبين اضبط البكسل (0 ، 0) ليكون أصفر. تبين اضبط البكسل (1 ، 0) ليكون أصفر. أين هو هذا بكسل؟ تبين اضبط البيكسل (0 ، 0) على اللون الأبيض. تبين اضبط البيكسل (0 ، 0) لتكون صفراء داكنة - اضبط الألوان اللازمة على 150 بدلاً من 255. إظهار اضبط البيكسل (0 ، 0) ليكون أحمر فاتحًا. تبين Image Code In this section, we'll look at simple code to load and manipulate a digital image. Here we'll just manipulate one pixel at a time. In the next section, scaling up to operate on thousands of pixels at a time. x.png x.png -- tiny example image (10 x 10) PNG format, like JPG The image "x.png" is very simple -- it's a very small black square with a white "x" at its center. PNG (Portable Network Graphics) is a image format, like JPG. Here is x.png: x.png Code Example Three line program image = new SimpleImage("x.png"); -- load into variable image.setZoom(20); -- set zoom option to 20 (10, 20, 30, ... whatever) print(image); -- print image to the right, as usual Zoom: each pixel shown 20x size here Our first image code example loads the x.png image and prints it. Run the code to see what it does. Try changing the image.setZoom(20) to use the number 10 or 30 instead. image = new SimpleImage("x.png"); image.setZoom(20); print(image); pixel.setRed(255) Example pixel = image.getPixel(0, 0); -- upper left pixel pixel.setRed(255); -- set red value of that pixel image = new SimpleImage("x.png"); image.setZoom(20); pixel = image.getPixel(0, 0); pixel.setRed(255); print(image); Pixel Set Red/Green/Blue Functions pixel.setRed(number); -- set the red value of the pixel to be the given number (0..255) pixel.setGreen(number); -- set the green value pixel.setBlue(number); -- set the blue value Aside: Image Functions Reference For later reference, there is a separate image functions reference page which lists in one place the image functions such as pixel.setRed(number) we are using here. Experiments On Pixel (0, 0) To see how image.getPixel(x, y) and pixel.setRed(number) etc. work, we'll try the experiments listed below (use the "show" button to see the solution code). image = new SimpleImage("x.png"); image.setZoom(20); pixel = image.getPixel(0, 0); pixel.setRed(255); print(image); Example Problems Solution Set pixel (0, 0) to be green. show Set pixel (0, 0) to be yellow. show Set pixel (1, 0) to be yellow. Where is that pixel? show Set pixel (0, 0) to white. show Set pixel (0, 0) to be dark yellow -- set the necessary colors to 150 instead of 255. show Set pixel (0, 0) to be a light, pastel red. Show ونرى أنه في الواقع ، عشرة بكسل في عشرة بكسل. ويتم عرضها هنا في حجم 20x. في الواقع يمكنني تغيير هذا الرقم هنا. لذلك إذا قمت بتغيير هذا إلى عشرة ، ثم قم بتشغيلها مرة أخرى ثم حسنا ، حسنا ، الآن 20X فقط. وإذا وضعت مثل ، a ، 40 هنا ، وقم بتشغيله ، ثم حسنًا ، أكبر كثيرًا. لذلك سوف أعيدها إلى عشرون. هذا مجرد مثال أول على القليل من الكود ، لكننا نوع من السير في طريق القدرة على تحميل ومعالجة الصور. حسناً لجعل هذا أكثر إثارة للاهتمام قليلا. أريد تمديد الشفرة لتكون قادرًا على التعامل مع وحدات بكسل فردية ، فأنا أضع خطوطًا في منتصف الصورة البرنامج هنا ، لذلك هذا الخط بكسل = image.getPixel (0،0). ما هذا هل يذهب إلى الصورة وسيحصل على إشارة إلى بكسل معين أيا كان ، كلما كانت إحداثيات س ، ص نحدد هنا 0،0 أو يشير هذا إلى ، بكسل اليسار العلوي ، لذلك يحصل على إشارة إلى بكسل اليسار العلوي ويخزن ذلك في بكسل متغير ثم هذا السطر: pixel.setRed (255). الذي يستدعي وظيفة وقد دعا بكسل setRed وماذا ، ما يفعله setRed هو أنه يأخذ في أي رقم هنا بين قوسين ومهما كان هذا الرقم ، فإنه يأخذ ويضع القيمة الحمراء للبكسل ليكون هذا الرقم. لذلك ، سأعمل على هذا. نحن بحاجة لرؤية ماذا يفعل. وما تراه هو ، ما حصل عليه الكود هو الحصول على مرجع إلى هذا ، بكسل اليسار العلوي وكان أسود من قبل ، وتذكر ، تذكر يحتوي كل بكسل على الأرقام الثلاثة فيه ، الأحمر والأخضر والأزرق. وما هذا رمز يفعل ، ذهب إلى الرقم الأحمر وتغير إلى 255 ، مجرد تجاوز كل ما كان هناك من قبل. لذلك عندما نراها ، حسناً ، تظهر في صورة بكسل أحمر ، وبالتالي. هناك setRed لتغيير القيم الحمراء. هناك وظيفة مماثلة setGreen و setBlue. لذلك ، لدينا هذه الثلاثة ، setRed ، setGreen و setBlue. وهكذا ، مع هؤلاء ، يمكننا فقط تغيير القيم الحمراء والخضراء والزرقاء أيا كان ، أينما نريد. وبالتالي. أوه ، وسأذكرها جانباً لذا أنا ، أنا فقط ، كما تعلمون ، قدمت ثلاث وظائف. هناك هذه الصفحة منفصلة ، مرجع وظائف الصورة ، الذي يسرد فقط جميع الوظائف في الجدول ، وذلك بالنسبة للبعض في وقت لاحق التمرين ، قد تريد ، يمكنك أن ترى أنه إذا كنت تريد أن تتذكر ما وظيفة لا. ولكن عادةً بالنسبة للمحاضرات ، سأستخدم فقط ، إذا كنت سأستخدم وظيفة أنا فقط ، وأنا ذاهب سأتحدث عن ذلك. لذلك ، ما أريد القيام به ل شرح كيف ، كيف تعمل هذه الوظائف ، هو مجرد الذهاب من خلال مجموعة من الأمثلة. مجرد استخدامها لفعل شيء في الواقع. حسنا ، لذلك هنا ، وبالتالي ، فإن الشكل من هذا أنا عندي ، منطقة كود صغيرة هنا مع بعض الرموز المبدئية فيها. و ثم في هذا الجدول هنا ، لقد سردت مجموعة من التحديات الصغيرة مشاكل ، مثل ، أوه ، تعيين شيء ما ليكون أخضر أو أصفر أو أيا كان ، وسوف نذهب من خلالهم. لكل واحد من هذه ، على الجانب الأيمن هناك القليل زر العرض ، حتى تتمكن من النقر فوق ذلك لرؤية رمز الحل. في وقت لاحق يمكنك الذهاب إلى هذه الصفحة بنفسك والتجارب التي جربتها ، يمكنك فقط تجربة نفسك و حاول الاختلافات منهم أو أيا كان. حسنا ، لذلك دعونا نجرب هذا أول واحد. حسنا في الواقع ، هنا ، سوف أقوم بتشغيل الكود أولاً لمعرفة ما الذي يفعله. حسنًا ، صحيح الآن أصبح الأمر مجرد الحصول على بكسل (0،0) وتعيينه إلى اللون الأحمر. لذلك ، نوع من المشاهدة أنه قبل. حسنًا ، إذن ما المشكلة الأولى التي تقول؟ اضبط البكسل (0،0) ليكون أخضر. لذا فإن النموذج هنا ، باللغة الإنجليزية ، سيقول ، حسنًا ، إليكم بعض التأثيرات مثلك للحصول على ومعنى الخطوات التي نمر بها هنا للتفكير حسنا ، ماذا سيكون في مجال التعليمات البرمجية ، من حيث المكالمات وظيفة والأرقام. ما هي سلسلة العمليات التي نريد القيام بها لتحقيق هذا التأثير؟ لذلك أنت لطيف ترجمة أساسا من الإنجليزية إلى الكمبيوتر. لذلك في هذه الحالة يقال ليتم تعيين الأخضر. فما أريد القيام به للقيام بذلك ، هو بدلاً من استدعاء setRed وظيفة ، أنا فقط تغييره لاستدعاء setGreen. لذلك دعونا نجرب ذلك. وها نحن نذهب. يجب أن نحصل على بكسل أخضر بدلاً من ذلك. دعونا نحاول واحد القادم. التالي يقول تعيين بكسل (0،0) ليكون أصفر. حسنًا ، حسنًا ، لكي يظهر البيكسل الأصفر ، ما أريده هو أن تكون كل من القيم الحمراء والخضراء 255. أنت تعرف ، الأصفر يساوي الأحمر زائد الأخضر. للقيام بذلك ، لتغيير كل من الأحمر و أخضر. سأعمل على نسخ هذا السطر ، وسألصقه هنا. وسوف أتغير فقط هذا واحد إلى اللون الأحمر. لذلك ، أنا أعتمد على حقيقة أنه بمجرد الحصول على المرجع إلى بكسل ، يمكنني أن أفعل أشياء متعددة لذلك. لذلك ، على ، في هذا السطر الأول ، أدعو setRed ، أقوم بتغيير القيمة الحمراء. وبعد ذلك يمكنني الاتصال setGreen في السطر التالي إلى تغيير الأخضر. وسوف ، سوف يمر الكود ويقوم بكل واحد من هؤلاء الأشياء داخليا. لذلك دعونا نجرب ذلك. وبالتأكيد ، الآن أحصل على اللون الأصفر. لذلك أنا ، هذا kinda يعود إلى فكرة أن هناك هذا بكسل. انها حقا كان مجرد هذه الأرقام الثلاثة هنا. وهنا أنا أكتب رمز سطر بسطر للوصول كيندا في هناك وتغيير هذه الأرقام. دعونا نحاول واحد القادم. اضبط البكسل 1،0 ليكون الأصفر. أين هو هذا بكسل؟ and see it is in fact, ten pixels by ten pixels. And it's being displayed here at 20x size. So actually I could change this number here. So if I change this to a ten, and then run it again then okay, well, now it's only 20X. And if I put like, a, a 40 here, and run it, then okay, it a lot bigger. So I'll put it back to twenty. So that's just a first example of a little bit of code, but we're sort of going down the path of being able to load and manipulate images. Right, so to make this a little more interesting. I wanna extend the code to be able to deal with individual pixels so I'm a add a, a couple lines in the middle of the a program here, so this line pixel=image.getPixel(0,0). What that does it goes to the image and its gonna get a reference to a particular pixel whatever, whenever x, y coordinates we specify here so 0,0 or this refers to the, the upper left pixel, so it gets reference to the upper left pixel and stores that in a variable pixel and then this line: pixel.setRed(255). That calls a function a pixel has called setRed and what the, what setRed does is it takes in any number here between the parentheses and whatever that number is, it takes it in and it sets the red value of the pixel to be that number. So, I'm gonna run this. We need to see what it does. And what you see is, what the code has done is obtained a reference to this, the upper left pixel and it was black before and it, remember, recall each, each pixel has the three numbers in it, red, green and blue. And so what this code does, it went to the red number and it changed to 255, just overriding whatever was there before. So when we see it, well okay it shows up as a red pixel, so. There's a setRed to change the red values. There's an analogous function setGreen and setBlue. So, we have these three, setRed, setGreen and setBlue. And, so, with those, we can just change the red, green and blue values to be whatever, wherever we want. So. Oh, and I'll mention it as an aside so there I, I just, you know, introduced three functions. There's this separate page, Image Functions Reference, that just lists all the functions in a table, so for some later exercise, you might wanna, you can go see that if you want to remember what a function does. But usually for the lectures I will just, if I'm gonna use a function I'll just, as I'm going I'll talk about it. So, what I want to do to demonstrate how, how these functions work, is just go through a bunch of examples. Just use them to actually do something. Alright, so here are, so the, the format of this is I've got, a little code area here with some starter code in it. And then in this table down here, I've just listed a bunch of little, challenge problems, like, oh, set something to be green or yellow or whatever, and we'll go through them. For each one of these, on the right hand side there's this little show button, so you can click that to see the solution code. So later on you can go to this page yourself and the experiments I've tried you can just try yourself and try variations of them or whatever. Alright, so let's try this first one. Well actually, here, I'll, I'll run the code first to see what it does. Okay, so right now it's just getting pixel (0,0) and setting it to red. So that, sort of seen that before. Alright, so what's the first problem saying? Set pixel (0,0) to be green. So the form here, is in English, it will say, well here's some effect we'd like you to get and in sense the steps we're going through here to think about well, what would be in the domain of code, in terms of function calls and numbers. What are the series of operations we want to do to get that effect? So you're sort of translating essentially from English into computer. So in this case it's said to be set green. So what I want to do to do that, is instead of calling the setRed function, I'll just change it to call setGreen. So lets try that. And there we go. We gotta a green pixel instead. Lets try the next one. The next one says set pixel (0,0) to be yellow. So right, well so, in order for the pixel to appear yellow, what I want is for both the red and green values to be 255. You know, yellow equals red plus green. So to do that, to change both the red and the green. I'm gonna copy this line, and I'll paste it in here. And I'll just change this one to red. So, I'm, I'm relying on the fact that, once I've got the reference to pixel, I can do multiple things to it. So, on, on this first line, I call setRed, I change the red value. And then I can call setGreen on the next line to change the green. And it'll, the code will just go through and do each one of those things internally. So let's try that. And sure enough, now I get yellow. So I've, this sorta goes back to the idea that there is this pixel. It really just had these three numbers in here. And here I'm writing code line by line to kinda reach in there and change those numbers. Let's try the next one. Set pixel 1,0 to be yellow. Where is that pixel? [عزف الموسيقى] مارليسي: قبل البدء في مونولوج شكسبير أثناء اجتماع مجلس الإدارة ، من المهم التفكير حول القصص وعندما تكون مناسبة في مواقف العمل وعندما لا يكونون كذلك. لقد وجدتها مفيدة بشكل خاص لإشراك العملاء مع محتوى التسويق ، والأفكار الترويج ، وبيع نفسك ومهاراتك أثناء المقابلات أو للمستثمرين. يمكنك التفكير في بعض الأحيان عندما لا ينبغي أن تستخدم؟ سقسقة لهم لي باستخدام الهاشتاج بالطبع. قراءات هذا القسم تتحدث عن كيف مؤسسو الشركة على وجه الخصوص الاستفادة من سرد القصص لبيع المنتجات. فكر في كيفية استخدام Elizabeth Holmes لرواية القصص في إحدى الشركات للترويج لمنتج لم يكن موجودًا تمامًا. أصبحت مليارديرًا تقريبًا تعتمد على قصتها - ليس هذا أنا أدافع عن الاحتيال. ولكن ماذا لو لم يكن لديك قصة مثيرة للاهتمام بشكل خاص خاصة بك أن أقول؟ لا يهم دائما. الشيء الجميل في القصص هو أنهم في كل مكان حولنا. دعنا نراجع بعض الأماكن التي يمكننا أن ننظر فيها. المجلات والمقالات الصحفية وأخبار البث ، وهذه كلها مصادر ممتازة. العديد من المراسلين يعالجون القضايا الخطيرة من خلال العدسة الشخص الذي يتعامل مع شيء متعلق به. إنهم يناشدون تعاطفنا من خلال إعطاء الحقائق والأشكال والوجوه والأسماء. تركز الكتب والمسرحيات واللوحات الفنية على سرد القصص. وثائق المحكمة هي مصدر غير عادي وغالبًا ما يتم تجاهله. كثير من الناس المهمشين الذين تتعهد قصصهم ينتهي في نظام المحاكم. غالبًا ما تكون محاكماتهم هي المرة الوحيدة التي يحضرون فيها جمهورًا وقادرون على التحدث عن حياتهم. MOOCs-- لأولئك الذين لم يأخذوا جميع دورات UBC Sauder ، تتم مشاركة العديد من المفاهيم من خلال سرد القصص - والتحدث مع الناس وطرح الأسئلة. لقد بدأنا تشغيل هذه الوحدة من خلال تسليط الضوء على عمل ستيوارت ماكلين وروايته القص. ما جعله مثل راوي القصص القوي كانت مهارات الاستماع له ، اهتمامه بالأشخاص الآخرين. سنتحدث عن تلك الصفات في آخر وحدة لدينا ، المهارات المتقدمة. لكن الآن أريدك أن تفكر ليس فقط في قصصك الخاصة ولكن كيف يمكنك الاستفادة من الآخرين كذلك ، دون الاستيلاء عليها بالطبع. MUSIC PLAYING] Marlisse: Before you launch into a Shakespearean monologue during a board meeting, it's important to think about stories and when they're appropriate in business situations and when they're not. I've found them particularly useful for engaging customers with content marketing, pitching ideas, and selling yourself and your skills during interviews or to investors. Can you think of some times when they shouldn't be used? Tweet them to me using the course hashtag. The readings for this section talk about how company founders in particular tap into storytelling to sell products. Think about how Elizabeth Holmes used storytelling in a company to promote a product that didn't even quite exist. She became a billionaire almost solely on the power of her story-- not that I'm advocating fraud. But what if you don't have a particularly interesting story of your own to tell? It doesn't always matter. The lovely thing about stories is that they're all around us. Let's review some of the places where we can look. Magazines, newspaper articles, broadcast news, these are all excellent sources. Many reporters tackle serious issues through the lens of a person who is dealing with something related to it. They're appealing to our empathy by giving facts and figures, faces and names. Books, plays, paintings, many of the arts focus on storytelling. Court documents are an unusual and often overlooked source of story. Many marginalized people whose stories are undertold end up in the court system. Their trials are often the only time they've had an audience and are able to talk about their lives. MOOCs- - for those who haven't taken all of UBC Sauder's courses, many of the concepts are shared through storytelling-- and talking to people and asking questions. We started off this unit by highlighting Stuart McLean's work and his storytelling legacy. What made him such a powerful storyteller were his listening skills, his interest in other people. We'll talk about those qualities in our last unit, advanced skills. But for now I want you to think not just about your own stories but how you can tap into other people's as well, without appropriating them of course. &&&&&&&&&&&&&&&&&&&&&&&&&&& مارليس: الآن سنتحدث عن موضوعي المفضل للغاية ، وهذا هو القص. أقوم بنشاط ممتع في الصف ، وأنا سوف أطلب منكم جميعًا القيام بنفس النشاط. أحصل على الطلاب للتفكير في قصص طفولتهم المفضلة ، تلك التي صداها حقا ، تلك التي يتذكرونها. ثم أطلب منهم أن يرسموا قصصهم. ونحن نقضي الكثير من الوقت في الحديث عن كل هذه القصص المختلفة قيل لنا كأطفال. الجزء الأنيق حول هذا النشاط هو أن لدي طلاب من جميع أنحاء العالم ، نوع من مثل هذا الجمهور. في Sauder ، لدينا هيئة طلابية متنوعة بالفعل ، وهذا أمر رائع. إذن أحصل على طلاب من باكستان ومن بيرو والهند والصين. وبغض النظر عن مكان وجود هذا الطالب في العالم ، نكتشف عندما نشارك كل هذه القصص لقد أخبرونا جميعًا بنفس الطريقة. هذه أشياء قوية جدا. وإذا استطعنا استخدام نفس هيكل القصة لنروي قصصنا في العمل ، سوف يحدث لمساعدتنا على التواصل مع جمهورنا. لذلك دعونا نذهب إلى ما هو الهيكل الآن. هذا هو الشكل العام للقصة. لدينا توتر. ويمكننا أن نرى أن توترنا يزداد مع استمرار القصة. وفي الأسفل هنا ، لدينا المدة أو الوقت الذي يستغرقه سرد القصة. نبدأ مع مقدمة. هذه هي اللحظة التي نلتقي فيها شخصياتنا الرئيسية وحيث يتم إخبارنا بنوع المشهد الذي نحن فيه ، المكان والزمان والعصر. نفهم سياق قصتنا. بعد وقت قصير من المقدمة ، لدينا تعقيد تم تقديمه. والمضاعفات هي عندما نكتشف المشكلة الرئيسية لشخصيتنا الرئيسية. لذلك يتم تقديم نوع من المشكلة لهذه الشخصية. ننتقل بعد ذلك إلى منتصف القصة. وهؤلاء عادة - في هذا الجزء الأوسط ، نرى سلسلة من الأحداث والصراعات لكلا شخصيتنا الرئيسية ولأي أحرف فرعية. لذلك لا يبدو دائمًا كالتوتر الصاعد المستقيم. في بعض الأحيان يبدو هذا قليلاً ، لذلك يتدفق ويسقط وينحسر ويسقط. ولكن كل شيء يؤدي إلى ذروتنا. ذروتنا هي اللحظة التي يكون فيها الشخصية الرئيسية يحل هذه المشكلة الرئيسية التي تم تقديمها في المضاعفات. ثم نرى حلاً ، حيث يتم حل القليل من النزاعات والمشاكل. وهذا يقودنا إلى كودا. كودا اختياري. ليس عليك دائمًا امتلاك واحدة. لكن الكوكا هي أخلاقية. إنه السبب وراء إخبارنا بهذه القصة. إذا كنت تفكر في قصص ديزني ، فكلها لها كوداس أو أخلاق قوية لهم. وكلهم يقعون في هيكل القصة الكلاسيكية هذا تمامًا. لكن ما سأحداك أن تفعله هو التفكير في كيفية ملائمة القصص الأخرى لهذا الهيكل نفسه. طلبت منك قراءة مقالتين لماندي لين كاترون. وأريد منك أن تفكر في كيفية تعاملها مع القصة واستخدامها هيكل للخروج من قصصها. إذا استطعنا الاستفادة من هذا ، إذا استطعنا سرد قصصنا بهذه الطريقة ، سيكون له صدى مع جماهيرنا. Marlisse: Now we're going to talk about my very favorite topic, and that's storytelling. I do a really fun activity in class, and I'm going to ask you all to do the same activity. I get students to think about their favorite childhood stories, the ones that really resonated with them, the ones they remember. Then I get them to map out their stories. And we spend a lot of time talking about all of these different stories we were told as children. The neat part about this activity is that I have students from all around the world, kind of like this audience. At Sauder, we have a really diverse student body, which is amazing. So I get students from Pakistan, from Peru, India, China. And no matter where that student was in the world, we find out when we share all of these stories that they've all been told to us in the same way. That's pretty powerful stuff. And if we can use that same story structure to tell our stories in business, it's going to help us connect with our audience. So let's go over what the structure is now. This is the general shape of a story. We have tension. And we can see that our tension rises as the story goes on. And on the bottom here, we have duration or the time it takes to tell the story. We start with an intro. This is the moment where we meet our main characters and where we're told what type of scene we're in, the place, the time, the era. We get to understand the context of our story. Shortly after the introduction, we have a complication that's introduced. And the complication is when we find out what the main problem is for our main character. So some type of problem is presented for this character. We move then onto the middle of the story. And those usually-- in this middle portion, we see a series of events and conflicts for both our main character and for any sub-characters. So it doesn't always look like straight upwards-rising tension. Sometimes it looks a little bit like this, so it flows and falls and ebbs and falls. But everything leads up to our climax. Our climax is the moment when the main character resolves this main problem that was introduced in the complication. Then we see a resolution, where little conflicts and problems are resolved. And it leads us to a coda. The coda is optional. You don't always have to have one. But a coda is a moral. It's the reason why we're being told this story. If you think of Disney stories, they all have really strong codas or morals to them. And they all fall into this classic story structure perfectly. But what I'm going to challenge you to do is to think about how other stories fit this same structure. I asked you to read two essays by Mandy Len Catron. And I want you to think how she manipulated and used the story structure to get out her stories. If we can tap into this, if we can tell our stories in this way, it's going to resonate with our audiences.&&&&&&&&&&&&&&&&&&&& مارليس: مايكل ، شكرًا جزيلاً على قضاء الوقت للدردشة معي اليوم حول توصيل البحوث الخاصة بك وكذلك إقناع الجمهور. مايكل بايرز: أنا سعيد لوجودي هنا. شكرا لكم. مارليس: لذلك أردت أن أتحدث إليكم ، ابدأ ببحثك. وأنت خبير في السيادة في القطب الشمالي ، من بين أمور أخرى. وبينما كنت أستعد لمقابلتنا اليوم ، نظرت إلى ما يعنيه ذلك ، سيادة القطب الشمالي. وقد انفجرت في كل الموضوعات المعقدة المختلفة التي تندرج تحت المظلة. لذلك علم تغير المناخ والدبلوماسية والقانون الدولي ، من بين العديد من الموضوعات الأخرى. ولذا سأطرح عليك أسئلة حول كلا كتاباتك وتحدثك اليوم ، ولكن لتبدأ ، أردت أن أعرف ، بشكل عام ، عندما تقوم بتوصيل البحوث الخاصة بك ، كيف يمكنك أن تفعل ذلك لجمهور كبير دون أن تفقد هذا التعقيد للجميع هذه المناطق المختلفة؟ مايكل بايرز: حسنًا ، أعتقد أنك قد حددت المشكلة الكبيرة بالنسبة لمعظم الناس الأكاديميين من حيث أنهم يريدون تكثيف مقالهم البحثي المكون من 10000 كلمة في 700 كلمة المرجع. مارليس: صحيح. مايكل بايرز: ونتيجة لذلك ، يصبح كثيفًا جدًا ومستحيلًا لأي شخص لمتابعة. يجب أن تكون مقالات الصحف قصيرة ويمكن الوصول إليها ومسلية. مارليس: صحيح. مايكل بايرز: هكذا ، أيضًا ، قم بإجراء المقابلات الإذاعية. ومعظم الأكاديميين يعرفون الكثير جدًا ، ولا يمكنهم التخلي عن معظمهم للتركيز على قضية واحدة ، فكرة واحدة. مارليس: هل هذا ما تفعله؟ كنت تأخذ قضية واحدة ثم توسيط حجة الخاص بك أو افتتاحية الخاص بك أو قطعة الخاص بك حول ذلك؟ مايكل بايرز: نعم. كنت تأخذ فكرة واحدة. أنت تجعل نقطة واحدة. قد يكون لديك 25 نقطة أخرى في جيبك الخلفي ، لكنهم لا يذهبون إلى المرجع. لا يذهبون إلى مقابلة البث. الآن ، في بعض الأحيان ، إذا أجريت مقابلة معك ، شخص ما سوف يعود مع سؤال. وتخيل ماذا؟ لقد حصلت على الجواب في جيبي الخلفي. كونك أكاديميًا ، ويقوم بالبحث الحقيقي ، يمنحك كل هذه الخلفية الإضافية ، كل الإجابات على الأسئلة الأخرى. ولكن بدلاً من محاولة حشر كل ما تبذلونه من البحوث في مقال واحد ، لماذا لا تكتب 10 مقالات منفصلة على 10 رؤى منفصلة؟ هذا هو المفتاح الحقيقي. أقول للأشخاص الذين يرغبون في كتابة مقالات افتراضية ، تخيل من هم جمهورك. وإذا كنت أكتب في جلوب اند ميل ، جمهوري هو رجل أعمال يمسك صباحًا مبكرًا رحلة من تورونتو إلى مونتريال. مارليس: صحيح. مايكل بايرز: لقد التقطوا ثلاث صحف ، وسوف يلقي نظرة على كل صفحة لمدة 10 ثوانٍ. أحتاج إلى جذب انتباههم. أحتاج أن أنقل معلوماتي بسرعة ، بإيجاز ، حتى يتمكنوا من قراءتها ، وهضمها ، والانتقال بعد 60 ثانية. هذا هو. هذا كل الوقت لدي. مارليس: حسنًا. إذن كيف تمكنت من عدم الوقوع في هذا الفخ الذي يفعله الكثير من الأكاديميين؟ كتاباتك قوية ومثيرة للاهتمام ومقنعة. هل كنت دائما هذا النوع من الكاتب؟ كيف غيرت صوتك أو بنت صوتك في الكتابة طوال حياتك؟ مايكل بايرز: حسنًا ، أعتقد أن الإجابة البسيطة هي أنني عنيد. لذلك أنا لا أحب الناس يقولون ، لا ، نحن لا نريد هذه القطعة. مارليس: صحيح. مايكل بايرز: إذن ، لقد كان لدي الكثير من المقالات الافتتاحية التي تم رفضها على مر السنين ، أكثر مما كنت قد قبلت. لكنني سأعود غالبًا إلى المحرر وأقول ، ما الذي لم يعجبك فيه؟ كيف اتعلم منك وأنا لا أعرف كيف يتعامل الأكاديميون الآخرون مع هذا ، ولكني أرى أن الصحفيين محترفين. لديهم قدر كبير من الخبرة. إنهم متخصصون في مجالهم ، أليس كذلك؟ مارليس: صحيح. مايكل بايرز: وإذا كنت أغامر في مجالهم ، فيجب أن أطلب النصيحة. يجب أن أشتبك معهم. إنهم ليسوا مقيمًا أعمىًا ، حكمًا لطلب المنحة. إنه شخص يمكنك التقاط الهاتف منه والاتصال والحصول على محادثة الكبار. لذا فإن النقطة المهمة الأخرى هي أنه عندما تكون محاولة الوصول إلى الأماكن العامة من خلال وسائل الإعلام ، العمل مع الصحفيين. لا تفترض فقط أنها ثقب أسود. مارليس: حسنًا ، حسنًا. لذا فإن طلب التعليقات يعد جزءًا كبيرًا من مايكل بايرز: بالتأكيد. مارليس: النجاح. مايكل بايرز: وكن مرتاحًا مع الرفض ، لأنه يمكنك دائما أن تفعل أفضل في المرة القادمة. مارليسي: ما هي بعض من أفضل ردود الفعل التي قمت بها على الإطلاق تلقى من محرر؟ مايكل بايرز: أفضل محرر عملت معه على الإطلاق كانت امرأة تدعى فال روس ، وكانت نائبة رئيس تحرير التعليق صفحة The Globe and Mail ، حتى ماتت صغيراً جدًا من ورم في المخ. لكنني اتصلت بها في الواقع يومًا ما حول قطعة تم رفضها. وقلت ، كما تعلمون ، ما الخطأ في ذلك؟ وقالت ، حسنًا ، دعني أقدم لك اقتراحًا. أود أن أعرف ما هي القطعة في الجملة الأولى. أريد أن أعرف ما هي الحجة الصحيحة من الأعلى. وأخذت هذا الدرس بعيدًا ، ومنذ ذلك الحين فصاعدًا دائمًا تعامل فقرتي الأولى كنوع من المرجع مصغرة. مارليس: أوه ، مثيرة للاهتمام. مايكل بايرز: إنني أحضر القارئ ، وأقول لهم رسالتي ، ثم الكلمات الـ 600 التالية هي كيف أنسخها. مارليس: تلاعب LAYING] Marlisse: Michael, thank you so much for taking the time to chat with me today about communicating your research and also persuading an audience. MICHAEL BYERS: I'm glad to be here. Thank you. Marlisse: So I wanted to talk to you, start with your research. And you're an expert in Arctic sovereignty, among other things. And as I was preparing for our interview today, I looked up what that meant, Arctic sovereignty. And I was blown away by all of the different complex topics that fall under the umbrella. So the science of climate change and diplomacy and international law, among many other topics. And so I'm going to ask you questions about both your writing and your speaking today, but to start with, I wanted to know, generally, when you're communicating your research, how do you do so to a mass audience without losing this complexity of all these different areas? MICHAEL BYERS: Well, I think you've identified the big problem for most academics in that they want to condense their 10,000-word research article into a 700-word op ed. Marlisse: Right. MICHAEL BYERS: And as a result, it becomes very dense and impossible for anyone to follow. Newspaper articles need to be short, accessible, entertaining. Marlisse: Right. MICHAEL BYERS: So, too, do broadcast interviews. And most academics simply know too much, and they can't let go of most of it to focus on one issue, one insight. Marlisse: So is that what you do? You take one issue and then center your argument or your op ed or your piece around that? MICHAEL BYERS: Yeah. You take one insight. You make one point. You might have another 25 points in your back pocket, but they don't go into the op ed. They don't go into the broadcast interview. Now, sometimes, if you're being interviewed, someone will come back with a question. And guess what? I've got the answer in my back pocket. Being an academic, doing real research, gives you all of that additional background, all of the answers to the other questions. But instead of trying to cram all your research into one op ed, why not write 10 separate op eds on 10 separate insights? That's the real key. I tell people who want to write op eds, imagine who your audience is. And if I'm writing in The Globe and Mail, my audience is a business person who's catching an early morning flight from Toronto to Montreal. Marlisse: Right. MICHAEL BYERS: And they've just picked up three newspapers, and they're going to glance at each page for 10 seconds. I need to grab their attention. I need to convey my information quickly, succinctly, so that they can read it, digest it, and move on 60 seconds later. That's it. That's all the time I've got. Marlisse: OK. So how did you manage not to fall into this trap that a lot of academics do? Your writing is so strong and interesting and compelling. Have you always been this type of writer? How have you changed your voice or built your writing voice throughout your life? MICHAEL BYERS: Well, I think the simple answer is that I'm stubborn. So I don't like people saying, no, we don't want this piece. Marlisse: Right. MICHAEL BYERS: So I've had an awful lot of op eds rejected over the years, more than I've had accepted. But I'll often go back to the editor and say, OK, what didn't you like about it? How can I learn from you? And I don't know how other academics approach this, but I take the view that journalists are professionals. They have a huge amount of experience. They're specialists in their own field, right? Marlisse: Right. MICHAEL BYERS: And if I'm venturing into their field, I should ask for advice. I should engage with them. They're not some blind assessor, a referee for a grant application. They're someone who you can pick up the phone and call and have an adult conversation. So the other big point is that when you're trying to access the public space through the media, work with journalists. Don't just assume that it's a black hole. Marlisse: Right, OK. So asking for feedback is a big part of-- MICHAEL BYERS: Absolutely. Marlisse: Being successful. MICHAEL BYERS: And be comfortable with rejection, because you can always do better next time. Marlisse: What's some of the best feedback you've ever received from an editor? MICHAEL BYERS: The best editor I've ever worked with was a woman named Val Ross, who was the deputy editor of the comment page of The Globe and Mail, until she died far too young from a brain tumor. But I actually phoned her up one day about a piece that had been rejected. And I said, you know, what's wrong with it? And she said, well, let me just give you a suggestion. I should know what the piece is about in the first sentence. I need to know what the argument is right from the top. And I took that lesson away, and, from that point onwards always treated my first paragraph as a kind of mini op ed. Marlisse: Oh, interesting. MICHAEL BYERS: That I'm bringing the reader in, I'm telling them my message, and then the next 600 words is how I back it up. Marlisse: Rig يصبح من السهل التحدث مع أشخاص آخرين حول عملك. وينتقل هذا الإثارة ونأمل أن يصبح معديا. مارليسي: إنه كذلك. انها حقا - نعم. مايكل بايرز: إذن هذا جزء منه. فقط اعمل على الأشياء التي تهمك حقًا. والأكاديميون محظوظون. لدينا بعض المرونة من حيث الموضوعات التي نتعامل معها. مارليس: صحيح. مايكل بايرز: لذا ، استفد من ذلك نقطة مهمة حقًا. الشيء الآخر من حيث الخطابة ، وكذلك لمقابلات البث ، هذا مهم حقًا تخدع نفسك في التفكير أنك تتحدث فقط مع واحد أو اثنين أو ثلاثة اشخاص. لذلك عندما يكون لديك قاعة محاضرة بها 100 شخص ، العثور على وجه ودية في منتصف الطريق حتى الغرفة أو ربما زوجين ، واحد على كل جانب ، والتحدث مع هؤلاء الناس. وحظر فقط حقيقة أن الجميع موجود هناك. إذا كنت تتحدث إلى صحفي يجري مقابلته للتلفزيون أو الإذاعة ، التحدث فقط لهذا الشخص. ادعي أنه لا يوجد أحد آخر هناك. وإذا استطعت أن تخدع نفسك ، فإن القلق يختفي. إنه يسبب ، أو يمكن أن يسبب ، الكثير من القلق لنعتقد أن هناك 100 شخص يستمعون بالنسبة لي ، أن هناك مليون شخص يستمعون إلي ، أليس كذلك؟ مارليس: نعم ، بالطبع. مايكل بايرز: إذن عليك فقط أن تخدع نفسك. ثم الخدعة النهائية لا تستمع أبداً إلى نفسك بعد ذلك. مارليس: حقا؟ مايكل بايرز: رقم لا أشاهد أو أستمع إلى المقابلات التي قمت بها. مارليس: مثيرة للاهتمام. مايكل بايرز: لأنني أريد المتابعة لخداع نفسي في التفكير أنه كان مجرد محادثة لشخصين. مارليس: أوه ، واو ، هذا تكتيك مثير للاهتمام حقًا. لأنني تحدثت إلى الكثير من الناس الذين لا يستطيعون التوقف عن المشاهدة. ينتقدون أدائهم بالكامل. لذلك أنت تفكر إلى الأمام جدا. مايكل بايرز: أو ربما أكون قلقًا تمامًا. مارليس: أوه ، أليس كلنا؟ نتحدث عن ذلك في هذه الدورة أيضًا حول كيف يكون هذا جزءًا طبيعيًا من الخطابة ، هو القلق الذي يأتي معها. مايكل بايرز: لقد رأيت أشخاصاً يتحدثون بانتظام إلى الملايين والملايين من الناس الذين كنت تعتقد هي الوجوه العامة الأكثر راحة واحترافية في العالم ، وأراهم قبل أن يذهبون على خشبة المسرح ، أيديهم تهتز. لأن لديهم قلق أيضا. أعني ، نحن جميعًا ندير ذلك. وقد يكون الأمر جيدًا للغاية ، لأنك مخطوب. أنت 100 ٪ في الوقت الحالي ، أليس كذلك؟ القلق هو الأدرينالين. مارليس: صحيح. مايكل بايرز: إنه ليس بالأمر السيئ بالضرورة. مارليس: هذا صحيح ، إذا أمكنك توجيهه إلى إيجابي. أردت أن أسألك عن نوع معين من الكلام الشفهي الذي قمت به ، وهذا في عام 2008 ، أنت ركض في الانتخابات الفيدرالية الكندية. وكجزء من حملتك ، كان عليك إجراء مناقشات عامة ضد المرشحين الآخرين. ما هو تكتيكك في هذا المنتدى لمحاولته إقناع جمهورك؟ ما النهج التي كنت تأخذ؟ مايكل بايرز: كان هذا التعلم الأكثر لا يصدق تجربة يمكن تخيلها. مارليس: أراهن. مايكل بايرز: أساتذة العلوم السياسية أعتقد أنهم يعرفون عن السياسة. مارليس: نأمل. مايكل بايرز: لكن إلى أن تشارك بالفعل في حملة ، إما كعامل حملة أو كمتطوع أو مرشح أو مستشار من نوع ما ، حقا لا يوجد لديك أي تقدير عن ما يشبه حقا. وكان لي شرف لا يصدق من الركض ضد ثلاثة قوي جدا ، والسياسيين ذوي الخبرة. فيما بينهم ، خاضوا الانتخابات في حوالي 18 انتخابات مختلفة. إنهم مجرد عقود وعقود من الخبرة ، وقد علموني ذلك. لذلك على مدار حملة استمرت خمسة أسابيع ، لقد تعلمت الكثير منهم فظيعة. لأنه ليس مثل أي شكل آخر من أشكال التواصل العام. أنت تطلب من الناس أن يثقوا بك. مارليس: صحيح. مايكل بايرز: ممارسة حقهم الديمقراطي الأساسي للتصويت وتكليفك بمستقبل بلادهم ، والتي هو أساسا مستقبل أسرهم وذريتهم. هذه صفقة كبيرة حقا. مارليس: نعم ، مخاطر عالية. مايكل بايرز: إنه عن الشخصية. إنه يتعلق بالثقة أكثر مما يتعلق بالسياسة أو المشكلات. وذهبت من خلال هذا منحنى التعلم حاد لا يصدق وخرج الطرف الآخر بتقدير أكبر بكثير بالنسبة للأشخاص الذين وضعوا أسمائهم للأمام للانتخابات أو لا تشارك فقط في السياسة. إنه عالم مختلف. إنه عالم مهم. ليس لدي أي خطط لتشغيل مرة أخرى. لكن كعلمي سياسي ، أعتقد أنه يترشح بالفعل للبرلمان كان شيء لا يصدق قيمة بالنسبة لي كشخص يكتب ويفكر حول هذه العمليات. مارليس: وماذا ستقول هو أكبر نصيحة تعلمتها حول طلب الثقة من الناس والبناء أن الثقة من خلال خطابك العام في هذا المكان؟ مايكل بايرز: حسنًا ، عليك تطوير بعض القدرات لرؤية العالم من خلال عيون شخص آخر ، أليس كذلك؟ كان لي شرف الركض في مركز فانكوفر والتعرف على مجتمع المثليين والمثليات في ويست إند جيد جدا على مدار خمسة أسابيع. كان جميع فريق حملتي تقريبًا أشخاصًا من هذه المجموعة it becomes easier to talk to other people about your work. And that excitement is transmitted and hopefully becomes infectious. Marlisse: It is. It really-- yeah. MICHAEL BYERS: So that's part of it. Just work on things that really matter to you. And academics are lucky. We have some flexibility in terms of the topics we take on. Marlisse: Right. MICHAEL BYERS: So make use of that is a really important point. The other thing in terms of public speaking, and also for broadcast interviews, that's really important is fool yourself into thinking you're only speaking to one or two or three people. So when you have a lecture hall full of 100 people, find a friendly face halfway up the room or maybe a couple, one on each side, and talk to those people. And just block out the fact that everyone else is there. If you're talking to a journalist being interviewed for television or radio, talk just to that person. Pretend that there's no one else out there. And if you can fool yourself, then the anxiety disappears. It causes, or it can cause, a lot of anxiety to think that there are 100 people listening to me, that there are a million people listening to me, right? Marlisse: Yeah, of course. MICHAEL BYERS: So you just have to fool yourself. And then the final trick is never listen to yourself afterwards. Marlisse: Oh, really? MICHAEL BYERS: No. I never watch or listen to interviews that I've done. Marlisse: Interesting. MICHAEL BYERS: Because I want to continue to fool myself into thinking that it was just a two-person conversation. Marlisse: Oh, wow, that's a really interesting tactic. Because I've talked to a lot of people who can't stop watching. They critique their entire performance. So you're very forward thinking. MICHAEL BYERS: Or maybe I'm just anxiety ridden. Marlisse: Oh, aren't we all? We talk about that in this course, as well, about how that's a natural part of public speaking, is the anxiety that comes with it. MICHAEL BYERS: And I have seen people who regularly speak to millions and millions of people who you would think are the most comfortable professional, experienced public faces in the world, and I see them before they go on stage, their hand shaking. Because they have anxiety, too. I mean, we're all managing that. And it can be a very good thing to have, because you're engaged. You're 100% in the moment, right? The anxiety is adrenaline. Marlisse: Right. MICHAEL BYERS: It's not necessarily a bad thing. Marlisse: That's true, if you can channel it into a positive. I wanted to ask you about a very specific type of oral speaking that you've done, and that's in 2008, you ran in the Canadian federal election. And as part of your campaign, you had to do public debates against other candidates. What was your tactic in that forum for trying to persuade your audience? What approaches were you taking? MICHAEL BYERS: That was the most incredible learning experience imaginable. Marlisse: I bet. MICHAEL BYERS: Political science professors think they know about politics. Marlisse: We hope. MICHAEL BYERS: But until you're actually involved in a campaign, either as a campaign worker or a volunteer, a candidate, a consultant of some kind, you really don't have any appreciation as to what it's really like. And I had the incredible privilege of running against three very strong, experienced politicians. Between them, they had run in something like 18 different elections. They're just decades and decades of experience, and they taught me. So over the course of a five-week campaign, I learned an awful lot from them. Because it's not like any other form of public communication. You're asking people to trust you. Marlisse: Right. MICHAEL BYERS: To exercise their fundamental democratic right to vote and to entrust you with the future of their country, which is essentially the future of their family, their descendants. This is a really big deal. Marlisse: Yeah, high stakes. MICHAEL BYERS: And it's about personality. It's about it's about trust more than it's about policy or issues. And I went through this incredible steep learning curve and came out the other end with much greater appreciation for people who do put their names forward for elections or do just become involved in politics. It's a different world. It's an important world. I have no plans to run again. But as a political scientist, I think that actually running for parliament was an incredibly valuable thing to do for me as someone who writes and thinks about these processes. Marlisse: And what would you say is the biggest tip that you learned about asking for trust from people and building that trust through your public speaking in that venue? MICHAEL BYERS: Well, you have to develop some capacity to see the world through another person's eyes, right? I had the privilege of running in Vancouver Center and getting to know the gay and lesbian community of the West End pretty well over the course of five weeks. Almost all of my campaign team were people from th ه المجتمع المجتمع. والتعلم عن ذلك والتعلم ليس فقط ل تعاطف ولكن أن نتعاطف في الواقع ، لنرى العالم من خلال عيون الناس في ظروف مختلفة جدا - الذهاب إلى الإسكان كبار الدخل المنخفض. الذهاب إلى فندق SRO ، فندق إقامة فردية ، على طول شارع Granville ورؤية العالم من خلال عيون الناس الذين يحتاجون إلى حكومة جيدة ، من بحاجة إلى السياسيين الذين يهتمون بهم. مارليس: نعم. بايرز مايكل: من يحتاج إلى نظام يعمل فعليًا للجميع. لذلك كان حقا قوية جدا. لقد قضيت معظم حياتي في مكتبات الجامعة. وكان الخروج من هذا العالم تجربة نمو حقيقية بالنسبة لي. مارليس: حسنًا ، تعاطف مع مايكل بايرز: نعم ، ولكن ليس التعاطف وهمية. لذلك أنا لا أتحدث عن هذا كثيرا ، ولكن في الواقع وضع نفسك في الظروف التي تشارك فيها في محادثة مع الناس الذين يعيشون في ظروف مختلفة جدا ، من رؤية العالم بشكل مختلف عنك. هذا لا يعني أن عليك أن تتفق معهم أو لديك لإقناعهم بالاتفاق معك. مارليس: صحيح. مايكل بايرز: لكن علينا أن نضع أنفسنا في تلك الظروف. الدرس الكبير الذي لدي للطلاب وللأكاديميين الآخرين هو أخذ نفسك في العالم الحقيقي في بعض الأحيان. ضع نفسك في ظروف مختلفة وغير عادية. آخذ ندوات الدراسات العليا إلى الجانب الشرقي من وسط المدينة ، وأنا آخذهم في جولات. وهذا ليس لأنني فقط أشير إلى الفقر. أشير إلى حقيقة أنه يمكنك إلقاء نظرة على الجانب الشرقي من وسط المدينة من منظور العلاقات الدولية وانظر تقاطع العشرات من القضايا من جميع أنحاء العالم التي اختتمت بأشياء مثل تجارة المخدرات ، مع تجارة الجنس ، مع حقيقة أننا ميناء عالمي رئيسي. ويمكنك البدء في كشف المشكلات المختلفة من خلال عدسة أكاديمية ، ولكن فجأة إنه حقيقي. مارليس: صحيح ، بالخروج إلى هناك في العالم - مايكل بايرز: بالتأكيد. مارليس: - والتحدث مع الناس. مايكل بايرز: نعم. مارليس: حسنًا ، شكرًا. هل تغير منهجك في التواصل؟ سواء كنت تتحدث أو تكتب؟ مايكل بايرز: أعتقد ذلك ، ببساطة لأن الكتابة هو تمرين حيث يمكنك التلميع وإعادة الكتابة والعودة وتقليله. إنه نوع من التراكم ، عملية تكرير. ومع التحدث ، لديك فقط طلقة واحدة. لذلك المفتاح الكبير للتحدث ، بقدر ما أنا قلق ، هو أن لا يكون الكمال. الكل يخطئ. الجميع أمهات وآهات. الجميع ينسى أحيانًا النقطة التي كانوا على وشك الإدلاء بها. هذا يحدث. إنها الحياة ، أليس كذلك؟ مارليس: نعم. مايكل بايرز: وهذا ليس بالضرورة ينتقص من التواصل ، لأن الناس لا يفعلون ذلك نريد المتحدث العام أن يكون بقعة. إنهم يريدون منهم أن يكونوا حقيقيين. مارليس: صحيح. الطبيعية ، المحادثة. مايكل بايرز: حتى مجرد الاسترخاء هي الرسالة بالنسبة للأشخاص الذين تدرس. فقط استرخ ، كن نفسك ، ولا تعرق الأخطاء. مارليس: نعم ، لأننا جميعًا نصنعها بالتأكيد. سؤالي الأخير بالنسبة لك هو الطلاب في هذه الدورة ، لقد بدأوا للتو في تعلم كيفية الإقناع والوقوف في قضايا مختلفة. لسوء الحظ ، لم نتمكن من الوصول إلى الأمر بعمق أو تعقيد. ولكن ما رأيك هو نوعية واحدة أن كل داعية ، كل داعية ناجح ، حقا يحتاج لامتلاك؟ مايكل بايرز: أعتقد أنك بحاجة إلى امتلاك المشكلة. تحتاج أن تشعر حيال هذه القضية. تحتاج إلى رعاية القضية. أنا تصطدم بالأشخاص الذين يعملون في شركات العلاقات العامة كأسلحة مستأجرة. مارليس: صحيح. بايرز مايكل: سيعملون لصالح عميل واحد أو آخر في محاولة لمساعدتهم على صياغة رسالة ، لنشرها علامة تجارية ، مهما كانت. لا أستطيع تخيل القيام بذلك ، لأنني لم أستطع تكون في وضع يمكنها من محاولة التأثير على الأفكار في الأماكن العامة أنني لم أهتم بالضرورة. ونعم ، هناك خط جيد حقًا هنا بين أن تكون أكاديميًا وكونك ناشطًا ، لكنك بحاجة إلى العناية. هذا ليس حكما مسبقا على ما يهمك. قد يهتم شخص ما بالرأسمالية ويريد أن يتقدم بها. وإذا كانوا يهتمون بذلك ، فسيكونون أكثر فاعلية مما لو لم يفعلوا. وإذا كان شخص ما يهتم حقًا بحقوق الإنسان أو محنة السكان الأصليين الشعوب أو البيئة ، وسوف تكون أكثر فعالية إذا ذهبوا في هذا الاتجاه. لكن النقطة الأساسية هي امتلاك المشكلة فعليًا ، وإضفاء الطابع الداخلي عليها ، والاهتمام بها. مارليس: حسنًا. حتى امتلاك القضية وبعض العاطفة لموضوعك. مايكل بايرز: حسنًا ، سيكون لديك شغف إذا كنت تملك المشكلة. مارليس: صحيح. مايكل بايرز: وإذا كان لديك شغف ، فسيشعر به الناس. مارليس: بالتأكيد. مايكل بايرز: وسيؤدي ذلك إلى زيادة تأثيرك إلى مستوى جديد تماما. مارليس: حسنًا. أرى كيف تسير هذه الدورة. حسنًا ، شكرًا مرة أخرى على الوقت الذي أمضيته في الدردشة معنا ولطلابي ، كذلك. وأنا أعلم أننا جميعا نقدر ذلك حقا. مايكل بايرز: إنه لمن دواعي سروري للغاية. شكرا لكم. مارليس: شكرًا. [عزف الموسيقى] نهاية النص. تخطي إلى البداية. التنزيلات والنصوص فيديو e queer community. And learning about that and learning not only to sympathize but to actually empathize, to see the world through the eyes of people in very different circumstances-- going into low income senior housing. Going into a SRO hotel, single residency hotel, along Granville Street and seeing the world through the eyes of people who need good government, who need politicians who care about them. Marlisse: Yes. MICHAEL BYERS: Who need a system that's actually working for everyone. So that was really quite powerful. I'd spent most of my adult life in university libraries. And to get out into that world was a real growth experience for me. Marlisse: OK, so empathy in-- MICHAEL BYERS: Yeah, but not fake empathy. So I don't talk about this very much, but actually putting yourself in circumstances where you're engaged in conversation with people who live in very different circumstances, who see the world differently from you. That doesn't mean that you have to agree with them or you have to persuade them to agree with you. Marlisse: Right. MICHAEL BYERS: But we have to put ourselves into those circumstances. The big lesson I have for students and for other academics is take yourself out in the real world sometimes. Put yourself into different, unusual circumstances. I take my graduate seminars down to the downtown east side, and I take them on tours. And it's not because I'm just pointing out poverty. I'm pointing out the fact that you can look at the downtown east side from the perspective of international relations and see the intersection of dozens of dozens of issues from around the world which are wrapped up with things like the drug trade, with the sex trade, with the fact that we're a major global port. And you can start to unravel the different issues through an academic lens, but all of a sudden it's real. Marlisse: Right, by getting out there in the world-- MICHAEL BYERS: Absolutely. Marlisse: --and talking to people. MICHAEL BYERS: Yeah. Marlisse: OK, thanks. Do you change your approach to communication whether you are speaking or writing? MICHAEL BYERS: I think so, simply because writing is an exercise where you can polish and rewrite and go back and reduce it. It's kind of an accumulation, a refining process. And with speaking, you only have one shot. So the big key for speaking, as far as I'm concerned, is to not be a perfectionist. Everyone misspeaks. Everyone ums and ahs. Everyone sometimes forgets the point that they were just about to make. It happens. It's life, right? Marlisse: Yeah. MICHAEL BYERS: And it doesn't necessarily detract from the communication, because people don't want their public speaker to be slick. They want them to be real. Marlisse: Right. Natural, conversational. MICHAEL BYERS: So just relax is the message for the people who you're teaching. Just relax, be yourself, and don't sweat the mistakes. Marlisse: Yeah, because we definitely all make them. My last question for you is the students in this course, they're just starting out to learn how to persuade and stand up on different issues. Unfortunately, we don't get to go into it in much depth or complexity. But what do you think is one quality that every advocate, every successful advocate, really needs to possess? MICHAEL BYERS: I think you need to own the issue. You need to feel about the issue. You need to care about the issue. I bump into people who are working for PR companies as hired guns. Marlisse: Right. MICHAEL BYERS: They'll be working for one or another client to try to help them craft a message, to disseminate a brand, whatever it might be. I can't imagine doing that, because I couldn't be in a position of trying to leverage ideas into the public space that I didn't necessarily care about. And yes, there's a really fine line here between being an academic and being an activist, but you do need to care. That's not prejudging what you care about. Someone might care about capitalism and want to be advancing it. And if they care about it, they'll be much more effective than if they don't. And if someone really cares about human rights or the plight of Indigenous peoples or the environment, they'll be more effective if they go in that direction. But the point is to actually own the issue, to internalize it, to care. Marlisse: OK. So owning the issue and some passion for your topic. MICHAEL BYERS: Well, you'll have passion if you own the issue. Marlisse: Right. MICHAEL BYERS: And if you have passion, people will feel it. Marlisse: For sure. MICHAEL BYERS: And that will then leverage your impact to an entirely new level. Marlisse: OK. I see how that cycle goes. Well, thanks again for taking the time to chat with us and for my students, as well. I know we all really appreciate it. MICHAEL BYERS: It's a very great pleasure. Thank you. Marlisse: Thanks. [MUSIC PLAYING] End of transcript. Skip to the start. Downloads and transcripts - &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& As the inventor of this device, I find it necessary to develop and invest in this readiness. In terms of health and consumer, it is very useful. Where people's health is a priority for us, it is essential to determine if the person in the case of overdose or not. It also alerts people with the device, as well as alerting people close to them that the person carrying the device is in a dangerous health condition and that he needs to go to the hospital or see a doctor. If the money is available, the process of developing the device will be certain. This means that its efficiency will be high and can also provide other services or have other advantages, such as automatically contact the nearest person from the holder of the device or the nearest hospital. In terms of financial investment, the device will be successful and its sales are huge as there are many people who are concerned about people close to them or even themselves, and will want to buy it. This will certainly save a lot of profits and will be in the interest of developing the device in the future. 7&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& الكتابة المقنعة [عزف الموسيقى] مارليس: الكتابة المقنعة لها نفس الأهداف التي تحدث بها الإقناع. أنت تحاول تغيير مواقف أو معتقدات أو تصرفات شخص ما. أنت تقنعهم بالقيام بشيء ما. انها ليست سهلة. هذا النوع من الكتابة عادة ما يكون أطول وأكثر تفصيلاً. منطقي. قد يكون الجمهور مقاومًا للتغيير. سوف يحتاجون إلى مزيد من السياق. في كثير من الأحيان ، عندما نكتب إلى الناس بشكل مقنع ، نحن لسنا وحدنا. فكر في رسائل الغلاف أو طلبات الرعاية. إنها فرصة ضئيلة لتكون الوظيفة الوحيدة مقدم الطلب أو غير ربحية فقط تصل إلى شركة نقدا. فكيف تجعل كتابتك المقنعة تبرز؟ تحتاج إلى إثبات مصداقيتك الخاصة لتبدأ. لا يمكنك إقناع أي شخص إذا كان لا يعرف من أنت ولماذا أنت الشخص المناسب لهذا الموضوع. بالنسبة لبعض الناس ، إنه فطري. لا أحد سوف يشكك في قدرة إيلون موسك على الابتكار. ولكن بالنسبة لبقية منا ، أولئك الذين لم يؤسسوا تسلا ، قد نحتاج إلى قضاء بعض الوقت في ترسيخ مصداقيتنا مقدمًا. إظهار الخبرة ، فهو يساعدك على القيام بذلك. تقديم أمثلة والسياق. قم ببحثك لإظهار جمهورك أنك لن تصاب بالبرد. كنت حتى على الصناعة أو الشركة. ما زلت أتذكر أسوأ مقابلة عمل معي على الإطلاق. كان الصيف بين عامي الثاني والثالث من التخلف. وكنت أجري مقابلة مع سفير بميناء فانكوفر السلطة. كان لدي انفلونزا سيئة حقا. لكن قبل المقابلة ، بدلًا من الإلغاء ، شعرت بالبرد. كان أحد الأسئلة الأولى التي سألوني عنها ما أعرفه عن هيئة ميناء فانكوفر - سهل للغاية. دعنا نقول فقط أن الإسهال اللفظي عن القوارب تخرج من فمي لم تهبط لي الوظيفة. لا تفعل هذا في كتابتك مقنعة. أظهر لجمهورك أن لديك خبرة في هذا المجال. إظهار الحماس والإيجابية. استخدم لغة عاطفية. إذا لم تكن متحمسًا لهذه الفكرة ، فلا يمكنك توقع أن يكون هناك شخص آخر. دعم مع الحقائق واسم المصادر الخاصة بك. تحتاج إلى استخدام أدلة موثوقة - لا يوجد أخبار وهمية هنا. حاول أن تكون موضوعيا. أظهر لجمهورك أنك نظرت في الجوانب الأخرى للقضية. إيجاد أرضية مشتركة. كيف يمكن أن تطلب ما ينفع الشخص أو الشركة التي تكتبها؟ هل هناك رؤى مماثلة ، مشاعر مشتركة؟ التأكيد على هذه. تذكر أنه يتعلق بالاتصالات التي تركز على الجمهور. لا تجعل الأمر يتعلق بسؤال شخص ما عن شيء ما. بدلاً من ذلك ، أظهر كيف يمكنك الاستفادة منها. نستخدم اختصار لتذكر أهداف الكتابة المقنعة. هل هناك أي مشجعين للأوبرا هناك؟ انها عايدة. التي تقف على الاهتمام ، الاهتمام ، الرغبة ، العمل. تمت مناقشته في واحدة من القراءات السابقة ، ولكن دعونا نراجع بسرعة كل مكون. انتباه - تحتاج إلى جذب انتباه جمهورك بادئ ذي بدء. الإبداع مفيد هنا. أن تكون موجزة وجذابة. هذا هو المكان الذي يمكنك أن تبدأ التأكيد على أرضية مشتركة. الفائدة - حدد سبب ارتباط الرسالة بجمهورك. تابع الموضوعات التي قدمتها في البداية. تقديم مزيد من التفاصيل والأمثلة. الرغبة - أن تكون مباشرة هنا. أخبر القراء كيف سيستفيدون. فكر في أنواع الأسئلة التي لديهم ، وحاول الإجابة عليها. أشر إلى بعض الاعتراضات الشائعة. محاولة لمواجهتها مع الأدلة الخاصة بك. العمل - جعل العمل سهلا. أن تكون محددة حقا حول ما تحتاجه. ما هي الخطوات التالية؟ التأكيد على ايجابيات القرار. [عزف الموسيقى] Persuasive Writing [MUSIC PLAYING] Marlisse: Persuasive writing has the same goals as persuasive speaking. You're trying to change someone's attitudes, beliefs, or actions. You're convincing them to do something. It's not easy. This type of writing is usually longer and more detailed. That makes sense. The audience might be resistant to the change. They'll need more context. Lots of times, when we're writing to people persuasively, we're not the only ones. Think about cover letters or requests for sponsorship. It's a slim chance that you'll be the only job applicant or the only nonprofit hitting a company up for cash. So how do you make your persuasive writing stand out? You need to establish your own credibility to start with. You can't persuade anyone if they don't know who you are and why you're the right person for this topic. For some people, it's innate. No one is going to question Elon Musk's ability to innovate. But for the rest of us, those who haven't founded Tesla, we might need to spend some time establishing our credibility up front. Demonstrating expertise, it helps you do this. Provide examples and context. Do your research to show your audience that you're not coming in cold. You're up on the industry or company. I still remember my worst job interview ever. It was the summer between my second and third years of undergrad. And I was interviewing to be an ambassador at the Vancouver Port Authority. I had a really bad flu. But before the interview, instead of canceling, I went in cold. One of the first questions they asked me was what I knew about the Vancouver Port Authority-- pretty easy. Let's just say that verbal diarrhea about boats coming out of my mouth didn't land me the job. Don't do this in your persuasive writing. Demonstrate to your audience you have expertise in the area. Show enthusiasm and positivity. Use language that's passionate. If you're not excited about this idea, you can't expect anyone else to be. Support with facts and name your sources. You need to use credible evidence-- no fake news here. Try to be objective. Show your audience that you've considered other sides of the issue. Find common ground. How can what you're asking for benefit the person or company you're writing? Are there similar visions, shared passions? Emphasize these. Remember, it's about audience-focused communications. Don't make it about asking someone for something. Instead, show how you can benefit them. We use an acronym to remember the objectives of persuasive writing. Are there any opera fans out there? It's AIDA. That stands for Attention, Interest, Desire, Action. It was discussed in one of your pre-readings, but let's quickly review each component. Attention-- you need to capture your audience's attention at the very beginning. Creativity is useful here. Be brief and engaging. This is where you can start emphasizing common ground. Interest-- outline why the message is relevant to your audience. Continue on with themes you introduced in the beginning. Provide more details and examples. Desire-- be direct here. Tell your readers how they're going to benefit. Think about what kinds of questions they'll have, and try to answer these. Point out some of the common objections. Try to counter them with your own evidence. Action-- make action easy. Be really specific about what you need. What are the next steps? Stress positives of the decision. [MUSIC PLAYING] |
إذن موضوع هذا القسم ، هو ما يُسمى بـ "الحلقة". وهذا سيكون أ زيادة كبيرة في ما يمكننا القيام به مع رمز. لذلك ، إذا نظرت إلى الأصل صورة الزهور ، هنا ، يبلغ عرضها 457 بكسل ارتفاع 360 بكسل. اذا انت اضرب فقط لتحصل على العدد الإجمالي للبكسل وهو 164000 بكسل وعدد قليل من الأفراد بكسل. وهذه صورة صغيرة جدا. لذلك ، هذا هو الكثير من بكسل. هكذا نحن تم كتابة التعليمات البرمجية من قبل ، حيث سيكون لديك خط مثل pixel.setRed (255) إلى تغيير بكسل واحد إلى اللون الأحمر ، هذا فقط ، هذه ليست طريقة عملية للقيام بذلك العملية على صورة كاملة. أعني ، هذه صورة صغيرة ولديها أكثر من 100000 بكسل. إذن ما نريده هو إنشاء حيث يمكننا كتابة بضعة أسطر من التعليمات البرمجية أن التقاط بعض التغيير الذي نريد القيام به ومن ثم السماح للكمبيوتر برعاية مسك الدفاتر من تشغيل هذه الخطوط من التعليمات البرمجية مرارا وتكرارا مرة واحدة لكل بكسل على صورة. لذا فإن الحلقة ، موضوع القسم ، هي أن تفعل هذا بالضبط وهذا سيكون زيادة كبيرة في ما يمكننا القيام به ، مع الكود. لذلك اسمحوا لي أن أتحدث حول ، هيكل هذا الشيء. أنا فقط ذاهب لتحديد الأجزاء ثم سأفعل مثالا. حتى هنا في المربع الأزرق هنا لدي صورة ل حلقة سأتحدث فقط عن الأجزاء. لذلك ، يبدأ - وسأستخدم بلدي القلم - وهذا ، يبدأ بـ الحلقة للحصول على الكلمة لـ ومن ثم بين قوسين يقول صورة القولون بكسل ومن ثم هناك هدفين مجعد الأيسر لبدء الانطلاق السطر التالي وماذا يعني هذا. وجميع بناء الجملة تتطلب الأقواس والقوس المجعد وكل شيء. عادة في الأمثلة أو في التدريبات سنقوم بذلك فقط في كل مرة ، لذلك سنوفرها عادةً وبعد ذلك فقط اطلب منك كتابة التعليمات البرمجية على السطر التالي. إذن ما يعنيه هذا هو ، من أجل كل بكسل في هذه الصورة ، يرجى التالي ، ثم التالي هو: كما هو محدد في الأقواس الملونة هنا. هذه الخطوط. داخل الشيء. هذا هو ، ودعا الجسم من أجل حلقة. وهذا هو فقط بضعة أسطر من التعليمات البرمجية التي يمكن القيام بها ، كل ما نريد. لذلك ، فإن الطريق تعمل for-loop ، ودعنا نقول أننا ، كما تعلمون ، نعمل على صورة الزهور هنا. فعلا. هنا لدينا ثلاثة خطوط. لذلك سوف يأخذ ، دعنا نقول ، بكسل رقم واحد من الصورة كاملة ، بكسل اليسار العلوي. وهكذا ، فإنه يعزل بكسل رقم واحد. وثم يدير هذه الحلقة ، هذه الأسطر الثلاثة الأولى. هكذا تقول ؛ pixel.setRed (0)، pixel.setGreen (0) ، pixel.setBlue (0). هذه كلها يحدث لبكسل رقم واحد. ثم ، في الحقيقة ، ما يفعله هو أنه يغيره إلى أسود ، أليس كذلك؟ يضبط اللون الأحمر والأخضر والأزرق على الصفر. لذلك عندما يحصل على حلقة ل الجزء السفلي يحدث شيء مضحك ولدي نوع من هذا السهم الأسود. انها حلقات نسخ احتياطي إلى الجزء العلوي من الخطوط الثلاثة والآن ستعمل عزل بكسل رقم اثنين ، لذلك بكسل الثاني ، ومن ثم يتم تشغيل هذه الخطوط الثلاثة مرة أخرى. هكذا يفعلهم إلى البيكسل اثنين ، ثم يعود إلى الأعلى ويقوم بتشغيل الخطوط الثلاثة مرة أخرى من بكسل رقم ثلاثة ، وهلم جرا. يعمل فقط الخطوط مرارا وتكرارا وتكرارا مرة واحدة لكل بكسل في الصورة. وبالتالي. و ، الشيء الآخر الذي أود الإشارة إليه هنا هل ستلاحظ أن ، الأسطر الثلاثة في الجسم هي بادئة وهذا لا مطلوب ولكن هذا هو ، انها اتفاقية شائعة لإظهار أن الخطوط في الجسم نوع مختلف عن سطور الكود الأخرى. حيث تساوي هذه الصورة الجديدة simpleImage ، حسناً ما يحدث مرة واحدة فقط والصورة المطبوعة التي تحدث مرة واحدة فقط. لكن الخطوط الموجودة داخل الحلقة مميزة نوعًا ما لأنها تتمتع بهذه الجودة سوف يتم تشغيلهم مرارًا وتكرارًا. اذا لنجرب. نحن فقط تشغيل هذا بالضبط مثال. حتى هنا لدي في رمز runnable لذلك ، هذا يحمّل الصورة. ثم لقد حصلت على ، حلقة for-off off the body. ها هي الخطوط الثلاثة لل الجسم. وبعد ذلك ، إنه نوع صغير هنا ولكن بعد ذلك ، هناك دعامة مجعد الأيمن نوع من التوازن بين هدفين مجعد اليسار هنا أن يغلق الجسم. So the topic of this section, is what's called a for-loop. And this is going to be a big increase in what we can do with the code. So, if you look at the original flowers image, here, it's 457 pixels wide by 360 pixels high. So, if you multiply just to get the total number of pixels that's 164,000 and a few odd pixels. And this is a pretty small image. So, that's a lot of pixels. So the way we were writing code before, where you would have a line like pixel.setRed(255) to change one pixel to red, that's just, that's not a practical way to do an operation on a whole image. I mean, this is a small image and has over 100,000 pixels. So what we want is a construct where we can write a few lines of code that capture some change we want to make and then let the computer take care of the bookkeeping of running those lines of code again and again once for each pixel on the image. So the for-loop, the topic of the section, is gonna do exactly this and this is gonna be a big increase in what we can do with, with the code. So let me talk about the, the structure of this thing. I'm just going to identify the parts then I'll do an example. So here in the blue box here I have a picture of a for-loop and I'll just talk about what the parts are. So, it starts off - and I'll use my pen - this, this begins the for loop so it has the word for and then in parenthesis it says pixel colon image and then there's a left curly brace to start to set off the next line and so what this means is. And all the syntaxes require the parenthesis and the curly brace and everything. Usually in my examples or in the exercises we'll, it's just, it's the same every time, so usually we'll provide it and then just ask you to write the code on the following line. So what this means is, for every pixel in this image please to the following and then the following is to defined as whatever is in the colored braces here so. These lines. Inside of the thing. That's the, called the body of the for-loop. And this is just a few lines of code that can do, whatever we want. So, the way the for-loop works, is, and let's say we're, you know, working on the flowers image here. Is it. Here we have three lines. So it's gonna take, let's say, pixel number one of the whole image, the upper left pixel. And so it, it isolates pixel number one. And then the for-loop runs these, these first three lines. So it says; pixel.setRed(0), pixel.setGreen(0), pixel.setBlue(0). So those are all happening to pixel number one. And then it, really, what that does is it changes it to black, right? It sets red, green, and blue all to zero. So when the for-loop gets to the bottom a funny thing happens and I sort of have this black arrow. It loops back up to the top of the three lines and now it's gonna isolate pixel number two, so the second pixel, and then it runs these three lines again. So it does them to pixel two and then it loops back to the top and it runs the three lines again from pixel number three, and so on. It just runs the lines again and again and again once for each pixel in the image. So. The, oh the other thing I should point out here is you'll notice that the, the three lines in the body are indented and that not required but it's a, it's a common convention to show that the lines in the body are kind of different from the other lines of code. Where this image equals new simpleImage, well that just happens once and the print image that just happens once. But the lines inside the loop are sort of special in that they had this quality that they're going to be run again and again. So let's try. We just run that, that exact example. So here I have it in runnable code so the, this loads the image. Then I've got the, the for-loop setting off the body. Here's the three lines of the body. And then it, it's kind of small here but then there's a, a right curly brace sort of balancing the left curly brace up here that closes off the body. ونرى أنه في الواقع ، عشرة بكسل في عشرة بكسل. ويتم عرضها هنا في حجم 20x. في الواقع يمكنني تغيير هذا الرقم هنا. لذلك إذا قمت بتغيير هذا إلى عشرة ، ثم قم بتشغيلها مرة أخرى ثم حسنا ، حسنا ، الآن 20X فقط. وإذا وضعت مثل ، a ، 40 هنا ، وقم بتشغيله ، ثم حسنًا ، أكبر كثيرًا. لذلك سوف أعيدها إلى عشرون. هذا مجرد مثال أول على القليل من الكود ، لكننا نوع من السير في طريق القدرة على تحميل ومعالجة الصور. حسناً لجعل هذا أكثر إثارة للاهتمام قليلا. أريد تمديد الشفرة لتكون قادرًا على التعامل مع وحدات بكسل فردية ، فأنا أضع خطوطًا في منتصف الصورة البرنامج هنا ، لذلك هذا الخط بكسل = image.getPixel (0،0). ما هذا هل يذهب إلى الصورة وسيحصل على إشارة إلى بكسل معين أيا كان ، كلما كانت إحداثيات س ، ص نحدد هنا 0،0 أو يشير هذا إلى ، بكسل اليسار العلوي ، لذلك يحصل على إشارة إلى بكسل اليسار العلوي ويخزن ذلك في بكسل متغير ثم هذا السطر: pixel.setRed (255). الذي يستدعي وظيفة وقد دعا بكسل setRed وماذا ، ما يفعله setRed هو أنه يأخذ في أي رقم هنا بين قوسين ومهما كان هذا الرقم ، فإنه يأخذ ويضع القيمة الحمراء للبكسل ليكون هذا الرقم. لذلك ، سأعمل على هذا. نحن بحاجة لرؤية ماذا يفعل. وما تراه هو ، ما حصل عليه الكود هو الحصول على مرجع إلى هذا ، بكسل اليسار العلوي وكان أسود من قبل ، وتذكر ، تذكر يحتوي كل بكسل على الأرقام الثلاثة فيه ، الأحمر والأخضر والأزرق. وما هذا رمز يفعل ، ذهب إلى الرقم الأحمر وتغير إلى 255 ، مجرد تجاوز كل ما كان هناك من قبل. لذلك عندما نراها ، حسناً ، تظهر في صورة بكسل أحمر ، وبالتالي. هناك setRed لتغيير القيم الحمراء. هناك وظيفة مماثلة setGreen و setBlue. لذلك ، لدينا هذه الثلاثة ، setRed ، setGreen و setBlue. وهكذا ، مع هؤلاء ، يمكننا فقط تغيير القيم الحمراء والخضراء والزرقاء أيا كان ، أينما نريد. وبالتالي. أوه ، وسأذكرها جانباً لذا أنا ، أنا فقط ، كما تعلمون ، قدمت ثلاث وظائف. هناك هذه الصفحة منفصلة ، مرجع وظائف الصورة ، الذي يسرد فقط جميع الوظائف في الجدول ، وذلك بالنسبة للبعض في وقت لاحق التمرين ، قد تريد ، يمكنك أن ترى أنه إذا كنت تريد أن تتذكر ما وظيفة لا. ولكن عادةً بالنسبة للمحاضرات ، سأستخدم فقط ، إذا كنت سأستخدم وظيفة أنا فقط ، وأنا ذاهب سأتحدث عن ذلك. لذلك ، ما أريد القيام به ل شرح كيف ، كيف تعمل هذه الوظائف ، هو مجرد الذهاب من خلال مجموعة من الأمثلة. مجرد استخدامها لفعل شيء في الواقع. حسنا ، لذلك هنا ، وبالتالي ، فإن الشكل من هذا أنا عندي ، منطقة كود صغيرة هنا مع بعض الرموز المبدئية فيها. و ثم في هذا الجدول هنا ، لقد سردت مجموعة من التحديات الصغيرة مشاكل ، مثل ، أوه ، تعيين شيء ما ليكون أخضر أو أصفر أو أيا كان ، وسوف نذهب من خلالهم. لكل واحد من هذه ، على الجانب الأيمن هناك القليل زر العرض ، حتى تتمكن من النقر فوق ذلك لرؤية رمز الحل. في وقت لاحق يمكنك الذهاب إلى هذه الصفحة بنفسك والتجارب التي جربتها ، يمكنك فقط تجربة نفسك و حاول الاختلافات منهم أو أيا كان. حسنا ، لذلك دعونا نجرب هذا أول واحد. حسنا في الواقع ، هنا ، سوف أقوم بتشغيل الكود أولاً لمعرفة ما الذي يفعله. حسنًا ، صحيح الآن أصبح الأمر مجرد الحصول على بكسل (0،0) وتعيينه إلى اللون الأحمر. لذلك ، نوع من المشاهدة أنه قبل. حسنًا ، إذن ما المشكلة الأولى التي تقول؟ اضبط البكسل (0،0) ليكون أخضر. لذا فإن النموذج هنا ، باللغة الإنجليزية ، سيقول ، حسنًا ، إليكم بعض التأثيرات مثلك للحصول على ومعنى الخطوات التي نمر بها هنا للتفكير حسنا ، ماذا سيكون في مجال التعليمات البرمجية ، من حيث المكالمات وظيفة والأرقام. ما هي سلسلة العمليات التي نريد القيام بها لتحقيق هذا التأثير؟ لذلك أنت لطيف ترجمة أساسا من الإنجليزية إلى الكمبيوتر. لذلك في هذه الحالة يقال ليتم تعيين الأخضر. فما أريد القيام به للقيام بذلك ، هو بدلاً من استدعاء setRed وظيفة ، أنا فقط تغييره لاستدعاء setGreen. لذلك دعونا نجرب ذلك. وها نحن نذهب. يجب أن نحصل على بكسل أخضر بدلاً من ذلك. دعونا نحاول واحد القادم. التالي يقول تعيين بكسل (0،0) ليكون أصفر. حسنًا ، حسنًا ، لكي يظهر البيكسل الأصفر ، ما أريده هو أن تكون كل من القيم الحمراء والخضراء 255. أنت تعرف ، الأصفر يساوي الأحمر زائد الأخضر. للقيام بذلك ، لتغيير كل من الأحمر و أخضر. سأعمل على نسخ هذا السطر ، وسألصقه هنا. وسوف أتغير فقط هذا واحد إلى اللون الأحمر. لذلك ، أنا أعتمد على حقيقة أنه بمجرد الحصول على المرجع إلى بكسل ، يمكنني أن أفعل أشياء متعددة لذلك. لذلك ، على ، في هذا السطر الأول ، أدعو setRed ، أقوم بتغيير القيمة الحمراء. وبعد ذلك يمكنني الاتصال setGreen في السطر التالي إلى تغيير الأخضر. وسوف ، سوف يمر الكود ويقوم بكل واحد من هؤلاء الأشياء داخليا. لذلك دعونا نجرب ذلك. وبالتأكيد ، الآن أحصل على اللون الأصفر. لذلك أنا ، هذا kinda يعود إلى فكرة أن هناك هذا بكسل. انها حقا كان مجرد هذه الأرقام الثلاثة هنا. وهنا أنا أكتب رمز سطر بسطر للوصول كيندا في هناك وتغيير هذه الأرقام. دعونا نحاول واحد القادم. اضبط البكسل 1،0 ليكون الأصفر. أين هو هذا بكسل؟ and see it is in fact, ten pixels by ten pixels. And it's being displayed here at 20x size. So actually I could change this number here. So if I change this to a ten, and then run it again then okay, well, now it's only 20X. And if I put like, a, a 40 here, and run it, then okay, it a lot bigger. So I'll put it back to twenty. So that's just a first example of a little bit of code, but we're sort of going down the path of being able to load and manipulate images. Right, so to make this a little more interesting. I wanna extend the code to be able to deal with individual pixels so I'm a add a, a couple lines in the middle of the a program here, so this line pixel=image.getPixel(0,0). What that does it goes to the image and its gonna get a reference to a particular pixel whatever, whenever x, y coordinates we specify here so 0,0 or this refers to the, the upper left pixel, so it gets reference to the upper left pixel and stores that in a variable pixel and then this line: pixel.setRed(255). That calls a function a pixel has called setRed and what the, what setRed does is it takes in any number here between the parentheses and whatever that number is, it takes it in and it sets the red value of the pixel to be that number. So, I'm gonna run this. We need to see what it does. And what you see is, what the code has done is obtained a reference to this, the upper left pixel and it was black before and it, remember, recall each, each pixel has the three numbers in it, red, green and blue. And so what this code does, it went to the red number and it changed to 255, just overriding whatever was there before. So when we see it, well okay it shows up as a red pixel, so. There's a setRed to change the red values. There's an analogous function setGreen and setBlue. So, we have these three, setRed, setGreen and setBlue. And, so, with those, we can just change the red, green and blue values to be whatever, wherever we want. So. Oh, and I'll mention it as an aside so there I, I just, you know, introduced three functions. There's this separate page, Image Functions Reference, that just lists all the functions in a table, so for some later exercise, you might wanna, you can go see that if you want to remember what a function does. But usually for the lectures I will just, if I'm gonna use a function I'll just, as I'm going I'll talk about it. So, what I want to do to demonstrate how, how these functions work, is just go through a bunch of examples. Just use them to actually do something. Alright, so here are, so the, the format of this is I've got, a little code area here with some starter code in it. And then in this table down here, I've just listed a bunch of little, challenge problems, like, oh, set something to be green or yellow or whatever, and we'll go through them. For each one of these, on the right hand side there's this little show button, so you can click that to see the solution code. So later on you can go to this page yourself and the experiments I've tried you can just try yourself and try variations of them or whatever. Alright, so let's try this first one. Well actually, here, I'll, I'll run the code first to see what it does. Okay, so right now it's just getting pixel (0,0) and setting it to red. So that, sort of seen that before. Alright, so what's the first problem saying? Set pixel (0,0) to be green. So the form here, is in English, it will say, well here's some effect we'd like you to get and in sense the steps we're going through here to think about well, what would be in the domain of code, in terms of function calls and numbers. What are the series of operations we want to do to get that effect? So you're sort of translating essentially from English into computer. So in this case it's said to be set green. So what I want to do to do that, is instead of calling the setRed function, I'll just change it to call setGreen. So lets try that. And there we go. We gotta a green pixel instead. Lets try the next one. The next one says set pixel (0,0) to be yellow. So right, well so, in order for the pixel to appear yellow, what I want is for both the red and green values to be 255. You know, yellow equals red plus green. So to do that, to change both the red and the green. I'm gonna copy this line, and I'll paste it in here. And I'll just change this one to red. So, I'm, I'm relying on the fact that, once I've got the reference to pixel, I can do multiple things to it. So, on, on this first line, I call setRed, I change the red value. And then I can call setGreen on the next line to change the green. And it'll, the code will just go through and do each one of those things internally. So let's try that. And sure enough, now I get yellow. So I've, this sorta goes back to the idea that there is this pixel. It really just had these three numbers in here. And here I'm writing code line by line to kinda reach in there and change those numbers. Let's try the next one. Set pixel 1,0 to be yellow. Where is that pixel? الصورة للحصول على حلقة في هذا القسم ، سننظر إلى بنية "for loop" ، والتي يمكن تشغيلها قليلاً من الكود آلاف المرات - وهي زيادة كبيرة في القوة المتاحة لنا. ازهار صفراء flowers.jpg بعرض 457 بكسل ارتفاع 360 بكسل - 164.520 بكسل رمز التشغيل بكسل واحد في وقت واحد ... غير عملي تريد: نحدد بعض الكودات ، يقوم الكمبيوتر بتشغيله مرارًا وتكرارًا ، مرة واحدة لكل بكسل "For loop" يفعل هذا - زيادة كبيرة في قوة التعليمات البرمجية لدينا الوصول إلى بكسل واحد في المرة الواحدة ، على سبيل المثال بكسل في (0 ، 0) ، ثم بكسل في (1 ، 0) ، وما إلى ذلك ليست طريقة جيدة للعمل على صورة قد تحتوي على 100000 بكسل أو أكثر. نود أن نقول شيئًا مثل "لكل بكسل تفعل ذلك" ، ونترك الكمبيوتر يتلاعب بتفاصيل استعراض كل القيم (س ، ص) للنظر في كل بكسل مرة واحدة. يوفر بنية "for loop" القوية للغاية التي سنتعلمها هنا هذا بالضبط "لكل بكسل تفعل هذه" الميزة. تأخذ الحلقة بضعة أسطر من الشفرة الخاصة بنا ، وتعمل هذه الخطوط مرارًا وتكرارًا ، مرة واحدة لكل بكسل في الصورة. ل حلقة هيكل بناء الجملة: لـ (بكسل: صورة) {...} يبدأ في حلقة ، بناء جملة كل المطلوب ، المسافة البادئة "الجسم" رمز داخل {...} يدير خطوط الجسم للبكسل رقم 1 يعود إلى الجزء العلوي من الجسم ، يعمل على بكسل رقم 2 يعمل مرارا وتكرارا ، مرة واحدة لكل بكسل في الصورة لكل بكسل: (افعل ما يقوله رمز الجسم) أجزاء من الحلقة على سبيل المثال حلقة 1 تعيين الأحمر والأخضر والأزرق الكل إلى 0 (ل 164.520 بكسل). ماذا يفعل هذا؟ ماذا لو وضعنا اللون الأحمر والأخضر والأزرق على 255؟ خطوط الجسم 3: تعيين الأحمر والأخضر والأزرق جميع إلى 0 يعمل For-loop على تشغيل هذه الخطوط ، مرة واحدة لكل بكسل ما هي النتيجة؟ صورة = SimpleImage جديدة ("flowers.jpg") ؛ لـ (بكسل: صورة) { pixel.setRed (0)؛ pixel.setGreen (0)؛ pixel.setBlue (0)؛ } طباعة (صورة)؛ لكل بكسل ، يعين كود الجسم القيم الحمراء والخضراء والزرقاء جميعها تكون 0. والنتيجة هي مستطيل أسود خالص. لم يتم ترك أي من بيانات الزهرة الأصلية ؛ كل شيء حصل على تغيير إلى الأصفار. على سبيل المثال حلقة 2 لكل بكسل ، اضبط اللون الأحمر والأخضر على 255 ، والأزرق على 0 ما هو كود الجسم للقيام بذلك؟ ما هي النتيجة؟ صورة = SimpleImage جديدة ("flowers.jpg") ؛ لـ (بكسل: صورة) { pixel.setRed (255)؛ pixel.setGreen (255)؛ pixel.setBlue (0)؛ } طباعة (صورة)؛ النتيجة هي مستطيل أصفر صلب. تقوم الشفرة بالكتابة فوق بيانات الزهرة ، وتغيير كل بكسل في الصورة الأصلية إلى بكسل أصفر نقي. على سبيل المثال حلقة 3 الأمثلة السابقة الكتابة فوق جميع البيانات زهرة ... غير واقعية العمل مع البيانات في flowers.jpg الزهور الصفراء - القيم الحمراء والخضراء عالية لكل بكسل ، اضبط اللون الأحمر على 0 ما هو كود الجسم للقيام بذلك؟ ما هي النتيجة؟ (ليس مطلوبًا أن تتمكن من التنبؤ بنتيجة عمليات RGB) ازهار صفراء انظر مرة أخرى إلى flowers.jpg. الأصفر مصنوع أو أحمر + أخضر ، لذلك نحن نعرف أن الأجزاء الصفراء من الصورة لها قيم حمراء وخضراء عالية. فماذا يحدث إذا ، لكل بكسل ، وضعنا الأحمر إلى 0؟ ما هي قيم RGB للبكسل نموذجي على الزهور الصفراء تبدو قبل تشغيل هذه الحلقة؟ ماذا بعد؟ صورة = SimpleImage جديدة ("flowers.jpg") ؛ لـ (بكسل: صورة) { pixel.setRed (0)؛ } طباعة (صورة)؛ كود الجسم pixel.setRed (0)؛ يتم تشغيله بواسطة الحلقة مرارًا وتكرارًا ، مرة واحدة لكل بكسل في الصورة. نظرًا لأن الزهور الصفراء مصنوعة من ضوء أحمر + أخضر ، فإن تعيين الأحمر إلى 0 لكل نتائج بكسل هو زهور خضراء. لا تتغير الأوراق الخضراء كثيرًا ، حيث كانت قيمها الحمراء بالقرب من 0 على أي حال. على سبيل المثال حلقة 4 لكل بكسل ، اضبط اللون الأخضر والأزرق على 0 ما هو كود الجسم للقيام بذلك؟ وتعرف النتيجة باسم "القناة الحمراء" رؤية صورة لمناطق الضوء الأحمر فقط صورة = SimpleImage جديدة ("flowers.jpg") ؛ لـ (بكسل: صورة) { pixel.setGreen (0)؛ pixel.setBlue (0)؛ } طباعة (صورة)؛ تعيين اللون الأخضر والأزرق إلى 0 في كل مكان ، كل ما تبقى هو منطقة الضوء الأحمر التي دخلت الصورة الأصلية ، ويعرف أيضًا باسم "القناة الحمراء" للصورة. الضوء الأحمر هو الأبرز في مجال الزهور الصفراء ، وهو أمر منطقي لأننا نعرف أن الأصفر = أحمر + أخضر. للاستنتاجات حلقة For-loop هي ميزة قوية للغاية ملاحظة: جافا سكريبت ليس لديها هذه الميزة ، أضفتها إلى CS101 نكتب رمز الجسم للتأثير الذي نريده يعالج الكمبيوتر مسك الدفاتر لتكرار كل وحدات البكسل الكمبيوتر = قوي + موضوع غبي حلقة: قوية ، ولكن الميكانيكية القسم التالي - يحول صورة أكثر إثارة للاهتمام Image For-Loop In this section, we'll look at the "for loop" construct, which can run a bit of code thousands of times -- a big increase in the power available to us. yellow flowers flowers.jpg is 457 pixels wide by 360 pixels high -- 164,520 pixels Code operating one pixel at a time ... not practical Want: we specify some code, computer runs it again and again, once for each pixel "For loop" does this -- big increase in the power of our code Accessing one pixel at a time, e.g. pixel at (0, 0), then the pixel at (1, 0), etc. is not a good way to work on an image which may have 100,000 or more pixels. We'd like to say something like "for each pixel do this", and let the computer fiddle with the details of going through all the (x, y) values to look at each pixel once. The very powerful "for loop" structure we'll learn here provides exactly this "for each pixel do this" feature. The loop takes a few lines of our code, and runs those lines again and again, once for each pixel in the image. For-Loop Structure Syntax: for (pixel: image) { ... } Starts the for loop, syntax all required, indentation "body" code inside the { ... } Runs body lines for pixel #1 Goes back to top of body, runs for pixel #2 Runs again and again, once for each pixel in the image For each pixel: (do what the body code says) parts of the for-loop For-Loop Example 1 Setting red, green, and blue all to 0 (for 164,520 pixels). What does that do? What if we set red, green, and blue all to 255? Body 3 lines: set red, green, and blue all to 0 For-loop runs those lines, once for each pixel What is the result? image = new SimpleImage("flowers.jpg"); for (pixel: image) { pixel.setRed(0); pixel.setGreen(0); pixel.setBlue(0); } print(image); For each pixel, the body code sets the red, green, and blue values all to be 0. The result is a pure black rectangle. None of the original flower data is left; it all got changed to zeros. For-Loop Example 2 For each pixel, set red and green to 255, blue to 0 What is the body code to do this? What is the result? image = new SimpleImage("flowers.jpg"); for (pixel: image) { pixel.setRed(255); pixel.setGreen(255); pixel.setBlue(0); } print(image); Result is a solid yellow rectangle. The code overwrites the flower data, changing each pixel in the original image into a pure yellow pixel. For-Loop Example 3 Previous examples overwrote all the flower data ... not realistic Work with the data in flowers.jpg Yellow flowers -- red and green values high For each pixel, set red to 0 What is the body code to do this? What is the result? (Not required that you have can predict the result of the RGB operations) yellow flowers Look again at flowers.jpg.Yellow is made or red + green, so we know that the yellow parts of the image have high red and green values. So what happens if, for each pixel, we set red to 0? What are the RGB values for a typical pixel on the yellow flowers look like before this loop runs? What about after? image = new SimpleImage("flowers.jpg"); for (pixel: image) { pixel.setRed(0); } print(image); The body code pixel.setRed(0); is run by the loop again and again, once for each pixel in the image. Since the yellow flowers are made with red + green light, setting the red to 0 for each pixel results is greenish flowers. The green leaves aren't changed much, since their red values were near 0 anyway. For-Loop Example 4 For each pixel, set green and blue to 0 What is the body code to do this? The result is known as the "red channel" Seeing an image of just the red light areas image = new SimpleImage("flowers.jpg"); for (pixel: image) { pixel.setGreen(0); pixel.setBlue(0); } print(image); Setting green and blue to 0 everywhere, all that is left is the area of red light that went into the original image, aka the "red channel" of the image. The red light is most prominent for the area of yellow flowers, which makes sense as we know that yellow = red + green. For-Loop Conclusions For-loop is a very powerful feature Note: Javascript does not have this feature, I added it for CS101 We write the body code for the effect we want Computer handles the bookkeeping to repeat over all the pixels Computer = powerful + stupid theme Loop: powerful, but mechanical Next section - more interesting image transforms |
إذن موضوع هذا القسم ، هو ما يُسمى بـ "الحلقة". وهذا سيكون أ زيادة كبيرة في ما يمكننا القيام به مع رمز. لذلك ، إذا نظرت إلى الأصل صورة الزهور ، هنا ، يبلغ عرضها 457 بكسل ارتفاع 360 بكسل. اذا انت اضرب فقط لتحصل على العدد الإجمالي للبكسل وهو 164000 بكسل وعدد قليل من الأفراد بكسل. وهذه صورة صغيرة جدا. لذلك ، هذا هو الكثير من بكسل. هكذا نحن تم كتابة التعليمات البرمجية من قبل ، حيث سيكون لديك خط مثل pixel.setRed (255) إلى تغيير بكسل واحد إلى اللون الأحمر ، هذا فقط ، هذه ليست طريقة عملية للقيام بذلك العملية على صورة كاملة. أعني ، هذه صورة صغيرة ولديها أكثر من 100000 بكسل. إذن ما نريده هو إنشاء حيث يمكننا كتابة بضعة أسطر من التعليمات البرمجية أن التقاط بعض التغيير الذي نريد القيام به ومن ثم السماح للكمبيوتر برعاية مسك الدفاتر من تشغيل هذه الخطوط من التعليمات البرمجية مرارا وتكرارا مرة واحدة لكل بكسل على صورة. لذا فإن الحلقة ، موضوع القسم ، هي أن تفعل هذا بالضبط وهذا سيكون زيادة كبيرة في ما يمكننا القيام به ، مع الكود. لذلك اسمحوا لي أن أتحدث حول ، هيكل هذا الشيء. أنا فقط ذاهب لتحديد الأجزاء ثم سأفعل مثالا. حتى هنا في المربع الأزرق هنا لدي صورة ل حلقة سأتحدث فقط عن الأجزاء. لذلك ، يبدأ - وسأستخدم بلدي القلم - وهذا ، يبدأ بـ الحلقة للحصول على الكلمة لـ ومن ثم بين قوسين يقول صورة القولون بكسل ومن ثم هناك هدفين مجعد الأيسر لبدء الانطلاق السطر التالي وماذا يعني هذا. وجميع بناء الجملة تتطلب الأقواس والقوس المجعد وكل شيء. عادة في الأمثلة أو في التدريبات سنقوم بذلك فقط في كل مرة ، لذلك سنوفرها عادةً وبعد ذلك فقط اطلب منك كتابة التعليمات البرمجية على السطر التالي. إذن ما يعنيه هذا هو ، من أجل كل بكسل في هذه الصورة ، يرجى التالي ، ثم التالي هو: كما هو محدد في الأقواس الملونة هنا. هذه الخطوط. داخل الشيء. هذا هو ، ودعا الجسم من أجل حلقة. وهذا هو فقط بضعة أسطر من التعليمات البرمجية التي يمكن القيام بها ، كل ما نريد. لذلك ، فإن الطريق تعمل for-loop ، ودعنا نقول أننا ، كما تعلمون ، نعمل على صورة الزهور هنا. فعلا. هنا لدينا ثلاثة خطوط. لذلك سوف يأخذ ، دعنا نقول ، بكسل رقم واحد من الصورة كاملة ، بكسل اليسار العلوي. وهكذا ، فإنه يعزل بكسل رقم واحد. وثم يدير هذه الحلقة ، هذه الأسطر الثلاثة الأولى. هكذا تقول ؛ pixel.setRed (0)، pixel.setGreen (0) ، pixel.setBlue (0). هذه كلها يحدث لبكسل رقم واحد. ثم ، في الحقيقة ، ما يفعله هو أنه يغيره إلى أسود ، أليس كذلك؟ يضبط اللون الأحمر والأخضر والأزرق على الصفر. لذلك عندما يحصل على حلقة ل الجزء السفلي يحدث شيء مضحك ولدي نوع من هذا السهم الأسود. انها حلقات نسخ احتياطي إلى الجزء العلوي من الخطوط الثلاثة والآن ستعمل عزل بكسل رقم اثنين ، لذلك بكسل الثاني ، ومن ثم يتم تشغيل هذه الخطوط الثلاثة مرة أخرى. هكذا يفعلهم إلى البيكسل اثنين ، ثم يعود إلى الأعلى ويقوم بتشغيل الخطوط الثلاثة مرة أخرى من بكسل رقم ثلاثة ، وهلم جرا. يعمل فقط الخطوط مرارا وتكرارا وتكرارا مرة واحدة لكل بكسل في الصورة. وبالتالي. و ، الشيء الآخر الذي أود الإشارة إليه هنا هل ستلاحظ أن ، الأسطر الثلاثة في الجسم هي بادئة وهذا لا مطلوب ولكن هذا هو ، انها اتفاقية شائعة لإظهار أن الخطوط في الجسم نوع مختلف عن سطور الكود الأخرى. حيث تساوي هذه الصورة الجديدة simpleImage ، حسناً ما يحدث مرة واحدة فقط والصورة المطبوعة التي تحدث مرة واحدة فقط. لكن الخطوط الموجودة داخل الحلقة مميزة نوعًا ما لأنها تتمتع بهذه الجودة سوف يتم تشغيلهم مرارًا وتكرارًا. اذا لنجرب. نحن فقط تشغيل هذا بالضبط مثال. حتى هنا لدي في رمز runnable لذلك ، هذا يحمّل الصورة. ثم لقد حصلت على ، حلقة for-off off the body. ها هي الخطوط الثلاثة لل الجسم. وبعد ذلك ، إنه نوع صغير هنا ولكن بعد ذلك ، هناك دعامة مجعد الأيمن نوع من التوازن بين هدفين مجعد اليسار هنا أن يغلق الجسم. So the topic of this section, is what's called a for-loop. And this is going to be a big increase in what we can do with the code. So, if you look at the original flowers image, here, it's 457 pixels wide by 360 pixels high. So, if you multiply just to get the total number of pixels that's 164,000 and a few odd pixels. And this is a pretty small image. So, that's a lot of pixels. So the way we were writing code before, where you would have a line like pixel.setRed(255) to change one pixel to red, that's just, that's not a practical way to do an operation on a whole image. I mean, this is a small image and has over 100,000 pixels. So what we want is a construct where we can write a few lines of code that capture some change we want to make and then let the computer take care of the bookkeeping of running those lines of code again and again once for each pixel on the image. So the for-loop, the topic of the section, is gonna do exactly this and this is gonna be a big increase in what we can do with, with the code. So let me talk about the, the structure of this thing. I'm just going to identify the parts then I'll do an example. So here in the blue box here I have a picture of a for-loop and I'll just talk about what the parts are. So, it starts off - and I'll use my pen - this, this begins the for loop so it has the word for and then in parenthesis it says pixel colon image and then there's a left curly brace to start to set off the next line and so what this means is. And all the syntaxes require the parenthesis and the curly brace and everything. Usually in my examples or in the exercises we'll, it's just, it's the same every time, so usually we'll provide it and then just ask you to write the code on the following line. So what this means is, for every pixel in this image please to the following and then the following is to defined as whatever is in the colored braces here so. These lines. Inside of the thing. That's the, called the body of the for-loop. And this is just a few lines of code that can do, whatever we want. So, the way the for-loop works, is, and let's say we're, you know, working on the flowers image here. Is it. Here we have three lines. So it's gonna take, let's say, pixel number one of the whole image, the upper left pixel. And so it, it isolates pixel number one. And then the for-loop runs these, these first three lines. So it says; pixel.setRed(0), pixel.setGreen(0), pixel.setBlue(0). So those are all happening to pixel number one. And then it, really, what that does is it changes it to black, right? It sets red, green, and blue all to zero. So when the for-loop gets to the bottom a funny thing happens and I sort of have this black arrow. It loops back up to the top of the three lines and now it's gonna isolate pixel number two, so the second pixel, and then it runs these three lines again. So it does them to pixel two and then it loops back to the top and it runs the three lines again from pixel number three, and so on. It just runs the lines again and again and again once for each pixel in the image. So. The, oh the other thing I should point out here is you'll notice that the, the three lines in the body are indented and that not required but it's a, it's a common convention to show that the lines in the body are kind of different from the other lines of code. Where this image equals new simpleImage, well that just happens once and the print image that just happens once. But the lines inside the loop are sort of special in that they had this quality that they're going to be run again and again. So let's try. We just run that, that exact example. So here I have it in runnable code so the, this loads the image. Then I've got the, the for-loop setting off the body. Here's the three lines of the body. And then it, it's kind of small here but then there's a, a right curly brace sort of balancing the left curly brace up here that closes off the body. ونرى أنه في الواقع ، عشرة بكسل في عشرة بكسل. ويتم عرضها هنا في حجم 20x. في الواقع يمكنني تغيير هذا الرقم هنا. لذلك إذا قمت بتغيير هذا إلى عشرة ، ثم قم بتشغيلها مرة أخرى ثم حسنا ، حسنا ، الآن 20X فقط. وإذا وضعت مثل ، a ، 40 هنا ، وقم بتشغيله ، ثم حسنًا ، أكبر كثيرًا. لذلك سوف أعيدها إلى عشرون. هذا مجرد مثال أول على القليل من الكود ، لكننا نوع من السير في طريق القدرة على تحميل ومعالجة الصور. حسناً لجعل هذا أكثر إثارة للاهتمام قليلا. أريد تمديد الشفرة لتكون قادرًا على التعامل مع وحدات بكسل فردية ، فأنا أضع خطوطًا في منتصف الصورة البرنامج هنا ، لذلك هذا الخط بكسل = image.getPixel (0،0). ما هذا هل يذهب إلى الصورة وسيحصل على إشارة إلى بكسل معين أيا كان ، كلما كانت إحداثيات س ، ص نحدد هنا 0،0 أو يشير هذا إلى ، بكسل اليسار العلوي ، لذلك يحصل على إشارة إلى بكسل اليسار العلوي ويخزن ذلك في بكسل متغير ثم هذا السطر: pixel.setRed (255). الذي يستدعي وظيفة وقد دعا بكسل setRed وماذا ، ما يفعله setRed هو أنه يأخذ في أي رقم هنا بين قوسين ومهما كان هذا الرقم ، فإنه يأخذ ويضع القيمة الحمراء للبكسل ليكون هذا الرقم. لذلك ، سأعمل على هذا. نحن بحاجة لرؤية ماذا يفعل. وما تراه هو ، ما حصل عليه الكود هو الحصول على مرجع إلى هذا ، بكسل اليسار العلوي وكان أسود من قبل ، وتذكر ، تذكر يحتوي كل بكسل على الأرقام الثلاثة فيه ، الأحمر والأخضر والأزرق. وما هذا رمز يفعل ، ذهب إلى الرقم الأحمر وتغير إلى 255 ، مجرد تجاوز كل ما كان هناك من قبل. لذلك عندما نراها ، حسناً ، تظهر في صورة بكسل أحمر ، وبالتالي. هناك setRed لتغيير القيم الحمراء. هناك وظيفة مماثلة setGreen و setBlue. لذلك ، لدينا هذه الثلاثة ، setRed ، setGreen و setBlue. وهكذا ، مع هؤلاء ، يمكننا فقط تغيير القيم الحمراء والخضراء والزرقاء أيا كان ، أينما نريد. وبالتالي. أوه ، وسأذكرها جانباً لذا أنا ، أنا فقط ، كما تعلمون ، قدمت ثلاث وظائف. هناك هذه الصفحة منفصلة ، مرجع وظائف الصورة ، الذي يسرد فقط جميع الوظائف في الجدول ، وذلك بالنسبة للبعض في وقت لاحق التمرين ، قد تريد ، يمكنك أن ترى أنه إذا كنت تريد أن تتذكر ما وظيفة لا. ولكن عادةً بالنسبة للمحاضرات ، سأستخدم فقط ، إذا كنت سأستخدم وظيفة أنا فقط ، وأنا ذاهب سأتحدث عن ذلك. لذلك ، ما أريد القيام به ل شرح كيف ، كيف تعمل هذه الوظائف ، هو مجرد الذهاب من خلال مجموعة من الأمثلة. مجرد استخدامها لفعل شيء في الواقع. حسنا ، لذلك هنا ، وبالتالي ، فإن الشكل من هذا أنا عندي ، منطقة كود صغيرة هنا مع بعض الرموز المبدئية فيها. و ثم في هذا الجدول هنا ، لقد سردت مجموعة من التحديات الصغيرة مشاكل ، مثل ، أوه ، تعيين شيء ما ليكون أخضر أو أصفر أو أيا كان ، وسوف نذهب من خلالهم. لكل واحد من هذه ، على الجانب الأيمن هناك القليل زر العرض ، حتى تتمكن من النقر فوق ذلك لرؤية رمز الحل. في وقت لاحق يمكنك الذهاب إلى هذه الصفحة بنفسك والتجارب التي جربتها ، يمكنك فقط تجربة نفسك و حاول الاختلافات منهم أو أيا كان. حسنا ، لذلك دعونا نجرب هذا أول واحد. حسنا في الواقع ، هنا ، سوف أقوم بتشغيل الكود أولاً لمعرفة ما الذي يفعله. حسنًا ، صحيح الآن أصبح الأمر مجرد الحصول على بكسل (0،0) وتعيينه إلى اللون الأحمر. لذلك ، نوع من المشاهدة أنه قبل. حسنًا ، إذن ما المشكلة الأولى التي تقول؟ اضبط البكسل (0،0) ليكون أخضر. لذا فإن النموذج هنا ، باللغة الإنجليزية ، سيقول ، حسنًا ، إليكم بعض التأثيرات مثلك للحصول على ومعنى الخطوات التي نمر بها هنا للتفكير حسنا ، ماذا سيكون في مجال التعليمات البرمجية ، من حيث المكالمات وظيفة والأرقام. ما هي سلسلة العمليات التي نريد القيام بها لتحقيق هذا التأثير؟ لذلك أنت لطيف ترجمة أساسا من الإنجليزية إلى الكمبيوتر. لذلك في هذه الحالة يقال ليتم تعيين الأخضر. فما أريد القيام به للقيام بذلك ، هو بدلاً من استدعاء setRed وظيفة ، أنا فقط تغييره لاستدعاء setGreen. لذلك دعونا نجرب ذلك. وها نحن نذهب. يجب أن نحصل على بكسل أخضر بدلاً من ذلك. دعونا نحاول واحد القادم. التالي يقول تعيين بكسل (0،0) ليكون أصفر. حسنًا ، حسنًا ، لكي يظهر البيكسل الأصفر ، ما أريده هو أن تكون كل من القيم الحمراء والخضراء 255. أنت تعرف ، الأصفر يساوي الأحمر زائد الأخضر. للقيام بذلك ، لتغيير كل من الأحمر و أخضر. سأعمل على نسخ هذا السطر ، وسألصقه هنا. وسوف أتغير فقط هذا واحد إلى اللون الأحمر. لذلك ، أنا أعتمد على حقيقة أنه بمجرد الحصول على المرجع إلى بكسل ، يمكنني أن أفعل أشياء متعددة لذلك. لذلك ، على ، في هذا السطر الأول ، أدعو setRed ، أقوم بتغيير القيمة الحمراء. وبعد ذلك يمكنني الاتصال setGreen في السطر التالي إلى تغيير الأخضر. وسوف ، سوف يمر الكود ويقوم بكل واحد من هؤلاء الأشياء داخليا. لذلك دعونا نجرب ذلك. وبالتأكيد ، الآن أحصل على اللون الأصفر. لذلك أنا ، هذا kinda يعود إلى فكرة أن هناك هذا بكسل. انها حقا كان مجرد هذه الأرقام الثلاثة هنا. وهنا أنا أكتب رمز سطر بسطر للوصول كيندا في هناك وتغيير هذه الأرقام. دعونا نحاول واحد القادم. اضبط البكسل 1،0 ليكون الأصفر. أين هو هذا بكسل؟ and see it is in fact, ten pixels by ten pixels. And it's being displayed here at 20x size. So actually I could change this number here. So if I change this to a ten, and then run it again then okay, well, now it's only 20X. And if I put like, a, a 40 here, and run it, then okay, it a lot bigger. So I'll put it back to twenty. So that's just a first example of a little bit of code, but we're sort of going down the path of being able to load and manipulate images. Right, so to make this a little more interesting. I wanna extend the code to be able to deal with individual pixels so I'm a add a, a couple lines in the middle of the a program here, so this line pixel=image.getPixel(0,0). What that does it goes to the image and its gonna get a reference to a particular pixel whatever, whenever x, y coordinates we specify here so 0,0 or this refers to the, the upper left pixel, so it gets reference to the upper left pixel and stores that in a variable pixel and then this line: pixel.setRed(255). That calls a function a pixel has called setRed and what the, what setRed does is it takes in any number here between the parentheses and whatever that number is, it takes it in and it sets the red value of the pixel to be that number. So, I'm gonna run this. We need to see what it does. And what you see is, what the code has done is obtained a reference to this, the upper left pixel and it was black before and it, remember, recall each, each pixel has the three numbers in it, red, green and blue. And so what this code does, it went to the red number and it changed to 255, just overriding whatever was there before. So when we see it, well okay it shows up as a red pixel, so. There's a setRed to change the red values. There's an analogous function setGreen and setBlue. So, we have these three, setRed, setGreen and setBlue. And, so, with those, we can just change the red, green and blue values to be whatever, wherever we want. So. Oh, and I'll mention it as an aside so there I, I just, you know, introduced three functions. There's this separate page, Image Functions Reference, that just lists all the functions in a table, so for some later exercise, you might wanna, you can go see that if you want to remember what a function does. But usually for the lectures I will just, if I'm gonna use a function I'll just, as I'm going I'll talk about it. So, what I want to do to demonstrate how, how these functions work, is just go through a bunch of examples. Just use them to actually do something. Alright, so here are, so the, the format of this is I've got, a little code area here with some starter code in it. And then in this table down here, I've just listed a bunch of little, challenge problems, like, oh, set something to be green or yellow or whatever, and we'll go through them. For each one of these, on the right hand side there's this little show button, so you can click that to see the solution code. So later on you can go to this page yourself and the experiments I've tried you can just try yourself and try variations of them or whatever. Alright, so let's try this first one. Well actually, here, I'll, I'll run the code first to see what it does. Okay, so right now it's just getting pixel (0,0) and setting it to red. So that, sort of seen that before. Alright, so what's the first problem saying? Set pixel (0,0) to be green. So the form here, is in English, it will say, well here's some effect we'd like you to get and in sense the steps we're going through here to think about well, what would be in the domain of code, in terms of function calls and numbers. What are the series of operations we want to do to get that effect? So you're sort of translating essentially from English into computer. So in this case it's said to be set green. So what I want to do to do that, is instead of calling the setRed function, I'll just change it to call setGreen. So lets try that. And there we go. We gotta a green pixel instead. Lets try the next one. The next one says set pixel (0,0) to be yellow. So right, well so, in order for the pixel to appear yellow, what I want is for both the red and green values to be 255. You know, yellow equals red plus green. So to do that, to change both the red and the green. I'm gonna copy this line, and I'll paste it in here. And I'll just change this one to red. So, I'm, I'm relying on the fact that, once I've got the reference to pixel, I can do multiple things to it. So, on, on this first line, I call setRed, I change the red value. And then I can call setGreen on the next line to change the green. And it'll, the code will just go through and do each one of those things internally. So let's try that. And sure enough, now I get yellow. So I've, this sorta goes back to the idea that there is this pixel. It really just had these three numbers in here. And here I'm writing code line by line to kinda reach in there and change those numbers. Let's try the next one. Set pixel 1,0 to be yellow. Where is that pixel? الصورة للحصول على حلقة في هذا القسم ، سننظر إلى بنية "for loop" ، والتي يمكن تشغيلها قليلاً من الكود آلاف المرات - وهي زيادة كبيرة في القوة المتاحة لنا. ازهار صفراء flowers.jpg بعرض 457 بكسل ارتفاع 360 بكسل - 164.520 بكسل رمز التشغيل بكسل واحد في وقت واحد ... غير عملي تريد: نحدد بعض الكودات ، يقوم الكمبيوتر بتشغيله مرارًا وتكرارًا ، مرة واحدة لكل بكسل "For loop" يفعل هذا - زيادة كبيرة في قوة التعليمات البرمجية لدينا الوصول إلى بكسل واحد في المرة الواحدة ، على سبيل المثال بكسل في (0 ، 0) ، ثم بكسل في (1 ، 0) ، وما إلى ذلك ليست طريقة جيدة للعمل على صورة قد تحتوي على 100000 بكسل أو أكثر. نود أن نقول شيئًا مثل "لكل بكسل تفعل ذلك" ، ونترك الكمبيوتر يتلاعب بتفاصيل استعراض كل القيم (س ، ص) للنظر في كل بكسل مرة واحدة. يوفر بنية "for loop" القوية للغاية التي سنتعلمها هنا هذا بالضبط "لكل بكسل تفعل هذه" الميزة. تأخذ الحلقة بضعة أسطر من الشفرة الخاصة بنا ، وتعمل هذه الخطوط مرارًا وتكرارًا ، مرة واحدة لكل بكسل في الصورة. ل حلقة هيكل بناء الجملة: لـ (بكسل: صورة) {...} يبدأ في حلقة ، بناء جملة كل المطلوب ، المسافة البادئة "الجسم" رمز داخل {...} يدير خطوط الجسم للبكسل رقم 1 يعود إلى الجزء العلوي من الجسم ، يعمل على بكسل رقم 2 يعمل مرارا وتكرارا ، مرة واحدة لكل بكسل في الصورة لكل بكسل: (افعل ما يقوله رمز الجسم) أجزاء من الحلقة على سبيل المثال حلقة 1 تعيين الأحمر والأخضر والأزرق الكل إلى 0 (ل 164.520 بكسل). ماذا يفعل هذا؟ ماذا لو وضعنا اللون الأحمر والأخضر والأزرق على 255؟ خطوط الجسم 3: تعيين الأحمر والأخضر والأزرق جميع إلى 0 يعمل For-loop على تشغيل هذه الخطوط ، مرة واحدة لكل بكسل ما هي النتيجة؟ صورة = SimpleImage جديدة ("flowers.jpg") ؛ لـ (بكسل: صورة) { pixel.setRed (0)؛ pixel.setGreen (0)؛ pixel.setBlue (0)؛ } طباعة (صورة)؛ لكل بكسل ، يعين كود الجسم القيم الحمراء والخضراء والزرقاء جميعها تكون 0. والنتيجة هي مستطيل أسود خالص. لم يتم ترك أي من بيانات الزهرة الأصلية ؛ كل شيء حصل على تغيير إلى الأصفار. على سبيل المثال حلقة 2 لكل بكسل ، اضبط اللون الأحمر والأخضر على 255 ، والأزرق على 0 ما هو كود الجسم للقيام بذلك؟ ما هي النتيجة؟ صورة = SimpleImage جديدة ("flowers.jpg") ؛ لـ (بكسل: صورة) { pixel.setRed (255)؛ pixel.setGreen (255)؛ pixel.setBlue (0)؛ } طباعة (صورة)؛ النتيجة هي مستطيل أصفر صلب. تقوم الشفرة بالكتابة فوق بيانات الزهرة ، وتغيير كل بكسل في الصورة الأصلية إلى بكسل أصفر نقي. على سبيل المثال حلقة 3 الأمثلة السابقة الكتابة فوق جميع البيانات زهرة ... غير واقعية العمل مع البيانات في flowers.jpg الزهور الصفراء - القيم الحمراء والخضراء عالية لكل بكسل ، اضبط اللون الأحمر على 0 ما هو كود الجسم للقيام بذلك؟ ما هي النتيجة؟ (ليس مطلوبًا أن تتمكن من التنبؤ بنتيجة عمليات RGB) ازهار صفراء انظر مرة أخرى إلى flowers.jpg. الأصفر مصنوع أو أحمر + أخضر ، لذلك نحن نعرف أن الأجزاء الصفراء من الصورة لها قيم حمراء وخضراء عالية. فماذا يحدث إذا ، لكل بكسل ، وضعنا الأحمر إلى 0؟ ما هي قيم RGB للبكسل نموذجي على الزهور الصفراء تبدو قبل تشغيل هذه الحلقة؟ ماذا بعد؟ صورة = SimpleImage جديدة ("flowers.jpg") ؛ لـ (بكسل: صورة) { pixel.setRed (0)؛ } طباعة (صورة)؛ كود الجسم pixel.setRed (0)؛ يتم تشغيله بواسطة الحلقة مرارًا وتكرارًا ، مرة واحدة لكل بكسل في الصورة. نظرًا لأن الزهور الصفراء مصنوعة من ضوء أحمر + أخضر ، فإن تعيين الأحمر إلى 0 لكل نتائج بكسل هو زهور خضراء. لا تتغير الأوراق الخضراء كثيرًا ، حيث كانت قيمها الحمراء بالقرب من 0 على أي حال. على سبيل المثال حلقة 4 لكل بكسل ، اضبط اللون الأخضر والأزرق على 0 ما هو كود الجسم للقيام بذلك؟ وتعرف النتيجة باسم "القناة الحمراء" رؤية صورة لمناطق الضوء الأحمر فقط صورة = SimpleImage جديدة ("flowers.jpg") ؛ لـ (بكسل: صورة) { pixel.setGreen (0)؛ pixel.setBlue (0)؛ } طباعة (صورة)؛ تعيين اللون الأخضر والأزرق إلى 0 في كل مكان ، كل ما تبقى هو منطقة الضوء الأحمر التي دخلت الصورة الأصلية ، ويعرف أيضًا باسم "القناة الحمراء" للصورة. الضوء الأحمر هو الأبرز في مجال الزهور الصفراء ، وهو أمر منطقي لأننا نعرف أن الأصفر = أحمر + أخضر. للاستنتاجات حلقة For-loop هي ميزة قوية للغاية ملاحظة: جافا سكريبت ليس لديها هذه الميزة ، أضفتها إلى CS101 نكتب رمز الجسم للتأثير الذي نريده يعالج الكمبيوتر مسك الدفاتر لتكرار كل وحدات البكسل الكمبيوتر = قوي + موضوع غبي حلقة: قوية ، ولكن الميكانيكية القسم التالي - يحول صورة أكثر إثارة للاهتمام Image For-Loop In this section, we'll look at the "for loop" construct, which can run a bit of code thousands of times -- a big increase in the power available to us. yellow flowers flowers.jpg is 457 pixels wide by 360 pixels high -- 164,520 pixels Code operating one pixel at a time ... not practical Want: we specify some code, computer runs it again and again, once for each pixel "For loop" does this -- big increase in the power of our code Accessing one pixel at a time, e.g. pixel at (0, 0), then the pixel at (1, 0), etc. is not a good way to work on an image which may have 100,000 or more pixels. We'd like to say something like "for each pixel do this", and let the computer fiddle with the details of going through all the (x, y) values to look at each pixel once. The very powerful "for loop" structure we'll learn here provides exactly this "for each pixel do this" feature. The loop takes a few lines of our code, and runs those lines again and again, once for each pixel in the image. For-Loop Structure Syntax: for (pixel: image) { ... } Starts the for loop, syntax all required, indentation "body" code inside the { ... } Runs body lines for pixel #1 Goes back to top of body, runs for pixel #2 Runs again and again, once for each pixel in the image For each pixel: (do what the body code says) parts of the for-loop For-Loop Example 1 Setting red, green, and blue all to 0 (for 164,520 pixels). What does that do? What if we set red, green, and blue all to 255? Body 3 lines: set red, green, and blue all to 0 For-loop runs those lines, once for each pixel What is the result? image = new SimpleImage("flowers.jpg"); for (pixel: image) { pixel.setRed(0); pixel.setGreen(0); pixel.setBlue(0); } print(image); For each pixel, the body code sets the red, green, and blue values all to be 0. The result is a pure black rectangle. None of the original flower data is left; it all got changed to zeros. For-Loop Example 2 For each pixel, set red and green to 255, blue to 0 What is the body code to do this? What is the result? image = new SimpleImage("flowers.jpg"); for (pixel: image) { pixel.setRed(255); pixel.setGreen(255); pixel.setBlue(0); } print(image); Result is a solid yellow rectangle. The code overwrites the flower data, changing each pixel in the original image into a pure yellow pixel. For-Loop Example 3 Previous examples overwrote all the flower data ... not realistic Work with the data in flowers.jpg Yellow flowers -- red and green values high For each pixel, set red to 0 What is the body code to do this? What is the result? (Not required that you have can predict the result of the RGB operations) yellow flowers Look again at flowers.jpg.Yellow is made or red + green, so we know that the yellow parts of the image have high red and green values. So what happens if, for each pixel, we set red to 0? What are the RGB values for a typical pixel on the yellow flowers look like before this loop runs? What about after? image = new SimpleImage("flowers.jpg"); for (pixel: image) { pixel.setRed(0); } print(image); The body code pixel.setRed(0); is run by the loop again and again, once for each pixel in the image. Since the yellow flowers are made with red + green light, setting the red to 0 for each pixel results is greenish flowers. The green leaves aren't changed much, since their red values were near 0 anyway. For-Loop Example 4 For each pixel, set green and blue to 0 What is the body code to do this? The result is known as the "red channel" Seeing an image of just the red light areas image = new SimpleImage("flowers.jpg"); for (pixel: image) { pixel.setGreen(0); pixel.setBlue(0); } print(image); Setting green and blue to 0 everywhere, all that is left is the area of red light that went into the original image, aka the "red channel" of the image. The red light is most prominent for the area of yellow flowers, which makes sense as we know that yellow = red + green. For-Loop Conclusions For-loop is a very powerful feature Note: Javascript does not have this feature, I added it for CS101 We write the body code for the effect we want Computer handles the bookkeeping to repeat over all the pixels Computer = powerful + stupid theme Loop: powerful, but mechanical Next section - more interesting image transforms الصورة للحصول على حلقة في هذا القسم ، سننظر إلى بنية "for loop" ، والتي يمكن تشغيلها قليلاً من الكود آلاف المرات - وهي زيادة كبيرة في القوة المتاحة لنا. ازهار صفراء flowers.jpg بعرض 457 بكسل ارتفاع 360 بكسل - 164.520 بكسل رمز التشغيل بكسل واحد في وقت واحد ... غير عملي تريد: نحدد بعض الكودات ، يقوم الكمبيوتر بتشغيله مرارًا وتكرارًا ، مرة واحدة لكل بكسل "For loop" يفعل هذا - زيادة كبيرة في قوة التعليمات البرمجية لدينا الوصول إلى بكسل واحد في المرة الواحدة ، على سبيل المثال بكسل في (0 ، 0) ، ثم بكسل في (1 ، 0) ، وما إلى ذلك ليست طريقة جيدة للعمل على صورة قد تحتوي على 100000 بكسل أو أكثر. نود أن نقول شيئًا مثل "لكل بكسل تفعل ذلك" ، ونترك الكمبيوتر يتلاعب بتفاصيل استعراض كل القيم (س ، ص) للنظر في كل بكسل مرة واحدة. يوفر بنية "for loop" القوية للغاية التي سنتعلمها هنا هذا بالضبط "لكل بكسل تفعل هذه" الميزة. تأخذ الحلقة بضعة أسطر من الشفرة الخاصة بنا ، وتعمل هذه الخطوط مرارًا وتكرارًا ، مرة واحدة لكل بكسل في الصورة. ل حلقة هيكل بناء الجملة: لـ (بكسل: صورة) {...} يبدأ في حلقة ، بناء جملة كل المطلوب ، المسافة البادئة "الجسم" رمز داخل {...} يدير خطوط الجسم للبكسل رقم 1 يعود إلى الجزء العلوي من الجسم ، يعمل على بكسل رقم 2 يعمل مرارا وتكرارا ، مرة واحدة لكل بكسل في الصورة لكل بكسل: (افعل ما يقوله رمز الجسم) أجزاء من الحلقة على سبيل المثال حلقة 1 تعيين الأحمر والأخضر والأزرق الكل إلى 0 (ل 164.520 بكسل). ماذا يفعل هذا؟ ماذا لو وضعنا اللون الأحمر والأخضر والأزرق على 255؟ خطوط الجسم 3: تعيين الأحمر والأخضر والأزرق جميع إلى 0 يعمل For-loop على تشغيل هذه الخطوط ، مرة واحدة لكل بكسل ما هي النتيجة؟ صورة = SimpleImage جديدة ("flowers.jpg") ؛ لـ (بكسل: صورة) { pixel.setRed (0)؛ pixel.setGreen (0)؛ pixel.setBlue (0)؛ } طباعة (صورة)؛ لكل بكسل ، يعين كود الجسم القيم الحمراء والخضراء والزرقاء جميعها تكون 0. والنتيجة هي مستطيل أسود خالص. لم يتم ترك أي من بيانات الزهرة الأصلية ؛ كل شيء حصل على تغيير إلى الأصفار. على سبيل المثال حلقة 2 لكل بكسل ، اضبط اللون الأحمر والأخضر على 255 ، والأزرق على 0 ما هو كود الجسم للقيام بذلك؟ ما هي النتيجة؟ صورة = SimpleImage جديدة ("flowers.jpg") ؛ لـ (بكسل: صورة) { pixel.setRed (255)؛ pixel.setGreen (255)؛ pixel.setBlue (0)؛ } طباعة (صورة)؛ النتيجة هي مستطيل أصفر صلب. تقوم الشفرة بالكتابة فوق بيانات الزهرة ، وتغيير كل بكسل في الصورة الأصلية إلى بكسل أصفر نقي. على سبيل المثال حلقة 3 الأمثلة السابقة الكتابة فوق جميع البيانات زهرة ... غير واقعية العمل مع البيانات في flowers.jpg الزهور الصفراء - القيم الحمراء والخضراء عالية لكل بكسل ، اضبط اللون الأحمر على 0 ما هو كود الجسم للقيام بذلك؟ ما هي النتيجة؟ (ليس مطلوبًا أن تتمكن من التنبؤ بنتيجة عمليات RGB) ازهار صفراء انظر مرة أخرى إلى flowers.jpg. الأصفر مصنوع أو أحمر + أخضر ، لذلك نحن نعرف أن الأجزاء الصفراء من الصورة لها قيم حمراء وخضراء عالية. فماذا يحدث إذا ، لكل بكسل ، وضعنا الأحمر إلى 0؟ ما هي قيم RGB للبكسل نموذجي على الزهور الصفراء تبدو قبل تشغيل هذه الحلقة؟ ماذا بعد؟ صورة = SimpleImage جديدة ("flowers.jpg") ؛ لـ (بكسل: صورة) { pixel.setRed (0)؛ } طباعة (صورة)؛ كود الجسم pixel.setRed (0)؛ يتم تشغيله بواسطة الحلقة مرارًا وتكرارًا ، مرة واحدة لكل بكسل في الصورة. نظرًا لأن الزهور الصفراء مصنوعة من ضوء أحمر + أخضر ، فإن تعيين الأحمر إلى 0 لكل نتائج بكسل هو زهور خضراء. لا تتغير الأوراق الخضراء كثيرًا ، حيث كانت قيمها الحمراء بالقرب من 0 على أي حال. على سبيل المثال حلقة 4 لكل بكسل ، اضبط اللون الأخضر والأزرق على 0 ما هو كود الجسم للقيام بذلك؟ وتعرف النتيجة باسم "القناة الحمراء" رؤية صورة لمناطق الضوء الأحمر فقط صورة = SimpleImage جديدة ("flowers.jpg") ؛ لـ (بكسل: صورة) { pixel.setGreen (0)؛ pixel.setBlue (0)؛ } طباعة (صورة)؛ تعيين اللون الأخضر والأزرق إلى 0 في كل مكان ، كل ما تبقى هو منطقة الضوء الأحمر التي دخلت الصورة الأصلية ، ويعرف أيضًا باسم "القناة الحمراء" للصورة. الضوء الأحمر هو الأبرز في مجال الزهور الصفراء ، وهو أمر منطقي لأننا نعرف أن الأصفر = أحمر + أخضر. للاستنتاجات حلقة For-loop هي ميزة قوية للغاية ملاحظة: جافا سكريبت ليس لديها هذه الميزة ، أضفتها إلى CS101 نكتب رمز الجسم للتأثير الذي نريده يعالج الكمبيوتر مسك الدفاتر لتكرار كل وحدات البكسل الكمبيوتر = قوي + موضوع غبي حلقة: قوية ، ولكن الميكانيكية القسم التالي - يحول صورة أكثر إثارة للاهتمام Image For-Loop In this section, we'll look at the "for loop" construct, which can run a bit of code thousands of times -- a big increase in the power available to us. yellow flowers flowers.jpg is 457 pixels wide by 360 pixels high -- 164,520 pixels Code operating one pixel at a time ... not practical Want: we specify some code, computer runs it again and again, once for each pixel "For loop" does this -- big increase in the power of our code Accessing one pixel at a time, e.g. pixel at (0, 0), then the pixel at (1, 0), etc. is not a good way to work on an image which may have 100,000 or more pixels. We'd like to say something like "for each pixel do this", and let the computer fiddle with the details of going through all the (x, y) values to look at each pixel once. The very powerful "for loop" structure we'll learn here provides exactly this "for each pixel do this" feature. The loop takes a few lines of our code, and runs those lines again and again, once for each pixel in the image. For-Loop Structure Syntax: for (pixel: image) { ... } Starts the for loop, syntax all required, indentation "body" code inside the { ... } Runs body lines for pixel #1 Goes back to top of body, runs for pixel #2 Runs again and again, once for each pixel in the image For each pixel: (do what the body code says) parts of the for-loop For-Loop Example 1 Setting red, green, and blue all to 0 (for 164,520 pixels). What does that do? What if we set red, green, and blue all to 255? Body 3 lines: set red, green, and blue all to 0 For-loop runs those lines, once for each pixel What is the result? image = new SimpleImage("flowers.jpg"); for (pixel: image) { pixel.setRed(0); pixel.setGreen(0); pixel.setBlue(0); } print(image); For each pixel, the body code sets the red, green, and blue values all to be 0. The result is a pure black rectangle. None of the original flower data is left; it all got changed to zeros. For-Loop Example 2 For each pixel, set red and green to 255, blue to 0 What is the body code to do this? What is the result? image = new SimpleImage("flowers.jpg"); for (pixel: image) { pixel.setRed(255); pixel.setGreen(255); pixel.setBlue(0); } print(image); Result is a solid yellow rectangle. The code overwrites the flower data, changing each pixel in the original image into a pure yellow pixel. For-Loop Example 3 Previous examples overwrote all the flower data ... not realistic Work with the data in flowers.jpg Yellow flowers -- red and green values high For each pixel, set red to 0 What is the body code to do this? What is the result? (Not required that you have can predict the result of the RGB operations) yellow flowers Look again at flowers.jpg.Yellow is made or red + green, so we know that the yellow parts of the image have high red and green values. So what happens if, for each pixel, we set red to 0? What are the RGB values for a typical pixel on the yellow flowers look like before this loop runs? What about after? image = new SimpleImage("flowers.jpg"); for (pixel: image) { pixel.setRed(0); } print(image); The body code pixel.setRed(0); is run by the loop again and again, once for each pixel in the image. Since the yellow flowers are made with red + green light, setting the red to 0 for each pixel results is greenish flowers. The green leaves aren't changed much, since their red values were near 0 anyway. For-Loop Example 4 For each pixel, set green and blue to 0 What is the body code to do this? The result is known as the "red channel" Seeing an image of just the red light areas image = new SimpleImage("flowers.jpg"); for (pixel: image) { pixel.setGreen(0); pixel.setBlue(0); } print(image); Setting green and blue to 0 everywhere, all that is left is the area of red light that went into the original image, aka the "red channel" of the image. The red light is most prominent for the area of yellow flowers, which makes sense as we know that yellow = red + green. For-Loop Conclusions For-loop is a very powerful feature Note: Javascript does not have this feature, I added it for CS101 We write the body code for the effect we want Computer handles the bookkeeping to repeat over all the pixels Computer = powerful + stupid theme Loop: powerful, but mechanical Next section - more interesting image transforms |