Write a static Processing sketch that draws circles on the screen. Your program
ID: 661996 • Letter: W
Question
Write a static Processing sketch that draws circles on the screen. Your program should have a variable called numBalls declared and initialized at the top of your code. This value determines how many balls will be drawn. The first row has numBalls, the next row has one less ball, the next row has two less, etc. Use a window size of 500x500. All the balls should be visible in the output window. There should be a little bit of space between each ball on the screen.The output of your program when numBalls is 5 and 11 will look something like the following:
Explanation / Answer
int numBalls = 11; //numBalls initialization
void setup(){
size(500 ,500); //setting up window size
}
void draw(){
int diameter = (500 / numBalls); //divide screen size by number of balls gives the diameter
int radius = diameter/2; //diameter divided by 2 gives radius
for (int i = radius; i < 500; i = i+diameter) { //select each row
for (int j = i; j < 500; j = j+diameter) { //select each column
ellipse(i, j, radius, radius); //draws circle ar (i,j) with 'radius' values as radius
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.