티스토리 뷰

processing

NATURE OF CODE-0.INTRODUCTION

zedo 2016. 5. 7. 19:40
// 화면에서 노이즈 발생시 offset 값을 조정하여 질감의 조정
void setup() {
size(640,408);
background(255); //white
}
void draw(){
loadPixels();
float xoff=0.0;
for(int x = 0; x < width; x++) { float yoff=0.0; for(int y= 0; y < height; y++) { float bright = map(noise(xoff,yoff), 0,1, 0,255); //float bright = random(255); pixels[x+y*width]=color(bright); yoff += 0.01; } xoff += 0.01; } updatePixels(); } //———————————————— // 화면에서 노이즈 발생 테스트(random 함수와 noise 함수 사용) void setup() { size(640,408); background(255); //white } void draw(){ loadPixels(); for(int x = 0; x < width; x++) { for(int y= 0; y < height; y++) { //float bright = map(noise(x,y), 0,1, 0,255); float bright = random(255); pixels[x+y*width]=color(bright); } } updatePixels(); } //———————————————— // map 함수를 통하여 noise() 함수에 대한 실험 (뱀처럼 이동하는 모습 확인 가능) class Walker{ float x,y; float tx, ty; // time value Walker(){ tx = 0; ty = 10000; } void step() { x = map(noise(tx), 0, 1, 0, width); y = map(noise(ty), 0, 1, 0, height); tx += 0.01; ty += 0.01; } void display() { fill(124, 10); ellipse(x, y, 16, 16); } } Walker w; void setup() { size(640,408); w = new Walker(); background(255); //white } // infinite loop of draw() void draw() { // Run the walker object w.step(); w.display(); } //———————————————– // noise 함수에서 시간(t)의 변이를 작게(0.0001)로 하면 변이가 작지만 크게(0.1이상)하면 변이가 큼 void setup() { size(640,408); background(255); //white } float t = 3; //time value int x = 0; void draw(){ float n = noise(t); stroke(0); point(x++, n * height); t += 0.001; } //———————————————— // noise() 함수에 대한 실험 (뱀처럼 이동하는 모습 확인 가능) void setup() { size(640,408); background(255); //white } float t1 = 0; // time value for noise() function float t2 = 3; // time value for noise() function // infinite loop of draw() void draw() { // Run the walker object float x = noise(t1) * width; float y = noise(t2) * height; fill(124, 10); ellipse(x, y, 16, 16); t1 += 0.01; t2 += 0.01; } //————————————————— // 캔버스 임의의 위치에 원을 그리기 void setup() { size(640,408); background(255); //white } // infinite loop of draw() void draw() { // Run the walker object float x = random(0, width); float y = random(0, height); fill(124, 10); ellipse(x, y, 16, 16); } //——————————————————- // java 유틸리티의 난수 발생기를 통해 가우시안 분포를 표현하도록 함 import java.util.Random; Random generator; // Java Class void setup(){ size(640, 360); generator = new Random(); background(255); //white } void draw(){ float num = (float)generator.nextGaussian(); // generate mean 0, standard deviation 1 float sd = 60; float mean = width/2; float x = sd * num + mean; noStroke(); fill(120,10); ellipse(x, height/2, 16,16); } //————————————- // 앞의 Random Walker에서 오른쪽으로 가는 경향을 40%로 변경 class Walker { int x,y; Walker() { x = width/2; //width 640 y = height/2; //height 360 } void display() { stroke(0); //black point(x,y); } // Randomly move up, down, left, right, or stay in one place void step() { float num = random(1); if (num < 0.4) { x++; } else if (num < 0.6) { x–; } else if (num < 0.8) { y++; } else { y–; } // Constrains a value to not exceed a maximum and minimum value // constrain(amt, low, high) x = constrain(x,0,width-1); // width minimum 0, maximum 639 y = constrain(y,0,height-1);//height minimum 0, maximum 359 } } Walker w; void setup() { size(640,360); // Create a walker object w = new Walker(); background(255); //white } // infinite loop of draw() void draw() { // Run the walker object w.step(); w.display(); } //————————————- // 임의변수 발생시 한쪽에 더 많은 Event를 발생하도록 변경 float num = random(1); //generate random number 0~1 if (num < 0.6) { println(“A(60%)”); } else if (num < 0.7) { println(“B(10%)”); } else { println(“C(30%)”); } //————————————– // rectangel example void setup(){ size(640, 480); } void draw(){ background(255); //white //stroke(0); //black; fill(175); //grey rect(0, 200, 31, 200); // rect(x, y, width, height) } //————————————– // Uniform distribution int[] randomCounts; void setup(){ size(640, 480); randomCounts = new int[20]; } void draw(){ background(255); //white int index=int(random(randomCounts.length)); // generate 0~19 numbers randomCounts[index]++; // increase element of randomCounts //stroke(0); //black; fill(175); //grey int w = width / randomCounts.length; // 640/20 = 32 for(int x=0; x < randomCounts.length; x++) { rect(x * w, height – randomCounts[x], w-1, randomCounts[x]); // rect(x,y, width, height); // (0, 479, 31, 1) } }

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG more
«   2026/01   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함