map ( 대상, 최소, 최대, mapping 최소, mapping 최대 )
map의 Document
float angle = 0.0f;
void setup(){
size(400,400);
}
void draw(){
float sinval = sin(angle);
float gray = map(sinval, -1 , 1 , 0 , 255 ) ;
background(gray);
angle += 0.1 ;
}
sinval 값은 sin 함수의 결과값이므로 -1 에서 1 까지의 값밖에 안나오지만 이를 0 에서 255까지 맵핑 한 것이다.
이 코드를 실행하면 화면이 하얀색에서 검은색까지 화면이 깜박깜박하게 된다.
이 코드를 조금 바꿔보면
float angle = 0.0f;
void setup(){
size(400,400);
}
void draw(){
float sinval = sin(angle);
float r = map(sinval , -1 , 1 , 183 , 255 ) ;
float g = map(sinval , -1 , 1 , 255 , 255 ) ;
float b = map(sinval , -1 , 1 , 191 , 255 ) ;
background(r,g,b);
angle += 0.1 ;
}
검은색과 하얀색만이 아닌 다른 색으로 깜박거리게 할 수도 있다.
'Programing > Processing' 카테고리의 다른 글
| Processing Growing Tree (0) | 2017.06.05 |
|---|---|
| 프로세싱 부엉이 그리기 ! (1) | 2017.05.15 |
| Processing 폰트 불러오기와 글자의 회전 (0) | 2017.05.08 |
| processing 이동 회전 확장( 크기 ) 에 대하여 (0) | 2017.05.08 |
| Processing Rotate( 회전 ) 에 관한 고찰 ( rotate 사용법 ) (0) | 2017.05.01 |
댓글 로드 중…