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
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));
}
Tuesday, 11 November 2014
Lab 5 Matrix
class Matrix{
int main_matrix[][];
int column;
Matrix exmatrix;
Matrix(int main_matrix[][], int column){
this.main_matrix = main_matrix;
this.column = column;
}
void printm(){
println("#Matrix#");
for(int i = 0; i < this.main_matrix.length; i++){
print("[ ");
for(int i2 = 0; i2 < this.column; i2 += 1){
print(this.main_matrix[i][i2]+" ");
}
println("]");
}
println("########");
}
Matrix plus(Matrix in){
this.exmatrix = in;
if((this.exmatrix.main_matrix.length == this.main_matrix.length) && (this.exmatrix.column == this.column)){
int[][] ans = new int[this.main_matrix.length][this.column];
for(int i = 0; i < this.main_matrix.length; i++){
for(int i2 = 0; i2 < this.column; i2 += 1){
ans[i][i2] = (this.main_matrix[i][i2])+(this.exmatrix.main_matrix[i][i2]);
}
}
Matrix m = new Matrix(ans,this.column);
return m;
}
else{
println(" Row and Column are not the same");
int[][] ans = new int[this.main_matrix.length][this.column];
Matrix m = new Matrix(ans,this.column);
return m;
}
}
Matrix minus(Matrix in){
this.exmatrix = in;
if((this.exmatrix.main_matrix.length == this.main_matrix.length) && (this.exmatrix.column == this.column)){
int[][] ans = new int[this.main_matrix.length][this.column];
for(int i = 0; i < this.main_matrix.length; i++){
for(int i2 = 0; i2 < this.column; i2 += 1){
ans[i][i2] = (this.main_matrix[i][i2])-(this.exmatrix.main_matrix[i][i2]);
}
}
Matrix m = new Matrix(ans,this.column);
return m;
}
else{
println(" Row and Column are not the same");
int[][] ans = new int[this.main_matrix.length][this.column];
Matrix m = new Matrix(ans,this.column);
return m;
}
}
}
int[][] amatrix = {{2,2,4,4},
{3,3,4,6},
{3,2,2,7}};
int[][] bmatrix = {{4,4,3,4},
{3,3,4,6},
{3,3,4,6}};
void setup(){
Matrix a = new Matrix(amatrix, 4);//(2d array, column)
Matrix b = new Matrix(bmatrix, 4);
a.printm();
b.printm();
a.plus(b).printm();
a.minus(b).printm();
}
int main_matrix[][];
int column;
Matrix exmatrix;
Matrix(int main_matrix[][], int column){
this.main_matrix = main_matrix;
this.column = column;
}
void printm(){
println("#Matrix#");
for(int i = 0; i < this.main_matrix.length; i++){
print("[ ");
for(int i2 = 0; i2 < this.column; i2 += 1){
print(this.main_matrix[i][i2]+" ");
}
println("]");
}
println("########");
}
Matrix plus(Matrix in){
this.exmatrix = in;
if((this.exmatrix.main_matrix.length == this.main_matrix.length) && (this.exmatrix.column == this.column)){
int[][] ans = new int[this.main_matrix.length][this.column];
for(int i = 0; i < this.main_matrix.length; i++){
for(int i2 = 0; i2 < this.column; i2 += 1){
ans[i][i2] = (this.main_matrix[i][i2])+(this.exmatrix.main_matrix[i][i2]);
}
}
Matrix m = new Matrix(ans,this.column);
return m;
}
else{
println(" Row and Column are not the same");
int[][] ans = new int[this.main_matrix.length][this.column];
Matrix m = new Matrix(ans,this.column);
return m;
}
}
Matrix minus(Matrix in){
this.exmatrix = in;
if((this.exmatrix.main_matrix.length == this.main_matrix.length) && (this.exmatrix.column == this.column)){
int[][] ans = new int[this.main_matrix.length][this.column];
for(int i = 0; i < this.main_matrix.length; i++){
for(int i2 = 0; i2 < this.column; i2 += 1){
ans[i][i2] = (this.main_matrix[i][i2])-(this.exmatrix.main_matrix[i][i2]);
}
}
Matrix m = new Matrix(ans,this.column);
return m;
}
else{
println(" Row and Column are not the same");
int[][] ans = new int[this.main_matrix.length][this.column];
Matrix m = new Matrix(ans,this.column);
return m;
}
}
}
int[][] amatrix = {{2,2,4,4},
{3,3,4,6},
{3,2,2,7}};
int[][] bmatrix = {{4,4,3,4},
{3,3,4,6},
{3,3,4,6}};
void setup(){
Matrix a = new Matrix(amatrix, 4);//(2d array, column)
Matrix b = new Matrix(bmatrix, 4);
a.printm();
b.printm();
a.plus(b).printm();
a.minus(b).printm();
}
Saturday, 8 November 2014
Lab 5 Complex number
class Complex{
float real_num;
float imaginary_num;
Complex complex;
Complex(float real_num, float imaginary_num){
this.real_num = real_num;
this.imaginary_num = imaginary_num;
}
void printcln(){
if(this.imaginary_num >= 0){
println(this.real_num+"+"+this.imaginary_num+"i");
}
else{
println(this.real_num+""+this.imaginary_num+"i");
}
}
void printc(){
if(this.imaginary_num >= 0){
print(this.real_num+"+"+this.imaginary_num+"i");
}
else{
print(this.real_num+""+this.imaginary_num+"i");
}
}
Complex plus(Complex c){
this.complex = c;
Complex m = new Complex(this.real_num+this.complex.real_num,this.imaginary_num+this.complex.imaginary_num);
return m;
}
Complex minus(Complex c){
this.complex = c;
Complex m = new Complex(this.real_num-this.complex.real_num,this.imaginary_num-this.complex.imaginary_num);
return m;
}
}
Complex a;
Complex b;
void setup(){
a = new Complex(4,5);
b = new Complex(2,2);
a.printcln();
a.plus(b).printcln();
a.minus(b).printcln();
b.minus(a).printcln();
}
float real_num;
float imaginary_num;
Complex complex;
Complex(float real_num, float imaginary_num){
this.real_num = real_num;
this.imaginary_num = imaginary_num;
}
void printcln(){
if(this.imaginary_num >= 0){
println(this.real_num+"+"+this.imaginary_num+"i");
}
else{
println(this.real_num+""+this.imaginary_num+"i");
}
}
void printc(){
if(this.imaginary_num >= 0){
print(this.real_num+"+"+this.imaginary_num+"i");
}
else{
print(this.real_num+""+this.imaginary_num+"i");
}
}
Complex plus(Complex c){
this.complex = c;
Complex m = new Complex(this.real_num+this.complex.real_num,this.imaginary_num+this.complex.imaginary_num);
return m;
}
Complex minus(Complex c){
this.complex = c;
Complex m = new Complex(this.real_num-this.complex.real_num,this.imaginary_num-this.complex.imaginary_num);
return m;
}
}
Complex a;
Complex b;
void setup(){
a = new Complex(4,5);
b = new Complex(2,2);
a.printcln();
a.plus(b).printcln();
a.minus(b).printcln();
b.minus(a).printcln();
}
Wednesday, 5 November 2014
Lab 5 Fraction
class Fraction{
float top;
float btm;
Fraction fraction;
Fraction(float top, float btm){
this.top = top;
this.btm = btm;
}
void printf(){
print(this.top+"/"+this.btm);
}
void printfln(){
println(this.top+"/"+this.btm);
}
float decimal(){
return this.top/this.btm;
}
void printdecimalln(){
print(this.top/this.btm);
}
Fraction plus(Fraction f){
this.fraction = f;
if(this.btm == this.fraction.btm){
Fraction m = new Fraction(this.top+this.fraction.top,this.btm);
return m;
}
else{
Fraction m = new Fraction((this.top*fraction.btm)+(this.fraction.top*this.btm),(this.fraction.btm*this.btm));
return m;
}
}
Fraction minus(Fraction f){
this.fraction = f;
if(this.btm == this.fraction.btm){
Fraction m = new Fraction(this.top-this.fraction.top,this.btm);
return m;
}
else{
Fraction m = new Fraction((this.top*fraction.btm)-(this.fraction.top*this.btm),(this.fraction.btm*this.btm));
return m;
}
}
Fraction multiply(Fraction f){
this.fraction = f;
Fraction m = new Fraction(this.top*this.fraction.top,this.btm*this.fraction.btm);
return m;
}
Fraction devide(Fraction f){
this.fraction = f;
Fraction m = new Fraction(this.top*this.fraction.btm,this.btm*this.fraction.top);
return m;
}
}
Fraction a = new Fraction(1,4);
Fraction b = new Fraction(1,5);
void setup(){
a.printfln();
b.printfln();
println(a.decimal());
println(b.decimal());
(a.plus(b)).printfln();
(a.minus(b)).printfln();
(a.multiply(b)).printfln();
(a.devide(b)).printfln();
}
float top;
float btm;
Fraction fraction;
Fraction(float top, float btm){
this.top = top;
this.btm = btm;
}
void printf(){
print(this.top+"/"+this.btm);
}
void printfln(){
println(this.top+"/"+this.btm);
}
float decimal(){
return this.top/this.btm;
}
void printdecimalln(){
print(this.top/this.btm);
}
Fraction plus(Fraction f){
this.fraction = f;
if(this.btm == this.fraction.btm){
Fraction m = new Fraction(this.top+this.fraction.top,this.btm);
return m;
}
else{
Fraction m = new Fraction((this.top*fraction.btm)+(this.fraction.top*this.btm),(this.fraction.btm*this.btm));
return m;
}
}
Fraction minus(Fraction f){
this.fraction = f;
if(this.btm == this.fraction.btm){
Fraction m = new Fraction(this.top-this.fraction.top,this.btm);
return m;
}
else{
Fraction m = new Fraction((this.top*fraction.btm)-(this.fraction.top*this.btm),(this.fraction.btm*this.btm));
return m;
}
}
Fraction multiply(Fraction f){
this.fraction = f;
Fraction m = new Fraction(this.top*this.fraction.top,this.btm*this.fraction.btm);
return m;
}
Fraction devide(Fraction f){
this.fraction = f;
Fraction m = new Fraction(this.top*this.fraction.btm,this.btm*this.fraction.top);
return m;
}
}
Fraction a = new Fraction(1,4);
Fraction b = new Fraction(1,5);
void setup(){
a.printfln();
b.printfln();
println(a.decimal());
println(b.decimal());
(a.plus(b)).printfln();
(a.minus(b)).printfln();
(a.multiply(b)).printfln();
(a.devide(b)).printfln();
}
Lab 5 2 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);
}
}
this.x =
Balloon b1;
Balloon b2;
void setup(){
size(500, 500);
b1 = new Balloon(150, 150, 50);
b2 = new Balloon(250, 250, 50);
}
void draw(){
background(255);
b1.fill_c();
b1.display();
b1.move_up();
b1.move_right();
b2.fill_c();
b2.display();
b2.move_up();
b2.move_right();
}
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);
}
}
this.x =
Balloon b1;
Balloon b2;
void setup(){
size(500, 500);
b1 = new Balloon(150, 150, 50);
b2 = new Balloon(250, 250, 50);
}
void draw(){
background(255);
b1.fill_c();
b1.display();
b1.move_up();
b1.move_right();
b2.fill_c();
b2.display();
b2.move_up();
b2.move_right();
}
Lab 5 1 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;
void setup(){
size(500, 500);
b = new Balloon(250, 250, 50);
}
void draw(){
background(255);
b.fill_c();
b.display();
b.move_up();
b.move_right();
}
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;
void setup(){
size(500, 500);
b = new Balloon(250, 250, 50);
}
void draw(){
background(255);
b.fill_c();
b.display();
b.move_up();
b.move_right();
}
Lab 5 Table / Load Table
Table table;
void setup() {
table = new Table();
table.addColumn("name", Table.STRING);
table.addColumn("age", Table.INT);
table.addColumn("height", Table.FLOAT);
table.addColumn("weight", Table.FLOAT);
TableRow[] Row = new TableRow[2];
Row[0] = table.addRow();
Row[0].setString("name", "Jermaine");
Row[0].setInt("age", 15);
Row[0].setFloat("height", 188);
Row[0].setFloat("weight", 20);
Row[1] = table.addRow();
Row[1].setString("name", "Chanon");
Row[1].setInt("age", 32);
Row[1].setFloat("height", 188);
Row[1].setFloat("weight", 120);
saveTable(table, "data/new.csv");
}
-------------------------------------------------------------
table = loadTable("data/new.csv", "header");
println(table.getRowCount() + " total rows in table");
for (TableRow row : table.rows()) {
float h = row.getFloat("height");
int a = row.getInt("age");
float w = row.getFloat("weight");
String name = row.getString("name");
println(name + " has a " + w + " kg and " + h + " cm and age of " + a);
}
}
void setup() {
table = new Table();
table.addColumn("name", Table.STRING);
table.addColumn("age", Table.INT);
table.addColumn("height", Table.FLOAT);
table.addColumn("weight", Table.FLOAT);
TableRow[] Row = new TableRow[2];
Row[0] = table.addRow();
Row[0].setString("name", "Jermaine");
Row[0].setInt("age", 15);
Row[0].setFloat("height", 188);
Row[0].setFloat("weight", 20);
Row[1] = table.addRow();
Row[1].setString("name", "Chanon");
Row[1].setInt("age", 32);
Row[1].setFloat("height", 188);
Row[1].setFloat("weight", 120);
saveTable(table, "data/new.csv");
}
-------------------------------------------------------------
table = loadTable("data/new.csv", "header");
println(table.getRowCount() + " total rows in table");
for (TableRow row : table.rows()) {
float h = row.getFloat("height");
int a = row.getInt("age");
float w = row.getFloat("weight");
String name = row.getString("name");
println(name + " has a " + w + " kg and " + h + " cm and age of " + a);
}
}
Lab 5 cont House Window Door
class House{
int house_x;
int house_y;
int house_w;
int house_h;
Door door;
Window window_left;
Window window_right;
int Door_Set;
int Window_Set;
House(int house_x, int house_y, int house_w, int house_h){
this.house_x = house_x;
this.house_y = house_y;
this.house_w = house_w;
this.house_h = house_h;
this.Window_Set = 0;
this.Door_Set = 0;
}
void drawWindow(Window w_l, Window w_r){
this.window_left = w_l;
this.window_right = w_r;
this.Window_Set = 1;
}
void drawDoor(Door d){
this.door = d;
this.Door_Set = 1;
}
void display(){
rect(this.house_x, this.house_y, this.house_w, this.house_h);
triangle(this.house_x, this.house_y, this.house_x+this.house_w, this.house_y, this.house_x+(this.house_w/2),this.house_y-(this.house_h/2));
if( this.Door_Set == 1){
this.door.display();
}
if( this.Window_Set == 1){
this.window_left.display();
this.window_right.display();
}
}
void move_left(){
this.house_x += 1;
if(this.house_x > width+150){this.house_x = -150;}
if( this.Door_Set == 1){
this.door.move_left();
}
if( this.Window_Set == 1){
this.window_left.move_left();
this.window_right.move_left();
}
}
}
class Door{
int door_x;
int door_y;
int door_w;
int door_h;
Door(int door_x, int door_y, int door_w, int door_h){
this.door_x = door_x;
this.door_y = door_y;
this.door_w = door_w;
this.door_h = door_h;
}
Door(){
this.door_x = 0;
this.door_y = 0;
this.door_w = 0;
this.door_h = 0;
}
void display(){
rect(this.door_x, this.door_y, this.door_w, this.door_h);
}
void move_left(){
this.door_x +=1;
if(this.door_x > width+150){ this.door_x = -150;}
}
}
class Window{
int window_x;
int window_y;
int window_w;
int window_h;
Window(int window_x, int window_y, int window_w, int window_h){
this.window_x = window_x;
this.window_y = window_y;
this.window_w = window_w;
this.window_h = window_h;
}
Window(){
this.window_x = 0;
this.window_y = 0;
this.window_w = 0;
this.window_h = 0;
}
void display(){
rect(this.window_x, this.window_y, this.window_w, this.window_h);
}
void move_left(){
this.window_x +=1;
if(this.window_x > width+150){ this.window_x = -150;}
}
}
House h;
Door d;
Window window_left;
Window window_right;
Window no_window = new Window(0,0,0,0);
House k;
void setup(){
size(300, 300);
h = new House(100,100,100,50);
k = new House(100,200,100,50);
d = new Door(130,125,40,25);
window_left = new Window(110, 110, 10, 10);
window_right = new Window(180, 110, 10, 10);
h.drawDoor(d);
h.drawWindow(window_left, window_right);
//h.drawWindow(window_left, no_window);
}
void draw(){
background(255);
h.display();
k.display();
k.move_left();
h.move_left();
}
int house_x;
int house_y;
int house_w;
int house_h;
Door door;
Window window_left;
Window window_right;
int Door_Set;
int Window_Set;
House(int house_x, int house_y, int house_w, int house_h){
this.house_x = house_x;
this.house_y = house_y;
this.house_w = house_w;
this.house_h = house_h;
this.Window_Set = 0;
this.Door_Set = 0;
}
void drawWindow(Window w_l, Window w_r){
this.window_left = w_l;
this.window_right = w_r;
this.Window_Set = 1;
}
void drawDoor(Door d){
this.door = d;
this.Door_Set = 1;
}
void display(){
rect(this.house_x, this.house_y, this.house_w, this.house_h);
triangle(this.house_x, this.house_y, this.house_x+this.house_w, this.house_y, this.house_x+(this.house_w/2),this.house_y-(this.house_h/2));
if( this.Door_Set == 1){
this.door.display();
}
if( this.Window_Set == 1){
this.window_left.display();
this.window_right.display();
}
}
void move_left(){
this.house_x += 1;
if(this.house_x > width+150){this.house_x = -150;}
if( this.Door_Set == 1){
this.door.move_left();
}
if( this.Window_Set == 1){
this.window_left.move_left();
this.window_right.move_left();
}
}
}
class Door{
int door_x;
int door_y;
int door_w;
int door_h;
Door(int door_x, int door_y, int door_w, int door_h){
this.door_x = door_x;
this.door_y = door_y;
this.door_w = door_w;
this.door_h = door_h;
}
Door(){
this.door_x = 0;
this.door_y = 0;
this.door_w = 0;
this.door_h = 0;
}
void display(){
rect(this.door_x, this.door_y, this.door_w, this.door_h);
}
void move_left(){
this.door_x +=1;
if(this.door_x > width+150){ this.door_x = -150;}
}
}
class Window{
int window_x;
int window_y;
int window_w;
int window_h;
Window(int window_x, int window_y, int window_w, int window_h){
this.window_x = window_x;
this.window_y = window_y;
this.window_w = window_w;
this.window_h = window_h;
}
Window(){
this.window_x = 0;
this.window_y = 0;
this.window_w = 0;
this.window_h = 0;
}
void display(){
rect(this.window_x, this.window_y, this.window_w, this.window_h);
}
void move_left(){
this.window_x +=1;
if(this.window_x > width+150){ this.window_x = -150;}
}
}
House h;
Door d;
Window window_left;
Window window_right;
Window no_window = new Window(0,0,0,0);
House k;
void setup(){
size(300, 300);
h = new House(100,100,100,50);
k = new House(100,200,100,50);
d = new Door(130,125,40,25);
window_left = new Window(110, 110, 10, 10);
window_right = new Window(180, 110, 10, 10);
h.drawDoor(d);
h.drawWindow(window_left, window_right);
//h.drawWindow(window_left, no_window);
}
void draw(){
background(255);
h.display();
k.display();
k.move_left();
h.move_left();
}
Monday, 20 October 2014
Lab 5 Array 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);
}
}
int B_num = 6;
Balloon b[] = new Balloon[B_num];
void setup(){
size(500, 500);
for( int i = 0; i < B_num; i++){
b[i] = new Balloon(63+(i*63), height, 50);
}
}
void draw(){
background(255);
for( int i = 0; i < B_num; i++){
b[i].fill_c();
b[i].display();
b[i].move_up();
b[i].move_right();
}
}
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);
}
}
int B_num = 6;
Balloon b[] = new Balloon[B_num];
void setup(){
size(500, 500);
for( int i = 0; i < B_num; i++){
b[i] = new Balloon(63+(i*63), height, 50);
}
}
void draw(){
background(255);
for( int i = 0; i < B_num; i++){
b[i].fill_c();
b[i].display();
b[i].move_up();
b[i].move_right();
}
}
Wednesday, 15 October 2014
Lab 4
int Table = 8;
int Rect_w_h = Table*10;
int size = Table*Rect_w_h;
int[][] T = new int[Table][Table];// row -- col /
void setup(){
size(size, size);
for(int i = 0; i < Table; i++){
for(int j = 0; j < Table; j++){
if(i%2 == 0){ if( j%2 == 0){ T[i][j] = 0; } else{ T[i][j] = 255; } }
else{ if( j%2 == 0){ T[i][j] = 255; } else{ T[i][j] = 0; } }
}
}
for(int i = 0; i < Table; i++){
for(int j = 0; j < Table; j++){
println("T "+i+" "+j+" "+T[i][j]);
}
}
}
void draw(){
for(int x = 0; x < size; x += Rect_w_h){
for(int y = 0; y < size; y += Rect_w_h){
int Fill_index1 = x/Rect_w_h;
int Fill_index2 = y/Rect_w_h;
fill(T[Fill_index1][Fill_index2]);
rect(x, y, size, size);
}
}
}
int Rect_w_h = Table*10;
int size = Table*Rect_w_h;
int[][] T = new int[Table][Table];// row -- col /
void setup(){
size(size, size);
for(int i = 0; i < Table; i++){
for(int j = 0; j < Table; j++){
if(i%2 == 0){ if( j%2 == 0){ T[i][j] = 0; } else{ T[i][j] = 255; } }
else{ if( j%2 == 0){ T[i][j] = 255; } else{ T[i][j] = 0; } }
}
}
for(int i = 0; i < Table; i++){
for(int j = 0; j < Table; j++){
println("T "+i+" "+j+" "+T[i][j]);
}
}
}
void draw(){
for(int x = 0; x < size; x += Rect_w_h){
for(int y = 0; y < size; y += Rect_w_h){
int Fill_index1 = x/Rect_w_h;
int Fill_index2 = y/Rect_w_h;
fill(T[Fill_index1][Fill_index2]);
rect(x, y, size, size);
}
}
}
Thursday, 9 October 2014
Bug Report from Assignment 1
1. ตั้งค่าการวนลูปผิด( < , > )ทำให้โปรเเกรมข้ามการวนลูปหรือทำซํ้าตลอด
- เปลี่ยน เคื่องหมาย (<,>) ให้ถูกต้อง
2. พิมพ์คำสั่งผิดทำให้โปรเเกรมไม่ทำงาน
-เช็คใน reference เพื่อดูคำสั่งที่ถูกต้อง
3. กำหนดชนิดของตัวเเปรไม่ถูกต้องทำให้ค่าที่ออกมาไม่เป็นที่ต้องการ
- เเก้ไขจาก Int เป็น float เพื่อให้
4.ไม่ได้ใส noFill(); ท้ายฟังกชันทำให้สีที่ใส่ต่อไป ผิดพลาด
-ใส่noFill ท้ายฟังกชัน
Thursday, 25 September 2014
Lab 3 cont 2
float[] R = new float[5];
void setup(){
rnd();
}
void rnd(){
for(int i = 0; i < R.length; i++){
R[i] = random(-10 , 10);
println("Random array "+i+" = "+R[i]); }
}
void setup(){
rnd();
}
void rnd(){
for(int i = 0; i < R.length; i++){
R[i] = random(-10 , 10);
println("Random array "+i+" = "+R[i]); }
}
Tuesday, 23 September 2014
Lab 3 cont 3
int al = 10;
int[] R = new int[al];
int max = 5;
int j,k;
void setup(){
rnd(2);
}
void rnd(int d){
for(int i = 0; i < R.length ; i++){
R[i] = round(random(0 , max));
if(R[i] != d){
j = 0;
k = 0;
for(j = i;j > 0;j--){
if(R[j-1] == R[i]){
k++;
}
}
if(k > 0){
i--;
}
}
}
for(int i = 0; i < R.length ; i++){
println("Random array "+i+" = "+R[i]);
}
}
int[] R = new int[al];
int max = 5;
int j,k;
void setup(){
rnd(2);
}
void rnd(int d){
for(int i = 0; i < R.length ; i++){
R[i] = round(random(0 , max));
if(R[i] != d){
j = 0;
k = 0;
for(j = i;j > 0;j--){
if(R[j-1] == R[i]){
k++;
}
}
if(k > 0){
i--;
}
}
}
for(int i = 0; i < R.length ; i++){
println("Random array "+i+" = "+R[i]);
}
}
Lab 3 cont
int K[] = { 4, 8, 5};
void setup(){
check(5);
check(4);
check(9);
}
void check(int j){
int c = 0;
for(int i = 0; i < K.length; i++){
if( j == K[i]){println(j+" has index = "+i+" in K"); c++;} }
for(int i = 0; i < K.length; i++){
if( j != K[i] && c == 0){println(j+" is not in K"); c++;} }
}
void setup(){
check(5);
check(4);
check(9);
}
void check(int j){
int c = 0;
for(int i = 0; i < K.length; i++){
if( j == K[i]){println(j+" has index = "+i+" in K"); c++;} }
for(int i = 0; i < K.length; i++){
if( j != K[i] && c == 0){println(j+" is not in K"); c++;} }
}
Monday, 22 September 2014
Wednesday, 17 September 2014
lab 3 balloon
int []ball = new int[4];
void setup() {
size(800, 600);
for (int i = 0; i < ball.length; i++) {
ball[i] = 4+i*4;
}
frameRate(30);
}
float y = 665;
void draw() {
background(0, 180, 200);
draw_balloon(100);
draw_balloon(110);
}
int k = 0;
int r = 0;
void draw_balloon(int One) {
for(int i = 1 ; i < 8;i++){
stroke(0);
line(i*One, y+(i*20), i*One, y+130+(i*20));
noStroke();
fill(r+(i*50), r+(i*40), r+(i*30));
ellipse(i*One, y+(i*20), (665/10)-y/10, 110);
}
y = y - ball[k];
if (y < -130) { y = height+260; r += 10; k = round(random(0,3)); }
}
void mousePressed(){
y = 665;
r = 0;
}
void setup() {
size(800, 600);
for (int i = 0; i < ball.length; i++) {
ball[i] = 4+i*4;
}
frameRate(30);
}
float y = 665;
void draw() {
background(0, 180, 200);
draw_balloon(100);
draw_balloon(110);
}
int k = 0;
int r = 0;
void draw_balloon(int One) {
for(int i = 1 ; i < 8;i++){
stroke(0);
line(i*One, y+(i*20), i*One, y+130+(i*20));
noStroke();
fill(r+(i*50), r+(i*40), r+(i*30));
ellipse(i*One, y+(i*20), (665/10)-y/10, 110);
}
y = y - ball[k];
if (y < -130) { y = height+260; r += 10; k = round(random(0,3)); }
}
void mousePressed(){
y = 665;
r = 0;
}
Sunday, 14 September 2014
Quadrant lab 3
void setup(){
size(300, 300);
background(0);
}
void draw(){
draw_line();
}
void draw_line(){
background(0);
stroke(255);
line(150, 0, 150, 300);
line(0, 150, 300, 150);
if((mouseX > 150) && (mouseY > 150))text("Quadrant 4", mouseX, mouseY);
if((mouseX > 150) && (mouseY < 150)) {text("Quadrant 1", mouseX, mouseY);}
if((mouseX == 150) && (mouseY == 150)) {text("Origin", mouseX, mouseY);}
if((mouseX < 150) && (mouseY < 150)) {text("Quadrant 2", mouseX, mouseY);}
if((mouseX < 150) && (mouseY > 150)) {text("Quadrant 3", mouseX, mouseY);}
}
size(300, 300);
background(0);
}
void draw(){
draw_line();
}
void draw_line(){
background(0);
stroke(255);
line(150, 0, 150, 300);
line(0, 150, 300, 150);
if((mouseX > 150) && (mouseY > 150))text("Quadrant 4", mouseX, mouseY);
if((mouseX > 150) && (mouseY < 150)) {text("Quadrant 1", mouseX, mouseY);}
if((mouseX == 150) && (mouseY == 150)) {text("Origin", mouseX, mouseY);}
if((mouseX < 150) && (mouseY < 150)) {text("Quadrant 2", mouseX, mouseY);}
if((mouseX < 150) && (mouseY > 150)) {text("Quadrant 3", mouseX, mouseY);}
}
Wednesday, 10 September 2014
Tax lab 3
double money = 35000,tax;
void setup() {
size(200, 200);
background(255);
if (money <= 15000) { tax = money * 10/100;}
else if(15000 < money && money <= 25000) {tax = money * 20/100;}
else if(25000 < money && money <= 35000) {tax = money * 30/100;}
else if(35000 < money) { tax = money * 40/100;}
println("Your money "+salary);
println("Your tax is = "+tax);
}
void setup() {
size(200, 200);
background(255);
if (money <= 15000) { tax = money * 10/100;}
else if(15000 < money && money <= 25000) {tax = money * 20/100;}
else if(25000 < money && money <= 35000) {tax = money * 30/100;}
else if(35000 < money) { tax = money * 40/100;}
println("Your money "+salary);
println("Your tax is = "+tax);
}
Tuesday, 9 September 2014
Grade lab 3
void setup() {
size(200, 200);
int score = 65;
char Grade;
if (score>=80) {Grade = 'A'; }
else if ((score<80)&&(score>=70)) {Grade = 'B'; }
else if ((score<70)&&(score>=60)) {Grade = 'C'; }
else if ((score<60)&&(score>=50)) {Grade = 'D';} else Grade = 'F';
}
println("You got Grade "+Grade);
fill(0);
text("You got Grade "+Grade, 50, 100);
}
size(200, 200);
int score = 65;
char Grade;
if (score>=80) {Grade = 'A'; }
else if ((score<80)&&(score>=70)) {Grade = 'B'; }
else if ((score<70)&&(score>=60)) {Grade = 'C'; }
else if ((score<60)&&(score>=50)) {Grade = 'D';} else Grade = 'F';
}
println("You got Grade "+Grade);
fill(0);
text("You got Grade "+Grade, 50, 100);
}
Tuesday, 2 September 2014
Animation Spoon and Fork lab 2
void setup(){
size(200, 200);
frameRate(50);
}
float posx = 0;
float c = 0;
void draw(){
if(c == 0){draw_fab(); posx = posx + 1;if(posx >20){c = 1;}}
if(c == 1){draw_fab(); posx = posx - 1;if(posx < -10){c = 0;}}
}
void draw_fab(){
background(200);
fill(255);
stroke(255);
quad(100, 25, 25, 100, 100, 175, 175, 100);
stroke(180);
fill(180);
rect(posx+45, 70, 10, 70);
rect(145-posx, 70, 10, 70);
quad(135-posx, 55, 165-posx, 55, 155-posx, 72, 145-posx, 72);
ellipse(posx+50, 50, 30, 45);
rect(135-posx, 30, 30, 25);
stroke(190);
fill(190);
ellipse(posx+50, 50, 26, 36);
rect(posx+47, 72, 6, 66);
rect(147-posx, 72, 6, 66);
quad(138-posx, 55, 162-posx, 55, 153-posx, 72, 147-posx, 72);
rect(138-posx, 32, 3, 25);
rect(145-posx, 32, 3, 25);
rect(152-posx, 32, 3, 25);
rect(159-posx, 32, 3, 25);
}
size(200, 200);
frameRate(50);
}
float posx = 0;
float c = 0;
void draw(){
if(c == 0){draw_fab(); posx = posx + 1;if(posx >20){c = 1;}}
if(c == 1){draw_fab(); posx = posx - 1;if(posx < -10){c = 0;}}
}
void draw_fab(){
background(200);
fill(255);
stroke(255);
quad(100, 25, 25, 100, 100, 175, 175, 100);
stroke(180);
fill(180);
rect(posx+45, 70, 10, 70);
rect(145-posx, 70, 10, 70);
quad(135-posx, 55, 165-posx, 55, 155-posx, 72, 145-posx, 72);
ellipse(posx+50, 50, 30, 45);
rect(135-posx, 30, 30, 25);
stroke(190);
fill(190);
ellipse(posx+50, 50, 26, 36);
rect(posx+47, 72, 6, 66);
rect(147-posx, 72, 6, 66);
quad(138-posx, 55, 162-posx, 55, 153-posx, 72, 147-posx, 72);
rect(138-posx, 32, 3, 25);
rect(145-posx, 32, 3, 25);
rect(152-posx, 32, 3, 25);
rect(159-posx, 32, 3, 25);
}
Animation Football Field lab 2
void setup(){
size(500, 300);
frameRate(30);
}
float g = 180;
float c = 0;
void draw(){
if(c == 0){draw_fbf(); g = g - 0.5;if(g < 100){c = 1;}}
if(c == 1){draw_fbf(); g = g + 0.5;if(g > 180){c = 0;}}
}
void draw_fbf(){
background(70, g, 70);
stroke(255);
strokeWeight(10);
line(0, 0, 500, 0);
line(0, 0, 0, 300);
line(500, 300, 500, 0);
line(0, 300, 500, 300);
line(250, 0, 250, 300);
noFill();
ellipse(250, 150, 100, 100);
line(500, 100, 430, 100);
line(500, 200, 430, 200);
line(430, 200, 430, 100);
line(0, 100, 70, 100);
line(0, 200, 70, 200);
line(70, 200, 70, 100);
arc(0, 0, 60, 60, 0, PI/2);
arc(500, 300, 60, 60, PI, TWO_PI-PI/2);
arc(500, 0, 60, 60, PI/2, PI);
arc(0, 300, 60, 60, TWO_PI-PI/2, TWO_PI);
}
size(500, 300);
frameRate(30);
}
float g = 180;
float c = 0;
void draw(){
if(c == 0){draw_fbf(); g = g - 0.5;if(g < 100){c = 1;}}
if(c == 1){draw_fbf(); g = g + 0.5;if(g > 180){c = 0;}}
}
void draw_fbf(){
background(70, g, 70);
stroke(255);
strokeWeight(10);
line(0, 0, 500, 0);
line(0, 0, 0, 300);
line(500, 300, 500, 0);
line(0, 300, 500, 300);
line(250, 0, 250, 300);
noFill();
ellipse(250, 150, 100, 100);
line(500, 100, 430, 100);
line(500, 200, 430, 200);
line(430, 200, 430, 100);
line(0, 100, 70, 100);
line(0, 200, 70, 200);
line(70, 200, 70, 100);
arc(0, 0, 60, 60, 0, PI/2);
arc(500, 300, 60, 60, PI, TWO_PI-PI/2);
arc(500, 0, 60, 60, PI/2, PI);
arc(0, 300, 60, 60, TWO_PI-PI/2, TWO_PI);
}
Animation Star lab 2
void setup() {
size(300, 300);
background(255, 255, 11);
frameRate(45);
}
float r = 0;
void draw(){
rotate(r);
draw_star();
r = r + 0.1;
}
void draw_star(){
background(255, 255, 11);
noStroke();
fill(0, 200, 200);
quad(150, 0, 50, 300, 150, 200, 250, 300);
triangle(0, 100, 300, 100, 150, 200);
rotate(PI/18);
fill(200, 10, 10);
quad(150, 0, 50, 300, 150, 200, 250, 300);
triangle(0, 100, 300, 100, 150, 200);
rotate(PI/9);
fill(10, 200, 10);
quad(150, 0, 50, 300, 150, 200, 250, 300);
triangle(0, 100, 300, 100, 150, 200);
rotate(PI/8);
fill(10, 10, 200);
quad(150, 0, 50, 300, 150, 200, 250, 300);
triangle(0, 100, 300, 100, 150, 200);
}
size(300, 300);
background(255, 255, 11);
frameRate(45);
}
float r = 0;
void draw(){
rotate(r);
draw_star();
r = r + 0.1;
}
void draw_star(){
background(255, 255, 11);
noStroke();
fill(0, 200, 200);
quad(150, 0, 50, 300, 150, 200, 250, 300);
triangle(0, 100, 300, 100, 150, 200);
rotate(PI/18);
fill(200, 10, 10);
quad(150, 0, 50, 300, 150, 200, 250, 300);
triangle(0, 100, 300, 100, 150, 200);
rotate(PI/9);
fill(10, 200, 10);
quad(150, 0, 50, 300, 150, 200, 250, 300);
triangle(0, 100, 300, 100, 150, 200);
rotate(PI/8);
fill(10, 10, 200);
quad(150, 0, 50, 300, 150, 200, 250, 300);
triangle(0, 100, 300, 100, 150, 200);
}
Bicycle lab 2
void setup(){
size(400, 300);
background(255);
frameRate(5);
}
float y = 0;
void draw(){
float rx = random(-100, 300);
float ry = random(-200, 100);
float rr = random(0, 255);
float rg = random(0, 255);
float rb = random(0, 255);
draw_b(30, rx, ry, rr, rg, rb);
y = y + 1;
if(y == 15){y = 0; background(255);}
}
void draw_b(float wheel,float posx, float posy, float rr, float rg, float rb){
stroke(rr, rg, rb);
strokeWeight(4);
noFill();
ellipse(posx+50, posy+200, wheel, wheel);
ellipse(posx+110, posy+200, wheel, wheel);
line(posx+50, posy+200, posx+65, posy+160);
line(posx+65, posy+160, posx+75, posy+160);
line(posx+62, posy+173, posx+100, posy+173);
line(posx+110, posy+200, posx+100, posy+173);
line(posx+62, posy+173, posx+80, posy+200);
line(posx+80, posy+200, posx+110, posy+200);
line(posx+80, posy+200, posx+105, posy+165);
line(posx+95, posy+165, posx+108, posy+165);
}
size(400, 300);
background(255);
frameRate(5);
}
float y = 0;
void draw(){
float rx = random(-100, 300);
float ry = random(-200, 100);
float rr = random(0, 255);
float rg = random(0, 255);
float rb = random(0, 255);
draw_b(30, rx, ry, rr, rg, rb);
y = y + 1;
if(y == 15){y = 0; background(255);}
}
void draw_b(float wheel,float posx, float posy, float rr, float rg, float rb){
stroke(rr, rg, rb);
strokeWeight(4);
noFill();
ellipse(posx+50, posy+200, wheel, wheel);
ellipse(posx+110, posy+200, wheel, wheel);
line(posx+50, posy+200, posx+65, posy+160);
line(posx+65, posy+160, posx+75, posy+160);
line(posx+62, posy+173, posx+100, posy+173);
line(posx+110, posy+200, posx+100, posy+173);
line(posx+62, posy+173, posx+80, posy+200);
line(posx+80, posy+200, posx+110, posy+200);
line(posx+80, posy+200, posx+105, posy+165);
line(posx+95, posy+165, posx+108, posy+165);
}
Subscribe to:
Posts (Atom)