how can I create a rice grain arrangement using ellipse and noise functions

edited June 2014 in How To...

Hello, Is it possible to create a pattern using noise function (for the amount of angular displacement of each grain) and ellipse function ( for the shape of the grain )? Hinohikari_hulled

Thank you

Tagged:

Answers

  • Yes, probably. What have you tried?

  • edited June 2014

    To recreate the shape, I used the following code:

    for (x = 0 ; x < width ; x = x + 5){
      for (y = 0 ; y < height ; y = y + 20){
        ellipse(x, y, 5, 20);
      }
    }
    

    I do not yet know how to use the noise function to adjust the result to the above pattern. My image as of now rice-pattern-attempt

  • Answer ✓

    I'd take a step back: can you create a single grain of rice that displays at a random angle?

  • edited June 2014

    Thank you very much. I was able to create the single grain displaced randomly using the code:

    { 
      int a=200,b=150;
      translate(a,b); 
      ang=noise(a,b);
      rotate(ang*2*PI);
      ellipse(0,0,5,20); 
      rotate(-ang*2*PI);
      translate(-a,-b);
    }
    

    I was also able to extend the same to

    for(x=0;x<width;x=x+5) {
      for(y=0;y<height;y=y+7) {
        translate(x,y);
        ang=noise(x,y);
        rotate(ang*2*PI);
        ellipse(0,0,5,20); 
        rotate(-ang*2*PI);
        translate(-x,-y);
      }
    }
    

    The resultant image rice-attempt2

    How could I improvise on the above?

    Thank you

  • I'm not exactly sure what you're asking. Maybe try adding colors/shades, or different sizes, or some user interaction (make the rice avoid the mouse, or travel towards the mouse). I'm not sure what your end goal is, so it's hard to tell you what to do next.

  • The end goal was the image attached with my question. I wanted that pattern of arrangement

  • Well, I think you are very close... What do you want to improve?

  • You might also be interested in reading about circle packing algorithms: http://en.wikipedia.org/wiki/Circle_packing

  • edited June 2014

    @_vk: I am vague on that, I would like it to be more recognizable,i.e. those seeing only my pattern should be able to know that it is a rice-grain like arrangement. I'm sorry I am unable to put this across properly.

    @KevinWorkman:I will, thank you

    Thank you for the guidance so far

  • You could also consider using actual images of rice grains instead of simple ovals.

  • _vk_vk
    edited June 2014

    Or, try improving one grain image, some imperfections, draw that vertical split... some shading... (3d?) If going for 3D, a use an image as texture...

    Perhaps a RiceGrain class to help you dealing with all parameters

    A silly and poor 3D rice grain:

    void setup(){
    size(200,200, P3D);
    background(0);
    
    smooth();
    noStroke();
    fill(255);
    lights();
    directionalLight(50, 50, 50, -1, 1, 0);
    translate(width/2, height/2);
    scale(0.5, 1);
    sphere(40);
    
    }
    
  • And about circle packing, there is this old post with a cool example from amnon...

    http://forum.processing.org/one/topic/help-random-distribution-of-non-overlapping-circles.html

Sign In or Register to comment.