my project comfun :)
วันอาทิตย์ที่ 6 กรกฎาคม พ.ศ. 2557
book :)
void setup(){
size(300,300); // กำหนดขนาดของ canvas
background(251,128,105); // กำหนดสีพื้นหลัง
int a = 80; // ปรกาศตัวแปร local ชนิด int ชื่อ a กำหนดค่าเป็น 80
int b = 135; // ปรกาศตัวแปร local ชนิด int ชื่อ b กำหนดค่าเป็น 135
int c = 165; // ปรกาศตัวแปร local ชนิด int ชื่อ c กำหนดค่าเป็น 165
int d = 220; // ปรกาศตัวแปร local ชนิด int ชื่อ d กำหนดค่าเป็น 220
int e = 60; // ปรกาศตัวแปร local ชนิด int ชื่อ e กำหนดค่าเป็น 60
int f = 85; // ปรกาศตัวแปร local ชนิด int ชื่อ f กำหนดค่าเป็น 85
noStroke(); // กำหนดให้ภาพที่แสดงไม่มีเส้น
fill(0,64,128); // กำหนดสีของปกหนังสือ
rect(e,f,180,130); // เรียกใช้คำสั่ง rect() วาดสี่เหลี่ยมผืนผ้า โดยกำหนดจุด x และ y รับค่าจากตัวแปร e และ f
fill(255); // กำหนดสีของแผ่นกระดาษ
rect(e + 10,f + 10,160,110); // เรียกใช้คำสั่ง rect() วาดสี่เหลี่ยมผืนผ้าโดยกำหนดจุด x และ y รับค่าจากตัวแปร e และ f และเพิ่มค่าคงที่ให้ตัวแปร e และ f ในคำสั่งแทน โดย ค่า e เพิ่มอีก 10 เป็น 70 และ ค่า f เพิ่มอีก 10 เป็น 95
fill(116,198,156); // กำหนดสีของสันหนังสือ
rect(e + 85,f,10,130); // เรียกใช้คำสั่ง rect() วาดสี่เหลี่ยมผืนผ้า โดยกำหนดจุด x และ y รับค่าจากตัวแปร e และ f และเพิ่มค่าคงที่ให้ตัวแปร e ในคำสั่งแทน โดย ค่า e เพิ่มอีก 85 เป็น 145
stroke(0); // กำหนดให้ภาพที่แสดงมีเส้น เนื่องจากคำสั่ง noStroke() ทำให้ภาพที่แสดงไม่มีเส้น คำสั่ง line() จะไม่แสดงผล
line(a,115,b,115);
line(a,125,b,125);
line(a,135,b,135);
line(a,145,b,145);
line(a,155,b,155);
line(a,165,b,165);
line(a,175,b,175);
line(a,185,b,185);
// เรียกใช้คำสั่ง line() 8 ครั้งเพื่อวาดเส้นตรง 8 เส้นด้านซ้ายของรูป โดยกำหนดจุด x รับค่าจากตัวแปร a และ b
line(c,115,d,115);
line(c,125,d,125);
line(c,135,d,135);
line(c,145,d,145);
line(c,155,d,155);
line(c,165,d,165);
line(c,175,d,175);
line(c,185,d,185);
// เรียกใช้คำสั่ง line() 8 ครั้งเพื่อวาดเส้นตรง 8 เส้นด้านขวาของรูป โดยกำหนดจุด x รับค่าจากตัวแปร c และ d
}
วันอาทิตย์ที่ 22 กันยายน พ.ศ. 2556
Continue
for(int i = 0; i < 100; i += 5) {
if (i == 50) {
continue;
}
line(i, 0, i, 100);
}
}
Chess
int r = 38;
void setup(){
size(400, 400);
int x, y, i, j;
int[][] Chess= {
{
2, 3, 4, 6, 5, 4, 3, 2
}
, {
1, 1, 1, 1, 1, 1, 1, 1
}
, {
0, 0, 0, 0, 0, 0, 0, 0
}
, {
0, 0, 0, 0, 0, 0, 0, 0
}
, {
0, 0, 0, 0, 0, 0, 0, 0
}
, {
0, 0, 0, 0, 0, 0, 0, 0
}
, {
1, 1, 1, 1, 1, 1, 1, 1
}
, {
2, 3, 4, 6, 5, 4, 3, 2
}
};
strokeWeight(4);
for (y=0,i=0 ; i<Chess.length ; i++,y+=50){
for (x=0,j=0 ; j<Chess.length ; j++,x+=50){
if ((j+i)%2 == 0){
fill(66, 217, 146);
}
else fill(192);
rect(x, y, 200, 200);
}
}
for (y=25,i=0 ; i<Chess.length ; i++,y+=50){
for (x=25,j=0 ; j<Chess.length ; j++,x+=50){
if (y<200){
fill(0);
}
else{
fill(255);
}
if (Chess[i][j]==1){
Prawn(x, y);
}
else if (Chess[i][j]==2){
Rook(x, y);
}
else if (Chess[i][j]==3){
Knight(x, y);
}
else if (Chess[i][j]==4){
Bishop(x, y);
}
else if (Chess[i][j]==5){
Queen(x, y);
}
else if (Chess[i][j]==6){
King(x, y);
}
}
}
}
void Rook(int x, int y){
ellipse(x, y, r, r);
fill(255,0,0);
text("Rook", x-14, y+4);
}
}
else if (Chess[i][j]==2){
Rook(x, y);
}
else if (Chess[i][j]==3){
Knight(x, y);
}
else if (Chess[i][j]==4){
Bishop(x, y);
}
else if (Chess[i][j]==5){
Queen(x, y);
}
else if (Chess[i][j]==6){
King(x, y);
}
}
}
}
void Rook(int x, int y){
ellipse(x, y, r, r);
fill(255,0,0);
text("Rook", x-14, y+4);
}
void Knight(int x, int y){
ellipse(x, y, r, r);
fill(255,0,0);
text("Knight", x-17, y+4);
}
void Bishop(int x, int y){
ellipse(x, y, r, r);
fill(255,0,0);
text("Bishop", x-18, y+4);
}
void Queen(int x, int y) {
ellipse(x, y, r, r);
fill(255,0,0);
text("Queen", x-18, y+4);
}
void King(int x, int y) {
ellipse(x, y, r, r);
fill(255,0,0);
text("King", x-12, y+4);
}
void Prawn(int x, int y){
ellipse(x, y, r, r);
}
base&derived class
void setup() {
Animal a = new Animal();
Animal b = new Dog();
a.move();
b.move();
}
class Animal {
void move() {
println("Animal move >w<");
}
}
class Dog extends Animal {
void move() {
println("Dog move -w-");
}
}
gcd & lcd
void setup(){
int x = 4;
int y = 6;
println(gcd(x,y));
println(lcd(8, 2));}
int gcd(int x,int y){
if (x == 0){
return y;
}
if (y == 0){
return x;
}
if (x > y){
return gcd(y,x % y);
}
else{
return gcd(x,y % x);
}
}
int lcd(int x, int y) {
return (x*y)/gcd(x, y);
}
Button
void setup() {
size(200, 200);
background(255);
println(a.toString());
println(b.toString());
a.Clicked();
a.Display();
}
Button a = new Button("moowan", 100, 100, 50);
Button b = new Button();
void draw() {
a.Display();
b.Display();
}
class Button {
int k = 0;
int x;
int y;
int s;
String name;
Button(String n, int a, int b, int c) {
this.name = n;
this.x = a;
this.y = b;
this.s = c;
}
Button() {
this.name = "Kananard";
this.x = 50;
this.y = 50;
this.s = 20;
}
String toString() {
String s = this.name;
return s;
}
void Clicked() {
if ((mousePressed && mouseX >=x && mousePressed && mouseX <=x + s) && (mousePressed && mouseY >= y && mousePressed && mouseY <= y + s)) {
if (k % 8 == 0) {
println(this.name);
}
k = k + 1;
}
}
void Display() {
rect(x, y, s, s);
a.Clicked();
b.Clicked();
}
}
Palindrome
String s = "CIVIC";
if (isPalindrome(s)) {
println(s + " is a palindrome");
}
else {
println(s + " is not a palindrome");
}
}
String reverseString(String s){
String show = "";
for (int index=0;index<s.length();index++){
show += s.charAt(s.length() - index - 1);
}
return show;
}
boolean isPalindrome(String s){
return s.equals(reverseString(s));
}
println(s + " is not a palindrome");
}
}
String reverseString(String s){
String show = "";
for (int index=0;index<s.length();index++){
show += s.charAt(s.length() - index - 1);
}
return show;
}
boolean isPalindrome(String s){
return s.equals(reverseString(s));
}
สมัครสมาชิก:
บทความ (Atom)