A Processing Java-mode sketch should draw an orange equipment block with its upper-left corner at (180,80) px(180,80)\ \text{px}(180,80) px and a blue circular indicator centred at (60,50) px(60,50)\ \text{px}(60,50) px. It uses this code:
void setup() { size(420, 240); colorMode(RGB, 255); noStroke(); rectMode(CORNER); ellipseMode(CENTER); fill(30, 90, 180); // blue pushMatrix(); translate(180, 80); fill(230, 120, 20); // orange rect(0, 0, 60, 30); popMatrix(); ellipse(60, 50, 20, 20); }
The indicator appears orange. Which single edit produces both intended colours and both intended positions? A matrix pair means pushMatrix() with its matching popMatrix(); a style pair means pushStyle() with its matching popStyle().
Keep the matrix pair, and add a style pair around the orange fill() and rect() calls.
Keep the matrix pair, but move its restoring call to just before the orange rect() call.
Replace the matrix pair with a style pair around the translation, orange fill(), and rect() calls.
Keep the matrix pair, and add another matrix pair around the orange fill() and rect() calls.
Unlock full course notes by signing up
Tracing the position actually drawn
A Processing Java-mode sketch animates a marker using the following complete code:
Count the first execution of draw() as call 1. Immediately after call 8 returns, before call 9 begins, what is the horizontal screen coordinate of the marker's centre in the displayed image?
Tracing nested coordinate frames
A Processing Java-mode sketch uses nested coordinate transformations to place two joint markers:
Using Processing's default 2D screen coordinates, what are the screen coordinates of the centres of markers A and B? All coordinates below are in pixels.
Comparing consecutive-temperature alarm conditions
An equipment monitor records one temperature per second. The following Processing sketch in Java mode processes the stored temperatures, in °C, once from beginning to end:
Determine the final alarmCount and meanTrigger for this original sketch. Then determine both quantities for a modified sketch in which only if (run == 3) becomes if (run >= 3).
Treat the original and modified sketches as independent runs with all variables initialized as shown. Enter both alarm counts as exact integers and both mean trigger temperatures in °C, to one decimal place.