int cellSize = 30;
int radius = cellSize/2;
int ellipseSize = cellSize;
int ellipseSizeMini = 5;
int gap = 0;
void setup()
{
size (300, 300);
background(255);
noStroke();
for (int j=0; j<height; j=j+cellSize)
for (int i=0; i<width; i=i+cellSize)
fill(0);
ellipse(i+radius, j+radius, ellipseSize, ellipseSize);
ellipseSizeMini = calculateSizeMini(i, j);
gap = radius-(ellipseSizeMini/2);// [10%] to write an equation which calculates the length of gap between the smaller white circle and the bigger black circle. Hard coding value does not receive any mark
float shiftX = random(-gap, gap);
float shiftY = random(-gap, gap);
fill(255);
ellipse(i+radius+shiftX,j+radius+shiftY,ellipseSizeMini,ellipseSizeMini); // [10%] fill in the four parameters (each takes 2.5% mark) for this ellipse() so that it draw a white circle on top of its corresponding black circle with size of ellipseSizeMini
}
}
int calculateSizeMini(int i, int j)
{
int sizeMax = (int)0.8*ellipseSize;// [5%] to write an equation which generates a value of 80% of ellipseSize to be the maximum possible size of the small white circle. Hard coding value does not receive any mark
int sizeMin = (int) 0.1*ellipseSize;// [5%] to write an equation which generates a value of 10% of ellipseSize to be the minimum possible size of the small white circle. Hard coding value does not receive any mark
int answer = ellipseSizeMini;
// [20%] to develop equation(s) and write lines of code here to calculate a value for ellipseSizeMini. This value changes according to i and j.
// The value is closed to sizeMax if i and j are closed to the center of the application window, and it closed to sizeMin if i and j are
// closed to the edge of the application window. This value will be assigned to the variable of answer as a returning value of this function.
// The simpler the approach, the higher is the mark.
return answer;
}
i finshed the previous part and the last part just make me crazy. i can’t work this out.
Can someone help me ? The closer a white dot locates toward the center, the bigger it is and vice versa. You should try to solve this problem by simply coding.
Hello and welcome to the forum!
You can find the distance with dist()
See reference please https://www.processing.org/reference/dist_.html
Store the distance in a float variable distC
Next step: use map() to get the size of a circle:
float sizeC= map( distC, 0, width/3, 3, 30);
to get the size of the circle (between 3 and 30 in the line above)
Warmest regards,
Chrisir