2020年10月19日 星期一

week06-text使用

 

視窗以及位置的緣故所以無法完整呈現文字

fill(255,0,0);                   文字顏色
textSize(40);                   文字大小
text("Hello",30,30);       文字輸入以及位置
size(500,400);                        視窗大小
rect(100,100,200,100);          方塊大小以及位置
fill(255,0,0);                          文字顏色
textSize(40);                          文字大小
textAlign(LEFT,TOP);          文字位置在左上角
text("Hello",100,100);          文字輸入以及位置
由於加入文字不同所以顯示的文字不相同
size(800,300);        視窗
fill(255,0,0);           

PFont font1=createFont("Times New Roman",30);   加入文字語法
textFont(font1);
text("中文vs.English",30,30);

PFont font2=createFont("標楷體",30);     加入標楷體
textFont(font2);
text("中文vs.English",30,130);

int [][]A=               陣列
{
  {1,1,1},
  {0,1,0},
  {0,1,1},
  {1,1,1}
};
size(300,400);                           視窗大小
for(int i=0;i<4;i++)                   i數值的累加
{
  for(int j=0;j<3;j++)                 j數值的累加
  {
    if(A[i][j]==0)fill(0);             當坐標[i][j]的數值等於0方塊為黑色
    else fill(255,0,0);                  當坐標[i][j]不等於0方塊為紅色
    rect (j*100,i*100,100,100);  方塊的位置隨[i][j]改變時移動
  }
}
int [][]A=                                      陣列
{
  {2,2,2,2},
  {0,1,1,1},
  {0,1,1,1},
  {2,2,2,2}
};
PImage bird, pig;                          設定圖片名稱
void setup()
{
  size(300,400);
  bird=loadImage("bird.png");      讀取圖片
  pig=loadImage("pige.png");
}
void draw()
{
  background(0);
  for(int i=0;i<4;i++)
  {
    for(int j=0;j<4;j++)
    {
      if(A[i][j]==1)image(bird,j*100,i*100,100,100);
      if(A[i][j]==2)image(pig,j*100,i*100,100,100);
    }
  }
}

int [][]A=
{
  {2,2,2,2},
  {0,1,1,1},
  {0,1,1,1},
  {2,2,2,2}
};
PImage bird, pig;
void mousePressed()              
{
  int i=int(mouseY/100);     滑鼠按下的位置給予坐標
  int j=int(mouseX/100);
  A[i][j]=0;                          按下的位置數值設為0將圖片變為背景
}
void setup()
{
  size(300,400);
  bird=loadImage("bird.png");
  pig=loadImage("pige.png");
}
void draw()
{
  background(0);
  for(int i=0;i<4;i++)
  {
    for(int j=0;j<4;j++)
    {
      if(A[i][j]==1)image(bird,j*100,i*100,100,100);
      if(A[i][j]==2)image(pig,j*100,i*100,100,100);
    }
  }
  ellipse(mouseX,mouseY,25,25);           在滑鼠上畫個圓形圖案
  text("mouseX:"+mouseX+"mouseY:"+mouseY,100,100);
              滑鼠目前的坐標在畫面上顯示
}


沒有留言:

張貼留言