วันพุธที่ 27 สิงหาคม พ.ศ. 2557

Lab 2 - Favourite Subject/Topic (with Functions)

Increase/Decrease Space_Left_Screen to move screen to right/left.
Increase/Decrease H_CPU to increase/decrease the height of CPU.
Increase/Decrease H_Disk to move CD-Rom to top/bottom.

Functions
    DrawScreen(int Space_Left_Screen); for draw screen
    DrawCPU(int H_CPU,int H_Disk); for draw CPU

void setup() {
    //variable
    int H_CPU,H_Disk,Space_Left_Screen;
    //assign variable
    H_CPU = 20;
    Space_Left_Screen = 50;
    H_Disk = -10;
    size(360,360);
    background(2,222,83);
    DrawScreen(Space_Left_Screen);
    DrawCPU(H_CPU,H_Disk);
}

void DrawScreen(int Space_Left_Screen)
{
    //draw case of screen
    fill(200);
    ellipse(Space_Left_Screen+180,240,100,60);
    quad(Space_Left_Screen+170,190,Space_Left_Screen+190,190,Space_Left_Screen+200,236,Space_Left_Screen+160,250); //bottom
    quad(Space_Left_Screen+160,185,Space_Left_Screen+170,190,Space_Left_Screen+160,250,Space_Left_Screen+145,242); //bottom
    quad(Space_Left_Screen+130,160,Space_Left_Screen+170,140,Space_Left_Screen+170,220,Space_Left_Screen+130,200); //top
    quad(Space_Left_Screen+170,140,Space_Left_Screen+230,130,Space_Left_Screen+230,200,Space_Left_Screen+170,220); //top
    //draw screen
    fill(0,197,227);
    quad(Space_Left_Screen+178,146,Space_Left_Screen+224,138,Space_Left_Screen+224,196,Space_Left_Screen+178,210);
}    
void DrawCPU(int H_CPU,int H_Disk)
{
    //draw CPU
    fill(200);
    quad(80,154-H_CPU,120,146-H_CPU,120,266,80,278);                        //front
    quad(20,134-H_CPU,80,154-H_CPU,80,278,20,254);                            //side
    quad(57,127-H_CPU,120,146-H_CPU,80,154-H_CPU,20,134-H_CPU); //top
    noStroke();
    fill(50);
    quad(83,160-H_Disk,118,152-H_Disk,118,160-H_Disk,83,168-H_Disk); //CD disk1
    quad(83,172-H_Disk,118,164-H_Disk,118,172-H_Disk,83,180-H_Disk); //CD disk2
}