A2 sourcecode
https://bitbucket.org/kevin_yuranan/assignment_2/src/9ecfc2a28d3673edb1564fb7e8278a3c9c0cf454/Assignment_2.java?at=default
My Commit
เปลี่ยน loop button ใหม่
https://bitbucket.org/kevin_yuranan/assignment_2/commits/daf05e184d5a60a031203bff6cb98a5441fbcc24?at=default
สร้างฟังก์ชั่นใหม่
https://bitbucket.org/kevin_yuranan/assignment_2/commits/1cf205cf30f215a55480bd06f9d6e7447fe89be7?at=default
เเก้ไขหน้า 10
https://bitbucket.org/kevin_yuranan/assignment_2/commits/767c101f6f663ebf3f237003bd83df4f6469c269?at=default
สลับหน้า 10 เเละ 11 เพื่อให้เนื้อหาต่อกัน
https://bitbucket.org/kevin_yuranan/assignment_2/commits/6623d57deb64827162fae5970781d1f2190998ef?at=default
เเก้ไขข้อมูลหน้า 10 จากที่สลับมา
https://bitbucket.org/kevin_yuranan/assignment_2/commits/5ac26a7a79c0333901025b95f54c84e8ccb6c236?at=default
ใส่ข้อมูลเพิ่มเติ่มหน้า 9
https://bitbucket.org/kevin_yuranan/assignment_2/commits/24c9311ca7bcfc7055ad5ea5eb391c30d95a9db5?at=default
เเก้ไขหน้า 5
https://bitbucket.org/kevin_yuranan/assignment_2/commits/9ecfc2a28d3673edb1564fb7e8278a3c9c0cf454?at=default
Computer Fundamental Blog
Tuesday, 16 December 2014
Tuesday, 25 November 2014
Lab 5 load table balloon
class Balloon {
float x;
float y;
float r;
Balloon(int x, int y, int r) {
this.x = x;
this.y = y;
this.r = r;
}
void display() {
line(this.x, this.y, this.x, this.y+this.r);
ellipse(this.x, this.y, this.r, this.r);
}
void move_up() {
this.y = this.y-3;
if (this.y < 0) {
this.y = height;
}
}
void move_right() {
this.x = this.x+1.5;
if (this.x > width) {
this.x = 0;
}
}
void fill_c() {
fill(this.x+this.y-445);
}
}
Balloon[] b;
Table table;
void setup() {
size(500, 500);
table = loadTable("data/new.csv", "header");
b = new Balloon[table.getRowCount()];
int index = 0;
for (TableRow row : table.rows ()) {
int pos_x = row.getInt("positionx");
int pos_y = row.getInt("positiony");
int radius = row.getInt("radius");
b[index] = new Balloon(pos_x,pos_y,radius);
index++;
}
}
void draw() {
background(255);
for(int i = 0; i < b.length; i++){
b[i].display();
}
}
float x;
float y;
float r;
Balloon(int x, int y, int r) {
this.x = x;
this.y = y;
this.r = r;
}
void display() {
line(this.x, this.y, this.x, this.y+this.r);
ellipse(this.x, this.y, this.r, this.r);
}
void move_up() {
this.y = this.y-3;
if (this.y < 0) {
this.y = height;
}
}
void move_right() {
this.x = this.x+1.5;
if (this.x > width) {
this.x = 0;
}
}
void fill_c() {
fill(this.x+this.y-445);
}
}
Balloon[] b;
Table table;
void setup() {
size(500, 500);
table = loadTable("data/new.csv", "header");
b = new Balloon[table.getRowCount()];
int index = 0;
for (TableRow row : table.rows ()) {
int pos_x = row.getInt("positionx");
int pos_y = row.getInt("positiony");
int radius = row.getInt("radius");
b[index] = new Balloon(pos_x,pos_y,radius);
index++;
}
}
void draw() {
background(255);
for(int i = 0; i < b.length; i++){
b[i].display();
}
}
Lab 5 save table balloon
Table table;
void setup() {
table = new Table();
table.addColumn("positiony", Table.INT);
table.addColumn("positionx", Table.INT);
table.addColumn("radius", Table.INT);
TableRow[] Row = new TableRow[2];
Row[0] = table.addRow();
Row[0].setInt("positionx", 300);
Row[0].setInt("positiony",300);
Row[0].setInt("radius", 60);
Row[1] = table.addRow();
Row[1].setInt("positionx",200);
Row[1].setInt("positiony",100);
Row[1].setInt("radius", 80);
saveTable(table, "data/new.csv");
}
void setup() {
table = new Table();
table.addColumn("positiony", Table.INT);
table.addColumn("positionx", Table.INT);
table.addColumn("radius", Table.INT);
TableRow[] Row = new TableRow[2];
Row[0] = table.addRow();
Row[0].setInt("positionx", 300);
Row[0].setInt("positiony",300);
Row[0].setInt("radius", 60);
Row[1] = table.addRow();
Row[1].setInt("positionx",200);
Row[1].setInt("positiony",100);
Row[1].setInt("radius", 80);
saveTable(table, "data/new.csv");
}
Sunday, 23 November 2014
Lab 5 cont class Queue New
class Data {
String name;
int priority;
Data(String name, int priority) {
this.name = name;
this.priority = priority;
}
String toString() {
String print = "Name#"+name+" Priority#"+priority;
return print;
}
}
class Queue {
Data[] wait;
int limit;
Queue(int limit) {
this.limit = limit;
this.wait = new Data[limit];
}
void show_queue() {
for (int i = 0; i < this.wait.length; i++) {
if (this.wait[i] != null) {
println(this.wait[i]);
}
}
}
void add(Data in) {
for (int i = 0; i < this.wait.length; i++) {
if ( this.wait[i] == null ) {
this.wait[i] = in;
i = this.wait.length;
}
}
}
void remove() {
int high = 0;
for (int i = 0; i < this.wait.length; i++) {
if (this.wait[i] != null) {
if (this.wait[high].priority < this.wait[i].priority) {
high = i;
}
}
}
this.wait[high] = null;
Data[] copy = new Data[this.limit];
for (int i = 0; i < copy.length; i++) {
copy[i] = this.wait[i];
this.wait[i] = null;
}
int count = 0;
for (int i = 0; i < copy.length; i++) {
if (copy[i] != null) {
this.wait[count] = copy[i];
count++;
}
}
}
}
Data[] human = new Data[322];
Queue hospital = new Queue(200);//max --> 2147483647
void setup() {
human[0] = new Data("Somsak", 30);
human[1] = new Data("Prasert", 30);
hospital.add(human[0]);
hospital.add(human[1]);
//hospital.remove();
//hospital.remove();
hospital.show_queue();
}
String name;
int priority;
Data(String name, int priority) {
this.name = name;
this.priority = priority;
}
String toString() {
String print = "Name#"+name+" Priority#"+priority;
return print;
}
}
class Queue {
Data[] wait;
int limit;
Queue(int limit) {
this.limit = limit;
this.wait = new Data[limit];
}
void show_queue() {
for (int i = 0; i < this.wait.length; i++) {
if (this.wait[i] != null) {
println(this.wait[i]);
}
}
}
void add(Data in) {
for (int i = 0; i < this.wait.length; i++) {
if ( this.wait[i] == null ) {
this.wait[i] = in;
i = this.wait.length;
}
}
}
void remove() {
int high = 0;
for (int i = 0; i < this.wait.length; i++) {
if (this.wait[i] != null) {
if (this.wait[high].priority < this.wait[i].priority) {
high = i;
}
}
}
this.wait[high] = null;
Data[] copy = new Data[this.limit];
for (int i = 0; i < copy.length; i++) {
copy[i] = this.wait[i];
this.wait[i] = null;
}
int count = 0;
for (int i = 0; i < copy.length; i++) {
if (copy[i] != null) {
this.wait[count] = copy[i];
count++;
}
}
}
}
Data[] human = new Data[322];
Queue hospital = new Queue(200);//max --> 2147483647
void setup() {
human[0] = new Data("Somsak", 30);
human[1] = new Data("Prasert", 30);
hospital.add(human[0]);
hospital.add(human[1]);
//hospital.remove();
//hospital.remove();
hospital.show_queue();
}
Tuesday, 18 November 2014
Lab 5 cont class Queue
class Data {
String name;
int priority;
Data(String name, int priority) {
this.name = name;
this.priority = priority;
}
String toString() {
String print = "name#"+name+" priority#"+priority;
return print;
}
}
class Queue {
Data[] wait = new Data[1];
int limit;
Queue(int limit) {
this.limit = limit;
this.wait = new Data[limit];
}
void show_queue() {
for (int i = 0; i < wait.length; i++) {
if (wait[i] != null) {
println(wait[i]);
}
}
}
void add(Data in) {
for (int i = 0; i < wait.length; i++) {
if ( wait[i] == null ) {
wait[i] = in;
i = wait.length;
}
}
}
void remove() {
int high = 0;
for (int i = 0; i < wait.length; i++) {
if (wait[i] != null) {
if (wait[high].priority < wait[i].priority) {
high = i;
}
}
}
wait[high] = null;
}
}
Data human;
Data human2;
Queue hos = new Queue(50);
void setup() {
human = new Data("Somsak", 300);
human2 = new Data("Prasert", 60);
hos.add(human);
hos.add(human2);
hos.remove();
hos.show_queue();
}
String name;
int priority;
Data(String name, int priority) {
this.name = name;
this.priority = priority;
}
String toString() {
String print = "name#"+name+" priority#"+priority;
return print;
}
}
class Queue {
Data[] wait = new Data[1];
int limit;
Queue(int limit) {
this.limit = limit;
this.wait = new Data[limit];
}
void show_queue() {
for (int i = 0; i < wait.length; i++) {
if (wait[i] != null) {
println(wait[i]);
}
}
}
void add(Data in) {
for (int i = 0; i < wait.length; i++) {
if ( wait[i] == null ) {
wait[i] = in;
i = wait.length;
}
}
}
void remove() {
int high = 0;
for (int i = 0; i < wait.length; i++) {
if (wait[i] != null) {
if (wait[high].priority < wait[i].priority) {
high = i;
}
}
}
wait[high] = null;
}
}
Data human;
Data human2;
Queue hos = new Queue(50);
void setup() {
human = new Data("Somsak", 300);
human2 = new Data("Prasert", 60);
hos.add(human);
hos.add(human2);
hos.remove();
hos.show_queue();
}
New Matrix
class Matrix {
int[][] mat;
int error;
Matrix(int[][] mat) {
this.mat = mat;
this.error = 0;
}
Matrix() {
this.error = 1;
}
String toString() {
if( this.error == 0){
String print = "Matrix";
for (int i = 0; i < this.mat.length; i++) {
print = print+" Row"+i+"#";
for (int j = 0; j < this.mat[i].length; j++) {
print = print+" "+this.mat[i][j];
}
}
return print;
}
else{
String print = "ERROR";
return print;
}
}
Matrix add(Matrix in) {
if (this.mat.length != in.mat.length) {
Matrix sum = new Matrix();
return sum;
} else {
int[][] result = new int[this.mat.length][this.mat[0].length];
for (int i = 0; i < this.mat.length; i++) {
for (int j = 0; j < this.mat[i].length; j++) {
result [i][j] = this.mat[i][j]+in.mat[i][j];
}
}
Matrix sum = new Matrix(result);
return sum;
}
}
Matrix minus(Matrix in) {
if (this.mat.length != in.mat.length) {
Matrix sum = new Matrix();
return sum;
} else {
int[][] result = new int[this.mat.length][this.mat[0].length];
for (int i = 0; i < this.mat.length; i++) {
for (int j = 0; j < this.mat[i].length; j++) {
result [i][j] = this.mat[i][j]-in.mat[i][j];
}
}
Matrix sum = new Matrix(result);
return sum;
}
}
}
int[][] math = {
{
5, 5, 5
}
, {
4, 4, 4
}
, {
2, 2, 2
}
};
int[][] math2 = {
{
5, 5, 5
}
, {
4, 4, 4
}
, {
2, 2, 2
}
};
Matrix m;
Matrix m2;
void setup() {
m = new Matrix(math);
m2 = new Matrix(math2);
println(m.add(m2));
println(m.minus(m2));
}
int[][] mat;
int error;
Matrix(int[][] mat) {
this.mat = mat;
this.error = 0;
}
Matrix() {
this.error = 1;
}
String toString() {
if( this.error == 0){
String print = "Matrix";
for (int i = 0; i < this.mat.length; i++) {
print = print+" Row"+i+"#";
for (int j = 0; j < this.mat[i].length; j++) {
print = print+" "+this.mat[i][j];
}
}
return print;
}
else{
String print = "ERROR";
return print;
}
}
Matrix add(Matrix in) {
if (this.mat.length != in.mat.length) {
Matrix sum = new Matrix();
return sum;
} else {
int[][] result = new int[this.mat.length][this.mat[0].length];
for (int i = 0; i < this.mat.length; i++) {
for (int j = 0; j < this.mat[i].length; j++) {
result [i][j] = this.mat[i][j]+in.mat[i][j];
}
}
Matrix sum = new Matrix(result);
return sum;
}
}
Matrix minus(Matrix in) {
if (this.mat.length != in.mat.length) {
Matrix sum = new Matrix();
return sum;
} else {
int[][] result = new int[this.mat.length][this.mat[0].length];
for (int i = 0; i < this.mat.length; i++) {
for (int j = 0; j < this.mat[i].length; j++) {
result [i][j] = this.mat[i][j]-in.mat[i][j];
}
}
Matrix sum = new Matrix(result);
return sum;
}
}
}
int[][] math = {
{
5, 5, 5
}
, {
4, 4, 4
}
, {
2, 2, 2
}
};
int[][] math2 = {
{
5, 5, 5
}
, {
4, 4, 4
}
, {
2, 2, 2
}
};
Matrix m;
Matrix m2;
void setup() {
m = new Matrix(math);
m2 = new Matrix(math2);
println(m.add(m2));
println(m.minus(m2));
}
Monday, 17 November 2014
New Complex
class Complex{
float real_num;
float imaginary_num;
Complex(float real_num, float imaginary_num){
this.real_num = real_num;
this.imaginary_num = imaginary_num;
}
String toString(){
if(this.imaginary_num >= 0){
String print = this.real_num+"+"+this.imaginary_num+"i";
return print;
}
else{
String print = this.real_num+""+this.imaginary_num+"i";
return print;
}
}
Complex plus(Complex complex){
Complex m = new Complex(this.real_num+complex.real_num,this.imaginary_num+complex.imaginary_num);
return m;
}
Complex minus(Complex complex){
Complex m = new Complex(this.real_num-complex.real_num,this.imaginary_num-complex.imaginary_num);
return m;
}
}
Complex a;
Complex b;
void setup(){
a = new Complex(4,5);
b = new Complex(2,2);
println(b.minus(a));
println(a.plus(b));
}
float real_num;
float imaginary_num;
Complex(float real_num, float imaginary_num){
this.real_num = real_num;
this.imaginary_num = imaginary_num;
}
String toString(){
if(this.imaginary_num >= 0){
String print = this.real_num+"+"+this.imaginary_num+"i";
return print;
}
else{
String print = this.real_num+""+this.imaginary_num+"i";
return print;
}
}
Complex plus(Complex complex){
Complex m = new Complex(this.real_num+complex.real_num,this.imaginary_num+complex.imaginary_num);
return m;
}
Complex minus(Complex complex){
Complex m = new Complex(this.real_num-complex.real_num,this.imaginary_num-complex.imaginary_num);
return m;
}
}
Complex a;
Complex b;
void setup(){
a = new Complex(4,5);
b = new Complex(2,2);
println(b.minus(a));
println(a.plus(b));
}
Subscribe to:
Posts (Atom)