แสดงบทความที่มีป้ายกำกับ lab6.1 แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ lab6.1 แสดงบทความทั้งหมด

วันเสาร์ที่ 21 กันยายน พ.ศ. 2556

Solar




int i=0;
int[] moon= {
  0, 0, 1, 2, 39, 30, 21, 8
};
int[] radius= {
  10, 15, 15, 12, 50, 40, 30, 27
};
int[] distant= {
  8, 50, 90, 130, 170, 230, 280, 330
};
color[] c= {
  #903CD6, #3F2CF2, #07B711, #DEA241, #FF9D24, #D2E3A3, #8CD2E3, #83AABC
};
String[] planet = {
  "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Ouranos", "Neptune"
};

void setup() {
  background(0);
  size(500, 300);
}
void draw() {
  fill(random(209), random(54), random(12));
  ellipse(0, 150, 140, 140);
  ellipse(distant[5]+90, 150, 55, 7);
  drawstar();
  //drawmoon();
}
int a;
void drawstar() {

  while (i<distant.length) {
    fill(c[i]);
    text(planet[i], distant[i]+75, 200);
    ellipse(distant[i]+90, 150, radius[i], radius[i]);
    fill(255, 255, 0);

    if (a<moon[i]) {
      ellipse(distant[i]+90+a, 100, 3, 3);
      a=a+1;
    }else
     {a=0;}
    i=i+1;
  }
}

For loop

This program prints a four-line triangle of asterisks(*)
เครื่องหมายดอกจันทร์เรียงกันเป็ยสามเหลี่ยมจำนวนสี่แถว

for(int i=1;i<=4;i++){
  for(int j=1;j<=i;j++)
  print("*");
  println();
}


วันพฤหัสบดีที่ 19 กันยายน พ.ศ. 2556

Parallel array





void setup() {  
  size (450, 450);
  background(25);
}
void draw () {
  int x = 50;
  int i = 0;
  int j = 0;
  int y = 50;
  float [][] B = { { 13.51, 14.74, 12.598, 32.65, 26.50 } ,
                         { 8.86, 11.75, 15.07, 39.32, 24.99  } };

  while (i < B[0].length) {
    textSize(10);
    fill(#23FC55);
    rect (x, 380, 20, -B[0][i]*10);
    text(B[0][i]+"%", x,400);
    fill(#FC7C03);
    rect (x+20, 380, 20, -B[1][j]*10);
    text(B[1][i]+"%", x+20,400+10);
    i = i + 1;
    x = x + 70;
  }
  textSize(15);
  fill (#FC0AA8);
  text("No. of marine fishery establishments ", 30, 30);
}