1 00:00:00,240 --> 00:00:07,280 Hi everyone! Today we're going to make a natural science educational project to explain light 2 00:00:07,280 --> 00:00:13,759 and the creation of shadows when light interacts with opaque objects. We're basically going to have 3 00:00:13,759 --> 00:00:19,120 a source of light which will be the sun and an opaque object, for example this apple, 4 00:00:19,120 --> 00:00:26,079 and another sprite which will actually create the light rays and will stop either when touching the 5 00:00:26,079 --> 00:00:32,259 edge or when touching the opaque object. And finally we will code it so that it 6 00:00:32,259 --> 00:00:37,460 runs instantly and we don't have to wait to see the shadow and I will give you 7 00:00:37,460 --> 00:00:42,039 some more ideas to improve your project as I usually do. Alright, so if you are 8 00:00:42,039 --> 00:00:45,719 ready let's get started. 9 00:00:45,719 --> 00:00:58,840 so let's begin adding the sprites first of all the Sun and then an opaque object 10 00:00:58,840 --> 00:01:03,240 I'm gonna take the Apple but you can take any object let me make the Sun a 11 00:01:03,240 --> 00:01:08,760 little bit smaller and this time I'm not gonna get rid of the cat because I'm 12 00:01:08,760 --> 00:01:15,459 gonna use the cat to draw the light rays well in fact you can use any sprite to 13 00:01:15,459 --> 00:01:20,640 draw the light rays. I'm gonna make the cat as small as possible, I'm gonna set 14 00:01:20,640 --> 00:01:26,019 size to one and as you see the minimum size is five and I'm gonna go to 15 00:01:26,019 --> 00:01:34,739 backdrops to convert it to bitmap and with the paint bucket I'm gonna make it 16 00:01:34,739 --> 00:01:42,400 black. So let's go back to the code and basically the program is gonna be this 17 00:01:42,400 --> 00:01:48,900 the cat is going to start from the Sun and it's going to move pen down I will 18 00:01:48,900 --> 00:01:54,420 explain to you what that is later and it's going to trace a yellow line it 19 00:01:54,420 --> 00:02:01,340 will stop when it touches the edge it will go back turn one degree and another 20 00:02:01,340 --> 00:02:07,560 line go back another line go back another line and when it is touching the 21 00:02:07,560 --> 00:02:12,120 apple it will also stop because if it continues we are not creating the shadow 22 00:02:12,120 --> 00:02:17,159 so when touching the apple it will stop we'll go back we'll turn make another 23 00:02:17,159 --> 00:02:23,699 ray stop when touching the Apple go back and so on so first of all I'm gonna go 24 00:02:23,699 --> 00:02:31,379 here and I'm going to add the pen which is what we need what I was saying well 25 00:02:31,379 --> 00:02:37,020 I'm gonna do it with the Apple so that you see it clearly look if pennies up 26 00:02:37,020 --> 00:02:45,000 and I move the Apple it doesn't paint anything but well pen up basically is 27 00:02:45,000 --> 00:02:49,020 when you move the pen up you are not touching the piece of paper so if you 28 00:02:49,020 --> 00:02:55,780 are not touching the piece of paper you cannot paint pen down means that I move 29 00:02:55,780 --> 00:03:00,180 the pen down and I'm touching the piece of paper so if I move the Apple with the 30 00:03:00,180 --> 00:03:07,919 pen down it traces a line alright so I'm gonna erase all I'm gonna take the apple 31 00:03:07,919 --> 00:03:15,960 here and let's begin coding I'm gonna go to scratch and in event well we could do 32 00:03:15,960 --> 00:03:22,840 one green flag clicked or when space key pressed when space key pressed first of 33 00:03:22,840 --> 00:03:27,840 all I'm gonna make sure I move the pen up so that I'm not touching the paper 34 00:03:27,840 --> 00:03:33,599 let's say the cat is over here so pen up so that I'm not touching the paper and 35 00:03:33,599 --> 00:03:42,300 now with the pen up I'm gonna move the cat to the Sun so go to Sun and I press 36 00:03:42,300 --> 00:03:51,400 space so now the cat is here and I can put the pen down I think before that at 37 00:03:51,400 --> 00:03:59,139 the beginning I'm going to do some things which could be this look when 38 00:03:59,139 --> 00:04:06,099 green flag clicked I'm going to set paint color to yellow because I don't 39 00:04:06,099 --> 00:04:15,770 want to have blue light rays set pen size this is how big how not how big how 40 00:04:15,770 --> 00:04:21,290 wide these lines are we can leave this number and later we will change the pen 41 00:04:21,290 --> 00:04:26,149 size and you will see the different results that we can obtain and finally 42 00:04:26,149 --> 00:04:30,790 what is the direction the cat is gonna be pointing in at the beginning let's 43 00:04:30,790 --> 00:04:38,870 say for example 45 which is this and when we're moving the direction of the 44 00:04:38,870 --> 00:04:46,529 cat we will reach okay other numbers so that could be so as we were saying when 45 00:04:46,529 --> 00:04:52,850 space key pressed the cat goes to the sun and moves the pen down. With the pen 46 00:04:52,850 --> 00:04:59,970 down and pointing in this direction now we can move the cat. As we have to move 47 00:04:59,970 --> 00:05:16,220 the cat a lot we're going to repeat this movement. So let's put repeat until. So 48 00:05:16,220 --> 00:05:23,180 cat is moving and when does the cat have to stop okay it has to stop when it is touching the edge 49 00:05:23,819 --> 00:05:32,699 or when touching the apple so the cat is going to repeat this until and i put an or until touching 50 00:05:32,699 --> 00:05:48,439 the edge or touching the apple. After this it's going to turn one degree and 51 00:05:48,439 --> 00:05:57,709 again go to the Sun to repeat the process. So it will turn one degree and 52 00:05:57,709 --> 00:06:06,389 then repeat this process I'm gonna do one thing when space key pressed the 53 00:06:06,389 --> 00:06:13,209 first thing we're going to do is erase all so that I press and it draws it has 54 00:06:13,209 --> 00:06:22,750 stopped so now basically it has to repeat this and this and this many times 55 00:06:22,750 --> 00:06:29,800 I'm gonna put the apple here so that you see what happens as you see when it 56 00:06:29,800 --> 00:06:38,899 touches the apple it stops and now that is not touching the apple anymore it 57 00:06:38,899 --> 00:06:45,160 completes and and paints the rest of the screen logically I don't want to be 58 00:06:45,160 --> 00:06:51,579 clicking here whenever I want to repeat this so I have a loop which is gonna be 59 00:06:51,579 --> 00:07:03,339 repeat 100 times for example place it here and now green flag oh well maybe 60 00:07:03,339 --> 00:07:17,120 this point in direction could be here let's begin as you see it works but it 61 00:07:17,120 --> 00:07:21,240 takes a long time and I don't want you to fall asleep so maybe you are 62 00:07:21,240 --> 00:07:26,819 wondering Diego is there way to do it instantly and the answer is yes of 63 00:07:26,819 --> 00:07:35,399 course look I'm gonna go to my blogs and I'm gonna make a blog called light up 64 00:07:35,399 --> 00:07:44,220 and I'm gonna select this run without screen refresh I'm gonna pass it here 65 00:07:44,220 --> 00:07:52,680 and all this this repetition is what has to be done instantly so I put the block 66 00:07:52,680 --> 00:08:00,180 light up here which is the same as all this which is run instantly and now only 67 00:08:00,180 --> 00:08:10,620 by pressing space this is done I'm gonna move the Apple I press space and as you 68 00:08:10,620 --> 00:08:17,500 this works very well so what you have here is the basic project this is very good but probably you 69 00:08:17,500 --> 00:08:23,500 want to make an excellent project and to make an excellent project i'm going to give you some ideas 70 00:08:23,500 --> 00:08:35,899 to make it better for example probably you know that a complete circumference has 360 degrees 71 00:08:35,899 --> 00:08:44,840 so if I repeat this 360 times as I'm turning one degree every time I'm gonna 72 00:08:44,840 --> 00:08:52,639 complete all this so I can put this anywhere spacebar and look I complete it 73 00:08:52,639 --> 00:09:00,799 other things we were saying if I change this which could be here as well all 74 00:09:00,799 --> 00:09:07,279 this could be here okay and we would get rid of the green flag if i set pen size to three 75 00:09:10,179 --> 00:09:16,580 as you see this is quite different because these lines are three pixels wide and not one 76 00:09:17,620 --> 00:09:26,899 if i set this to 10 i basically complete the whole the whole screen all right more things we can do 77 00:09:26,899 --> 00:09:30,580 probably you're wondering if we can add more objects obviously we can 78 00:09:31,220 --> 00:09:41,299 i'm going to add for example a bat and i'm going to put it here but look when i press spacebar 79 00:09:42,820 --> 00:09:48,500 the light race or the cat the sprite stops when touching the apple but it doesn't stop when 80 00:09:48,500 --> 00:09:55,539 touching the bat why because we haven't coded it yet okay in the cat we said that it has to 81 00:09:55,539 --> 00:10:03,700 move until touching it or apple but not until touching the bat so we need an or all this 82 00:10:04,500 --> 00:10:17,120 is going to be here and in this space we add touching bat now spacebar and that works 83 00:10:17,759 --> 00:10:26,000 another thing we can do here in the edition uh screen obviously we can move the object 84 00:10:26,000 --> 00:10:34,320 but if i am trying my game i can't so to be able to move the object here when i am actually playing 85 00:10:35,759 --> 00:10:41,440 i'm gonna go to uh the sun and i could put when green flag clicked 86 00:10:44,559 --> 00:10:53,600 it's here set drag mode to draggable okay so that you can drag the sun look now i can drag it 87 00:10:53,600 --> 00:11:00,799 but i can't drag these two so i'm gonna pass this to the apple and i'm gonna pass this to the bat 88 00:11:02,000 --> 00:11:09,679 green flag and now these three are draggable and i can drag them all right and with this you have 89 00:11:09,679 --> 00:11:17,679 an excellent project if you want to make it brilliant um you could add some uh variables 90 00:11:17,679 --> 00:11:23,519 for example if i want to control the pen size if i want to control 91 00:11:26,080 --> 00:11:37,679 this from the game i can create a variable called pen size in this variable with right click slider 92 00:11:37,679 --> 00:11:44,399 i make it into slider and with right click change slider range the minimum could be one 93 00:11:44,960 --> 00:11:55,320 and the maximum 10. so i'm going to set pen size to this variable so i put this here 94 00:11:56,840 --> 00:12:03,159 now if i put here an 8 we are setting pen size to 8. so 95 00:12:05,559 --> 00:12:13,090 before you press spacebar make sure you click on the screen and as you see i'm going to move 96 00:12:13,090 --> 00:12:30,519 the objects and I'm gonna set pen size to six okay so that works and another 97 00:12:30,519 --> 00:12:34,059 thing that you could add for example I'm just gonna do it in one of the objects 98 00:12:34,059 --> 00:12:38,419 but you could do it in both of them is that we can control the size of the 99 00:12:38,419 --> 00:12:45,159 Apple from the game or the size of the bat as well it's quite similar I'm gonna 100 00:12:45,159 --> 00:12:52,580 make a variable which is going to be apple size again right click slider 101 00:12:52,580 --> 00:13:01,879 right click change slider range and the size could go from 5 to 300 for example 102 00:13:01,879 --> 00:13:15,700 now in the Apple after this I could put forever set size to what I have here so 103 00:13:15,700 --> 00:13:24,399 variables Apple size so you will see now Apple size is tiny because this is zero 104 00:13:24,399 --> 00:13:35,980 but if I increase it it sets pen size so it says Apple size to this number so now 105 00:13:35,980 --> 00:13:39,879 I can move the Apple I can move the bat you could create another variable for 106 00:13:39,879 --> 00:13:46,440 the bat size and do the same as I've done in the apple and spacebar and I 107 00:13:46,440 --> 00:13:52,320 create the shadow so this is the project guys to study shadows and light and how 108 00:13:52,320 --> 00:13:56,860 light interacts with opaque objects I hope you liked it and please do not 109 00:13:56,860 --> 00:14:01,320 forget to send me a project when you have them done alright see you guys bye 110 00:14:01,320 --> 00:14:03,080 bye