댓글 쓰기 권한이 없습니다. 로그인 하시겠습니까?
이재중 선생님께 질무운~
첨부파일 '1' |
---|
이재중 선생님, 잘 지내고 계시나요?
전 만리타국에서 영어로 프로세싱 수업 들으려니까 진짜 미춰버릴 것 같아요...
선생님께서 해주신 수업 너무 재밌게 잘 들었는데, 여기오니까 재미가 확 반감되네요.
정말 거의 반쯤 울면서 과제 하다가 도저히 모르겠어서 여기에 질문 드려요. ㅜㅜ
아래는 보로노이 다이어그램을 시각화 시킨 코드인데요, 점이 랜덤으로 찍히고 그걸 기준으로 선이 그려지게 되어 있어요.
저는 지금 그걸 csv 파일에 있는 데이터 1, 2열에 있는 수를 array로 불러와서 그 수치 대로 x,y 점이 찍히고 그걸 기준으로 보로노이 라인이 그려지게 하고 싶은데요. 어떤 부분을 고쳐야 제가 원하는 결과를 얻을 수 있을까요?
// MeshLibDemo.pde - Demo of Lee Byron's Mesh library for
// calculating and drawing Voronoi, Delaunay and Convex Hull
// diagrams.
// Uses a set of random points to calculate all
// three diagrams, with one point responding to the mouse
// position. Press space to reset points, press '1', '2' and
// '3' to toggle display of the different diagrams.
//
// The library is included in this sketch, see the "libraries"
// subfolder See http://leebyron.com/else/mesh/ for more
// information about the library.
//
// Marius Watz - http://workshop.evolutionzone.com/
import megamu.mesh.*;
Voronoi myVoronoi;
Delaunay myDelaunay;
Hull myHull;
float[][] points;
float[][] myEdges;
MPolygon myRegions[],myHullRegion;
int col[];
float startX,startY,endX,endY;
float[][] regionCoordinates;
boolean showVoronoi=true;
boolean showDelaunay=false;
boolean showHull=false;
void setup() {
size(500,250);
// initialize points and calculate diagrams
initMesh();
smooth();
}
void draw() {
background(200);
if(myRegions==null) return;
// draw Voronoi
if(showVoronoi) {
strokeWeight(1);
stroke(0);
for(int i=0; i<myRegions.length; i++) {
fill(col[i]); // use random color for each region
regionCoordinates = myRegions[i].getCoords();
myRegions[i].draw(this); // draw this shape
}
}
// draw Voronoi as lines
if(showDelaunay) {
strokeWeight(2);
stroke(255,0,0);
for(int i=0; i<myEdges.length; i++) {
startX = myEdges[i][0];
startY = myEdges[i][1];
endX = myEdges[i][2];
endY = myEdges[i][3];
line(startX, startY, endX, endY);
}
}
// draw Hull in semi-transparent yellow
if(showHull) {
strokeWeight(1);
stroke(0);
fill(255,255,0, 150);
myHullRegion.draw(this);
}
}
void initMesh() {
// is points array is null then initialize it
if(points==null) initPoints();
// save the current number of regions, so that
// we can check if it's the same after the Voronoi
// has been recalculated.
int oldlength=0;
if(myRegions!=null) oldlength=myRegions.length;
myVoronoi = new Voronoi( points );
myHull = new Hull( points );
myDelaunay = new Delaunay( points );
myRegions = myVoronoi.getRegions();
myHullRegion = myHull.getRegion();
myEdges = myDelaunay.getEdges();
// if the number of regions is different than
// before then recalculate the random colors
if(oldlength!=myRegions.length) {
col=new int[myRegions.length];
for(int i=0; i<myRegions.length; i++) {
float prob=random(100);
if(prob>60) col[i]=color(random(30,100));
else col[i]=color(random(200,255));
}
// col[0]=color(255,0,0);
}
}
void initPoints() {
points = new float[(int)random(5,30)][2];
for(int i=0; i<points.length; i++) {
points[i][0] = random(width); // first point, x
points[i][1] = random(height); // first point, y
}
}
-
-
?
보로노이 굉장히 흥미로운 부분이네요ㅎㅎ
좋은 정보 감사합니다~
그리고 죄송하지만 Voronoi 클래스부분 소스도 볼 수 있을까요? -
별도의 클래스는 없고 라이블러리 입니다.^^ 고마우신 분들이 만들어주셨죠..^^ 링크겁니다..
http://leebyron.com/else/mesh/
여기서 다운받아서 설치하시고 해보시면 될거예요~~ -
?
라이브러리 다운받아서 임포트했는데 안되네융 ㅠ
영어를 못해서리.. 오늘은 이 문제해결을 목표로 공부하겟습니다ㅎㅎ
-
음..압축 풀면 나오는 mesh 폴더 자체를 도큐멘트 > processing > libraries 에 넣어주시고 프로세싱 다시 시작하시면 됩니다.~~이미지 첨부합니다.~
Q&A
질문하는 공간입니다. 회원이면 누구나 질문/답변 할 수 있습니다.
Designed by sketchbooks.co.kr / sketchbook5 board skin
Sketchbook5, 스케치북5
Sketchbook5, 스케치북5
Sketchbook5, 스케치북5
Sketchbook5, 스케치북5
print 문으로 각 단계의 값을 출력해 보시면 이해가 될 겁니다.
글로 적는데는 한계가 있는것 같네요...^^
참고로 좌표가 지금 스케치 사이즈보다 크기 때문에.
스케치 크기를 size(600, 600)으로 조정해 주세요~~
화이팅!!!