Processing
07 ArrayList & Class
Array
0
1
2 5 3 4
6 Array
Declare Array
Function bag name Open bag
Things that side the bag
Close bag
int[]x = { 200,100,300,500 }; this is an array called “x� and there are all integers inside of it.
void setup(){ size(500,500); smooth(); } void draw(){ background(0); int [] x1 = {200,400,300}; int [] y1 = {300,400,200}; ellipse(x1[0], y1[0], 200, 200); ellipse(x1[1], y1[1], 100, 100); ellipse(x1[2], y1[2], 50, 50); }
x1[0]=200, x1[1]=400, x1[2]=300 y1[0]=300, y1[1]=400, x1[2]=200
Conceptually talking about
ArrayList
ArrayList
Putting more Balls in the bag
And still, we can pick up the ball
ArrayList
Conceptually talking about
CLASS
Class
Structure Data
Function
OBJECT white
Color Legs (Long or Short)
DOG
RUN();
ears (Long or Short)
BARK();
Length (Long or Short)
JUMP();
blacky
Weight (heavy, light) spot
name
class dog{
open
//declare global variables int legs,color,size; //input value dog( int _legs, int _color, int _size){ legs = _legs; color = _color; size = _size; }
//function of the class(what this class can do) void run(){ run as a dog; }
}
close
Basic Setup
Set up the “ArrayList”, first
ArrayList pointList; void setup(){ size(500,500); smooth(); pointList = new ArrayList(); }
Set up the “Class” class Pts{ float x; float y; float z; float r;
The parameters you are going to use
Pts(float _x, float _y, float _z, float _r){ x = _x; y = _y; z = _z; r = _r; }
Basic Elements
void display(){ fill(random(255), random(255), random(255)) ellipse(x, y, r, r); }
Functions
}
Basic Setup
ArrayList pointList;
class Pts{
void setup(){ size(500,500); smooth(); pointList = new ArrayList(); }
float x; float y; float z; float r;
void draw(){ float x = random(width); float y = random(height); float z = 0; float r = random(200);
These refer to the class
Pts(float _x, float _y, float _z, float _r){ x = _x; y = _y; z = _z; r = _r; } void display(){ fill(random(255), random(255), random(255)); ellipse(x, y, r, r); }
Pts nPt = new Pts(x,y,z,r); } Make an Object
Making Object
}
NOTHING HAPPENS ???!!!
ArrayList pointList;
class Pts{
void setup(){ size(500,500); smooth(); pointList = new ArrayList(); }
float x; float y; float z; float r; Pts(float _x, float _y, float _z, float _r){ x = _x; y = _y; z = _z; r = _r; }
void draw(){ float x = random(width); float y = random(height); float z = 0; float r = random(200);
void display(){ fill(random(255), random(255), random(255)); ellipse(x, y, r, r); }
Pts nPt = new Pts(x,y,z,r); Pts.display(); } Don’t forget to “DISPLAY”
Making Object
}
ArrayList pointList;
class Pts{
void setup(){ size(500,500); smooth(); pointList = new ArrayList(); }
float x; float y; float z; float r;
Pts(float _x, float _y, float _z, float _r){ x = _x; y = _y; z = _z; r = _r; }
void draw(){
} void mousePressed(){ Pts n = new Pts (mouseX, mouseY, 0, random(20,200)); n.display pointList.add(n); }
There is nothing happen again, because we didn’t display them LET’s DISPLAY them in ”draw”
Use Mouse to put them into ArrayList
void display(){ fill(random(255), random(255), random(255)); ellipse(x, y, r, r); } }
ArrayList pointList;
class Pts{
void setup(){ size(500,500); smooth(); pointList = new ArrayList(); }
float x; float y; float z; float r; Pts(float _x, float _y, float _z, float _r){ x = _x; y = _y; z = _z; r = _r; }
void draw(){ stroke(255); for(int i=1; i<pointList.size();i++){ Pts PtO = (Pts)pointList.get(i-1); Pts PtN = (Pts)pointList.get(i); line(PtO.x,PtO.y,PtN.x,PtN.y); } }
Draw Line between void mousePressed(){ Pts n = new Pts (mouseX, mouseY, 0, random(20,200)); n.display(); pointList.add(n); }
void display(){ fill(255); ellipse(x, y, r, r); } }