2013-01-02 3 views
5

누구나 내 프로필 사진처럼 꽃을 임의로 생성하는 링크, 아이디어 또는 알고리즘을 제안 할 수 있습니까? 프로필 그림 꽃은 10 x 10 격자 밖에 없으며 알고리즘은 실제로 무작위가 아닙니다. 나는 또한 새로운 알고리즘이 약 500 x 500 이상의 그리드를 사용하거나 사용자가 그리드의 크기를 선택할 수있게하는 것을 선호한다.임의의 꽃을 생성하는 알고리즘에 대한 아이디어

[공장은 [] [] INT 공장 [10] [10]로 선언]

public void generateSimpleSky(){ 

    for(int w2=0;w2<10;w2++) 
     for(int w3=0;w3<10;w3++) 
      plant[w2][w3]=5; 

} 

public void generateSimpleSoil(){ 

    for(int q=0;q<10;q++) 
     plant[q][9]=1; 

} 

public void generateSimpleStem(){ 

    int ry=rand.nextInt(4); 
    plant[3+ry][8]=4; 
    xr=3+ry; 

    for(int u=7;u>1;u--){ 

     int yu=rand.nextInt(3); 
     plant[xr-1+yu][u]=4; 
     xr=xr-1+yu; 

    } 

} 

public void generateSimpleFlower(){ 

    plant[xr][2]=3; 

    for(int q2=1;q2<4;q2++) 
     if((2-q2)!=0) 
      plant[xr][q2]=2; 

    for(int q3=xr-1;q3<=xr+1;q3++) 
     if((xr-q3)!=0) 
      plant[q3][2]=2; 

} 
+2

* 진정한 무작위 * 란 무엇을 의미합니까? – jeremy

+4

두 번째 @Nile 님의 댓글입니다. 우선 무작위로 원하는 꽃에 대해 * 무엇을 * 분리 할 수 ​​있습니다. 색깔, 꽃잎 크기, 중핵 크기 또는 색깔, 줄기 크기, 등등. 그 꽃의 진실한 무작위 화는 진짜 지저분한 식물을 위해 만들 것입니다. – brainmurphy1

+0

내 프로필 사진에서 꽃을 생성하는 데 사용한 알고리즘이 줄기가 어떻게 ooked되었는지를 변경하는 것보다 알고리즘을 사용한다는 것을 의미합니다. 꽃은 여전히 ​​똑같아 보였다. 그래서 나는 그것을 "진정한 randam"으로 만들고 싶습니다. 즉, enteire procedure를 무작위로 만들고 싶습니다. – Hele

답변

4

그것은 그냥 한 번에 한 매개 변수를 생성 합리적으로 간단한 문제 같은데, 아마도 기반으로 이전 변수의 출력.

꽃의 나의 모델은 다음과 같습니다 : 그것은 단지 합리적인 수직 줄기, 완벽하게 둥근 중심, 줄기의 줄기가 줄기가있는 줄기, 꽃잎이 중심 주위에 완벽하게 분포되어 있습니다.

random()은 일부 선택된 경계 내에서 임의의 숫자이며, 경계는 각 변수마다 고유 할 수 있습니다. random(x1, x2, ..., xn)은 변수 x1, x2, ..., xn (stemWidth < stemHeight/2의 합리적인 가정에서와 같이)에 따라 일부 경계 내에서 난수를 생성합니다.

stemXPosition = width/2 
stemHeight = random() 
stemWidth = random(stemHeight) 
stemColour = randomColour() 
stemWidthVariationMax = random(stemWidth, stemHeight) 
stemWidthVariationPerPixel = random(stemWidth, stemHeight) 

stemWidthVariationMax/-PerPixel 완벽하게 직선이 아닌 줄기 생성하는 줄기 (당신이 복잡한 일을 수행하려는 경우를, 낮은 PerPixel은 부드러움입니다). 다음과 같이 다음을 사용하여 줄기를 생성 : 또한 사물을 단순화 호를 사용하여 한 번에 1 개 이상의 픽셀을 갈 수

pixelRelative[y-position][0] := left x-position at that y-position relative to the stem 
pixelRelative[y-position][1] := right x-position at that y-position relative to the stem 

pixelRelative[0][0] = randomInRange(-stemWidthVariationMax, stemWidthVariationMax) 
for each y > 0: 
    pixelRelative[y-1][0] = max(min(randomInRange(pixel[y] - stemWidthVariationPerPixel, 
             pixel[y] + stemWidthVariationPerPixel), 
          -stemWidthVariationMax), 
         stemWidthVariationMax) 
//pixelRelative[0][1] and pixelRelative[y-1][1] generated same as pixelRelative[y-1][i] 
for each y: 
    pixelAbsolute[y][0] = width/2 - stemWidth/2 + pixelRelative[y][0] 
    pixelAbsolute[y][1] = width/2 + stemWidth/2 + pixelRelative[y][1] 

.

그것은 꽃잎을 생성하기 너무 쉬운 일이 아니다 상위

centerRadius = random(stemHeight) 
petalCount = random() // probably >= 3 
petalSize = random(centerRadius, petalCount) 

, 당신은 원 주위에 호를 2*PI/petalCount의 스텝 크기 0 *의 PI 2에서 단계로 생성해야합니다. 좋은 그래픽 API 또는 적절한 수학이 필요합니다.

Here's 일부 오픈 소스는 멋지게 꽃의 정상을 생성합니다. 그들은 센터가 전혀 없다는 것을 유의하십시오. (또는 centerRadius = 0)

당신은 아마이에 전체 용지를 작성할 수

잎, (같은 this one)하지만 간단한 아이디어는 1/2 원을 생성하고 외부 라인을 확장하는 것 거기에서 원의 반지름 2 *를 만나 꽃에 평행선을 그리십시오.

당신은 잎 생성 알고리즘이 있으면 :

leafSize = random(stemHeight) // either all leaves are the same size or generate the size for each randomly 
leafStemLength = random(leafSize) // either all leaves have the same stem length or generate for each randomly 
leafStemWidth = random(leafStemLength) 
leaf[0].YPosition = random(stemHeight) 
leaf[0].XSide = randomly either left or right 
leaf[0].rotation = random between say 0 and 80 degrees 
for each leaf i: 
    leaf[i].YPosition = random(stemHeight, leaf[i-1]) // only generate new leaves above previous leaves 
    leaf[i].XSide = opposite of leaf[i].XSide 

마지막 단어를

하나가 그것을 주장하거나 몇 가지 고정 된 값을 제공하는 것입니다 각 random의 경계를 결정하는 방법 무작위로 몇 번 생성하고 이상하게 보일 때까지 늘리거나 줄입니다.

10 x 10 대 500 x 500은 아마도 크게 다른 알고리즘을 필요로 할 것입니다. 100x100 미만의 경우에는 권장하지 않으며, 더 큰 이미지를 생성하고 평균화 등을 사용하여 간단히 축소하십시오.

코드 나는 그것을 더 이상 나는이에 지출하고자하는보다 조금 걸릴 수 있습니다 깨달았을 때, 일부 Java 코드를 쓰기 시작, 그래서 내가 지금까지 무엇을 보여주지

.

// some other code, including these functions to generate random numbers: 
    float nextFloat(float rangeStart, float rangeEnd); 
    int nextInt(int rangeStart, int rangeEnd); 

    ... 

    // generates a color somewhere between green and brown 
    Color stemColor = Color.getHSBColor(nextFloat(0.1, 0.2), nextFloat(0.5, 1), nextFloat(0.2, 0.8)); 
    int stemHeight = nextInt(height/2, 3*height/4); 
    int stemWidth = nextInt(height/20, height/20 + height/5); 
    Color flowerColor = ??? // I just couldn't use the same method as above to generate bright colors, but I'm sure it's not too difficult 
    int flowerRadius = nextInt(Math.min(stemHeight, height - stemHeight)/4, 3*Math.min(stemHeight, height - stemHeight)/4); 
+0

간단히 말하면, 너는 최고야! – Hele

관련 문제