void setup()
{
size(800, 800);
}
void draw()
{
background(247,247,135);
noFill();
strokeWeight(5);
rect(50,50,700,700);
strokeWeight(1);
for (int i = 0; i < 10 ; i++)
{
line(50,50+i*70, 750 , 50+i*70);
line(50+i*70, 50, 50+i*70, 750);
}
}
2. 擺棋子
3. 運用滑鼠事件來達到 點一下在畫的功能(放棋子)
int nowX, nowY;
int [][]array = new int [10][10]; //宣告陣列 將棋盤方格化
void setup()
{
size(800, 800);
}
void draw()
{
background(247, 247, 135);
noFill();
strokeWeight(5);
rect(50, 50, 700, 700);
strokeWeight(1);
for (int i = 0; i < 10 ; i++)
{
line(50, 50+i*70, 750, 50+i*70);
line(50+i*70, 50, 50+i*70, 750);
}
fill(255, 255, 255, 80);
rect(nowX*70+85, nowY*70+85, 70, 70);
fill(0);
for (int i = 0 ; i < 10; i++)
{
for (int j = 0; j < 10 ;j++)
{
if (array[i][j] == 1)
{
rect(i*70+85, j*70+85, 70, 70);
}
}
}
}
void mousePressed()
{
array[nowX][nowY]=1;
}
void mouseMoved()
{
nowX = (mouseX-50)/70;
nowY = (mouseY-50)/70;
}
3.1 把格子修改成棋子 並切換顏色
int nowX, nowY,nowcolor=1;
int [][]array = new int [10][10]; //宣告陣列 將棋盤方格化
void setup()
{
size(800, 800);
}
void draw()
{
background(247, 247, 135);
noFill();
strokeWeight(5);
rect(50, 50, 700, 700);
strokeWeight(1);
for (int i = 0; i < 10 ; i++)
{
line(50, 50+i*70, 750, 50+i*70);
line(50+i*70, 50, 50+i*70, 750);
}
fill(255, 255, 255, 80);
ellipse(nowX*70+120, nowY*70+120, 70, 70);
fill(0);
for (int i = 0 ; i < 10; i++)
{
for (int j = 0; j < 10 ;j++)
{
if (array[i][j] == 1){fill(0); ellipse(i*70+120, j*70+120, 70, 70); }
else if (array[i][j]==2){fill(255); ellipse(i*70+120, j*70+120, 70, 70); }
}
}
}
void mousePressed()
{
array[nowX][nowY]=nowcolor;
if (nowcolor==1) nowcolor=2;
else if (nowcolor==2) nowcolor=1;
}
void mouseMoved()
{
nowX = (mouseX-50)/70;
nowY = (mouseY-50)/70;
}
4. 貼你覺得有意思的影片, 使用youtube 的分享, Blogger 分享, 兩邊都改成 HTML, 貼上 HTML
沒有留言:
張貼留言