Processing=007=arraylist

Preview:

DESCRIPTION

A_Little_Bit_Processing_Tutorial

Citation preview

Processing

ArrayList & Class

07矩陣列 以及 克拉斯

Little Warm-up

一點點暖身

http://computationalmatter.com/Magneto

How toDraw it

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);

} }

}

}

}

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();

}

}

}

}

Add the Slider

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

Array矩陣

Array

1 2

34

5

6

0

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

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

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裡面放的是整數

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

Conceptually talking about

ArrayList概念上說明矩陣列

ArrayList

ArrayList

Putting more

Balls in the bag

And still, we can

pick up the ball

可以不斷在袋子裡加東西

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

Conceptually talking about

CLASS概念上說明克拉斯

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

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

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

基本設定

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

產生物件

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

增加功能

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

用滑鼠控制

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;}

}

}

製造心跳

Recommended