30
Processing ArrayList & Class 07 矩陣列 以及 克拉斯

Processing=007=arraylist

Embed Size (px)

DESCRIPTION

A_Little_Bit_Processing_Tutorial

Citation preview

Page 1: Processing=007=arraylist

Processing

ArrayList & Class

07矩陣列 以及 克拉斯

Page 2: Processing=007=arraylist

Little Warm-up

一點點暖身

Page 4: Processing=007=arraylist

http://computationalmatter.com/Magneto

Page 5: Processing=007=arraylist

How toDraw it

Page 6: Processing=007=arraylist
Page 7: Processing=007=arraylist

import peasy.test.*;

import peasy.org.apache.commons.math.*;

import peasy.*;

import peasy.org.apache.commons.math.geometry.*;

PeasyCam cam;

void setup(){

size(500,500,P3D);

cam = new PeasyCam(this,0,0,0,500);

}

void draw(){

background(0);

for(int i =0; i< 125; i+=25){

for(int j=0; j<125; j+=25){

for(int k=0; k<125; k+=25){

pushMatrix();

translate(i,j,k);

if((i+j+k)%3==1){

box(20);

}

else{

sphereDetail(50);

sphere(20);

} }

}

}

}

Page 8: Processing=007=arraylist
Page 9: Processing=007=arraylist

import peasy.test.*;

import peasy.org.apache.commons.math.*;

import peasy.*;

import peasy.org.apache.commons.math.geometry.*;

PeasyCam cam;

void setup(){

size(500,500,P3D);

cam = new PeasyCam(this,0,0,0,500);

}

void draw(){

background(0);

noStroke();

//stroke(255);

for(int i =0; i< 125; i+=25){

for(int j=0; j<125; j+=25){

for(int k=0; k<125; k+=25){

pushMatrix();

fill(i,j,k);

translate(i,j,k);

if((i+j+k)%3==1){

box(20);

}

else{

sphereDetail(10);

sphere(20);

}

popMatrix();

}

}

}

}

Page 10: Processing=007=arraylist

Add the Slider

Page 11: Processing=007=arraylist
Page 12: Processing=007=arraylist

import peasy.*;

import controlP5.*;

float sphereSize = 20;

float boxSize = 20;

PeasyCam cam;

ControlP5 controlP5;

PMatrix3D currCameraMatrix;

PGraphics3D g3;

void setup() {

size(800,600,P3D);

g3 = (PGraphics3D)g;

cam = new PeasyCam(this, 600);

controlP5 = new ControlP5(this);

controlP5.addSlider("sphereSize",20,100,10,10,200,20);

controlP5.addSlider("boxSize",20,100,10,40,200,20);

controlP5.setAutoDraw(false);

}

void draw() {

if (controlP5.window(this).isMouseOver()) {

cam.setActive(false);

} else {

cam.setActive(true);

}

background(0);

noStroke();

for(int i =0; i< 125; i+=25){

for(int j=0; j<125; j+=25){

for(int k=0; k<125; k+=25){

pushMatrix();

fill(i,j,k);

translate(i,j,k);

if((i+j+k)%3==1){

box(boxSize);

}

else{

sphereDetail(10);

sphere(sphereSize);

}

popMatrix();

}

}

}

gui();

}

void gui() {

currCameraMatrix = new PMatrix3D(g3.camera);

camera();

controlP5.draw();

g3.camera = currCameraMatrix;

}

Put your code here

Page 13: Processing=007=arraylist

Array矩陣

Page 14: Processing=007=arraylist

Array

1 2

34

5

6

0

Like a bag to put things in.But with certain Amount

像個袋子可是只能裝特定數量

Page 15: Processing=007=arraylist

Declare Array

int[]x = { 200,100,300,500 };

this is an array called “x” and there are all integers inside of it.

Function bagname

Things that side the bagOpen bag Close bag

宣告陣列

這是一個陣列X裡面放的是整數

Page 16: Processing=007=arraylist

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]=300y1[0]=300, y1[1]=400, x1[2]=200

Page 17: Processing=007=arraylist
Page 18: Processing=007=arraylist

Conceptually talking about

ArrayList概念上說明矩陣列

Page 19: Processing=007=arraylist

ArrayList

Page 20: Processing=007=arraylist

ArrayList

Putting more

Balls in the bag

And still, we can

pick up the ball

可以不斷在袋子裡加東西

仍舊可以取出我們要的那一顆

Page 21: Processing=007=arraylist

Conceptually talking about

CLASS概念上說明克拉斯

Page 22: Processing=007=arraylist

DOG

Class Structure Data Function

Color

OBJECT

Legs (Long or Short)

ears (Long or Short)

Length (Long or Short)

Weight (heavy, light)

RUN();

BARK();

JUMP();

white

blacky

spot

Page 23: Processing=007=arraylist

class dog{//declare global variables

int legs,color,size;

//input valuedog( 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;}

}

openname

close

Page 24: Processing=007=arraylist

ArrayList circleList;

void setup(){

size(500,500);

smooth();

circleList = new ArrayList();

}

class pulse{

PVector loc;

float randomR;

pulse(PVector _loc, float _randomR){

loc = _loc;

randomR = _randomR;

}

}

Basic Setup

基本設定

Page 25: Processing=007=arraylist

ArrayList circleList;

void setup(){

size(500,500);

smooth();

circleList = new ArrayList();

}

void draw(){

PVector location = new PVector(random(0,width), random(0,width), 0);

pulse heart;

heart = new pulse( location, random(20,200));

}

class pulse{

PVector loc;

float randomR;

pulse(PVector _loc, float _randomR){

loc = _loc;

randomR = _randomR;

}

}

Making Object

產生物件

Page 26: Processing=007=arraylist

ArrayList circleList;

void setup(){

size(500,500);

smooth();

circleList = new ArrayList();

}

void draw(){

PVector location = new PVector(random(0,width), random(0,width), 0);

pulse heart;

heart = new pulse( location, random(20,200));

heart.display();

}

class pulse{

PVector loc;

float randomR;

pulse(PVector _loc, float _randomR){

loc = _loc;

randomR = _randomR;

}

void display(){

fill(random(0,255),random(0,255),random(0,255));

ellipse(loc.x, loc.y, randomR, randomR);

}

}

AddingFunction

增加功能

Page 27: Processing=007=arraylist
Page 28: Processing=007=arraylist

ArrayList circleList;

void setup(){

size(500,500);

smooth();

circleList = new ArrayList();

}

void draw(){

}

void mousePressed(){

PVector location = new PVector(random(0,width), random(0,width), 0);

pulse heart;

heart = new pulse( location, random(20,200));

circleList.add(heart);

}

class pulse{

PVector loc;

float randomR;

pulse(PVector _loc, float _randomR){

loc = _loc;

randomR = _randomR;

}

void display(){

fill(random(0,255),random(0,255),random(0,255));

ellipse(loc.x, loc.y, randomR, randomR);

}

}

Control by Mouse

用滑鼠控制

Page 29: Processing=007=arraylist

ArrayList circleList;

void setup(){

size(500,500);

smooth();

circleList = new ArrayList();

}

void draw(){

background(0);

for(int i=0; i<circleList.size(); i++){

pulse newHeart = (pulse)circleList.get(i);

newHeart.beat();

}

}

void mousePressed(){

PVector location = new PVector(mouseX, mouseY, 0);

pulse heart;

heart = new pulse( location, random(20,200));

circleList.add(heart);

}

Make the Pulse

class pulse{

PVector loc;

float randomR;

float t =0;

pulse(PVector _loc, float _randomR){

loc = _loc;

randomR = _randomR;

}

void display(){

ellipse(loc.x, loc.y, randomR, randomR);

}

void beat(){

ellipse(loc.x, loc.y, sin(t)*randomR, sin(t)*randomR);

t =t +1;

if(t>2*PI){t=0;}

}

}

製造心跳

Page 30: Processing=007=arraylist