Created
May 28, 2020 06:10
-
-
Save icq4ever/ee0358f4188ab2d0e543d35fda1be549 to your computer and use it in GitHub Desktop.
10print 실습 예제
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int x; | |
int y; | |
int size; | |
float posibility; | |
void setup() { | |
size(600, 600); | |
background(0); | |
reset(); | |
} | |
void draw() { | |
stroke(255); | |
strokeWeight(2); | |
// 확률에 따라 슬래시 혹은 역슬래시를 그리도록 한다. | |
// 확률은 변수화하여, 이미지로 저장한 이후 확률을 업데이트 하도록 한다 (reset() 참고) | |
if ( random(1) < posibility) { | |
line(x, y + size, x+size, y); // / 슬래시 | |
} else { | |
line(x, y, x+size, y+size); // \ 역슬래시 | |
} | |
x = x + size; | |
if ( x > width ) { // 기준점이 화면우측으로 벗어나면.. | |
x = 0; | |
y = y + size; | |
} | |
// 이렇게 계속해서 반복하다가 | |
// y의 값이 height보다 크면 | |
// 현재 캔버스를 이미지로 저장하고 | |
// 프로그램을 종료한다. | |
if ( y > height) { | |
String fileName; | |
fileName = "patterns/" + getTimeStamp() + "_pattern.png"; | |
save(fileName); | |
//exit(); // 프로세싱 프로그램을 종료한다. | |
reset(); | |
} | |
} | |
// 변수값들을 리셋 | |
void reset() { | |
x = 0; | |
y = 0; | |
size = 30; | |
posibility = random(0.2, 0.8); // 20% ~ 80% 확률로 슬래시, 역슬래시를 결정하도록 한다. | |
} | |
// 현재 날짜와 시간을 문자열로 리턴해주는 함수 | |
String getTimeStamp(){ | |
return year() + "-" + month() + "-" + day() + "_" + hour() + "-" + minute() + "-" + second(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment