Sunday, December 23, 2012

Programming Day 2

Ice Cream!

Angela

Angela's code looked like this:
size (500,500); // make a big blank window
// choose background color

//choose line color 

// choose color of ice cream 
 ellipse(200,200,300,300); // make a circle 200 right 200 left 300 wide 300 tall

// choose color of cone 
  triangle(40,240,200,450,360,240); // make a piont 255 to the right 460 down 340 right 480 down 350 right 590 down  
Very descriptive psuedocode, right?! Her coding resulted in:
Mmm... vanilla!

Jason

Jason started turning his cone into a waffle cone with this code:
size(1000,1000);
background(220,200,220);
//fill(100,010,250);//dark blue
fill(#640afa);
ellipse(500,300,350,350);//circle
fill(150,100,100);
triangle(300,300,700,300,500,700);


stroke(#00ff00);
line(300,2*300-300,300,300); //dot on the left
strokeWeight(10);
line(400,300,400,500);
line(600,300,600,500);
line(350,2*350-300,350,300);
line(500,2*500-300,500,300); // line in the center
line(300,2*300-300,300,300);
line(300,2*300-300,300,300);
/*
line(650,2*650-,650,300);
*/

strokeWeight(10);
line(450,2*450-300,450,300);
line(550,2*550-500,550,300);

for(int i=0; i<=width; i=i+1){
  point(i,2*i-300);
}
Here is the current result:
Did you see how he used mx b equations to draw the vertical lines the appropriate length?
Jason also began learning about another way to use the color function. We've been using three numbers to represent red (255,0,0), green (0,255,0), and blue (0,0,255). There's also the combinations like blue-green (0,200,200) or purplish-red (125,25,10). Well, it turns out that using something call the base-16 numbers (or "hexidecimal numbers") you can choose the same colors using the number sign (#) symbol followed by three "hex" numbers. For example:
  • red (#FF0000)
  • green (#00FF00)
  • blue (#0000FF)
  • blue-green (#00C8C8)
  • purplish-red (#7D190A)
By the way, to get a list of these hex numbers and their matching regular (decimal number), you can run some Python code:
'Print a list of the first 255 hexidecimal'
'numbers and their decimal equivalents.'

hexArray = []

for i in range(0,16):
    hexArray.append([])


for i in range(0,16**2):    
    hexArray[i//16].append([" "*(3-len(str(i)))+str(i)," "*(2-len(str(hex(i))[2:]))+ str(hex(i))[2:]])


for i in range(0,16):
    print(hexArray[i])
When I tweeted this code, someone replied to me with a much simpler method.


Click to see the resulting list.

William

William also coded an ice cream cone:
size (400,400); // window size
background(125,25,10); // purple ish red

stroke(255); // white

fill(200,10,20); //red
ellipse(200,200,100,100); //200 right 200 down 100 wide 100 tall

fill(5,70,65); // blue
triangle(150,230,250,230,200,400);
It's interesting that his psuedocode tells us what is going on in his own words. Here's the result:
Looks tasty!

No comments:

Post a Comment