CS101: fun intro to Computer Science from Stanford

Post all your tuts or request for tuts here.
Post Reply
User avatar
Verahta
Posts: 440
Joined: Wed Aug 24, 2011 1:50 am

CS101: fun intro to Computer Science from Stanford

Post by Verahta »

https://class.stanford.edu/courses

CS101 is a fun little basic intro to Computer Science if anyone is interested (experienced vets won't get much out of it probably). As an example of some of the exercises, I will explain my avatar which I made for the Week 3 optional exercise in the class. The class already started and is on Week 4, but honestly you could catch up with just a few hours of effort. It really is a basic intro to various areas of CS (programming, pixel manipulation, pixel coordinates, bits bytes & binary, CPU & hardware, etc).

I found the average pixel value and which one was above the average was obviously what color that pixel slanted to. Then you just copy the pixels from the back image and replace them with the corresponding pixels on the front image. Anyways, fun little exercise :D

My theme was "nerdy".

I had a heck of a time with the supergirl image when the background was pale blue, because it couldn't tell the difference between pale blue and dark blue of her clothing. So I changed the background to green. But then, it was erasing the green but ALSO the yellow of the Superman logo. That's when I realized both green and yellow have green RGB values above the average. And I noticed green has only green above the average but the other two are below the average, so I made that tweak to the code so it found green but left the yellow alone. If I had realized this earlier, I probably could have skipped the part where I changed the background to green and just found a boolean expression to differentiate between pale blue and dark blue.

Pseudo-JS code:

Code: Select all

image = new SimpleImage("matrix.jpg");
back = new SimpleImage("supergirl.jpg");
back.setSameSize(image);

for (pixel: image) {
  avg = (pixel.getRed() + pixel.getGreen() + pixel.getBlue())/3;

  if (pixel.getGreen() > avg*1.05 && pixel.getRed() < avg*1.05 && pixel.getBlue() < avg*1.05 ) {
pixel2 = back.getPixel(pixel.getX(), pixel.getY());
pixel.setRed(pixel2.getRed());
pixel.setGreen(pixel2.getGreen());
pixel.setBlue(pixel2.getBlue());
}
}
print(image);
Image

Image
"In order to understand recursion, one must first understand recursion".
Post Reply

Return to “Tutorials”