2012年3月4日 星期日

Homework 4-1: Text & Image

I have learnt how to create a save button to store a picture. I have also learnt how to write a text inside the button created. I can now draw any picture by using the different button with different colours.

void setup() {
  size(500, 400);
  strokeWeight(5);
  smooth();
  background(204);
  fill(255, 0, 0);
  rect(0, 0, 50, 50);
  fill(0, 255, 0);
  rect(0, 50, 50, 50);
 
  fill(0, 0, 255);
  rect(0, 100, 50, 50);
 
  fill(255, 0, 255);
  rect(0, 150, 50, 50);
 
  fill(255, 255, 255);
  rect(450,0,50,50);
 
   fill(255, 255, 255);
  rect(450,50,50,50);
   
   fill(255, 255, 255);
  rect(450,100,50,50);
 
  fill(255, 255, 255);
  rect(450,150,50,50);
 
  PFont font;
  font = loadFont("AgencyFB-Reg-48.vlw");
  textFont(font);
  fill(0);
  textSize(20);
  String s = "Erase";
  text(s,450, 20);
 
  String j = "Save";
  text(j,450, 100);
 
  String n = "Next";
  text(n,450, 150);
 
   fill(255, 255, 255);
  //ellipse (250,0,100,100);
  
    fill(255, 255, 255);
   ellipse (250,400,100,100);
  
 
  int front = int(random(1, 10)); // Select the front card
  int back = int(random(1, 10)); // Select the back card
  PImage line1 = loadImage(front + "1b.jpg");
  PImage line2 = loadImage(back + "2b.jpg");
  image(line1, 0, 0);
  image(line2, 60, 0);
  stroke(0, 0, 0);
}
void draw() {
  if (mousePressed && mouseX >=0 && mouseX <=50 && mouseY >=0 && mouseY <=50)
     stroke(255,0,0);
    
   if (mousePressed && mouseX >=0 && mouseX <=50 && mouseY >=50 && mouseY <=100)
     stroke(0,255,0);
    
    if (mousePressed && mouseX >=0 && mouseX <=100 && mouseY >=100 && mouseY <=150)
     stroke(0,0,255);
    
     if (mousePressed && mouseX >=0 && mouseX <=150 && mouseY >=150 && mouseY <=200)
     stroke(255,0,255);

    if (mousePressed && mouseX >=450 && mouseX <=500 && mouseY >=50 && mouseY <=100)
      save("line.tif");
     
      
     if (mousePressed && mouseX >=60 && mousePressed && mouseX<=450) 
        line(mouseX, mouseY, pmouseX, pmouseY);
   
}

沒有留言:

張貼留言