Drawing a simple cricket bat and ball

edited October 2017 in Share Your Work
void setup(){
  fullScreen();
  background(0);
  stroke(192);
  strokeWeight(3);
  noLoop();  
}

void draw(){
  line(100,100,250,250); //bat handle lower edge
  line(125,75,275,225);  //bat handle upper edge
  line(100,100,125,75);  //bat handle upper width
  line(275,225,300,200); //bat upper collar
  line(250,250,225,275); //bat lower collar
  line(300,200,600,500); //bat upper edge
  line(225,275,525,575); //bat lower edge
  noFill();
  arc(525,500,150,150,0,PI/2);  //curved edge of bat
  ellipse(600,400,50,50);       //ball
  strokeWeight(1);
  line(575,398,625,398);        //ball seam upper edge
  line(575,402,625,402);        //ball seam lower edge
}

Comments

  • Somehow the image doesn’t come out

    You can go back and edit your post

  • @Chrisir sorry didn't realize. I have modified the post. Please try and run the code now and let me know. Thanks!

  • There are two icons for images maybe you want the one on the left side?

  • edited October 2017

    Fun, and looks good, @mproc.

    I think that the coordinates and the fullscreen call are very specific to certain monitor sizes.

    1. Keep in mind that you can draw a bat with its points centered around 0,0 and then use translate() to place it anywhere you want.
    2. You can specify the points at any scale that makes sense with the stroke weight you are using (e.g. maybe 200x200 at default stroke weight 1, rather than 600x600 at 3) and then use scale(3) before drawing to make your image larger.

    Like this:

    // cricket bat redux
    // forum.processing.org/two/discussion/24642/drawing-a-simple-cricket-bat-and-ball
    
    void setup(){
      size(800,800);
      stroke(192);
      noFill();
    } 
    void draw(){
      background(0);
      translate(width/2,height/2);
      scale(second()%10);
      drawBat();
      translate(35,15);
      drawBall();
    }
    void drawBat(){
      line(-15.0,-15.0,  0.0,  0.0);  //bat handle lower edge
      line(-12.5,-17.5,  2.5, -2.5);  //bat handle upper edge
      line(-15.0,-15.0,-12.5,-17.5);  //bat handle upper width
      line(  2.5, -2.5,  5.0, -5.0);  //bat upper collar
      line(  0.0,  0.0, -2.5,  2.5);  //bat lower collar
      line(  5.0, -5.0, 35.0, 25.0);  //bat upper edge
      line( -2.5,  2.5, 27.5, 32.5);  //bat lower edge
      arc(  27.5, 25.0, 15.0, 15.0, 0, PI/2);  //bat curved edge
    }
    void drawBall(){
      ellipse(0,0,5,5);  //ball
      pushStyle();
      strokeWeight(0.5);
      line(-2.45,-0.5, 2.45,-0.5);  //ball seam upper edge
      line(-2.45, 0.5, 2.45, 0.5);  //ball seam lower edge
      popStyle();
    }
    

    If you are interested you can go even further with this by putting your bat and ball into PShapes.

  • edited October 2017

    @Chrisir sorry didn't get you.... :-/

  • @jeremydouglass Thanks for your wonderful comment. Didn't know about scaling, pushStyle and popStyle. It's Great! Thanks!

Sign In or Register to comment.