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:
int[] temperature = {74, 78, 82, 79, 65, 76, 81, 84, 87, 60, 83}; void setup() { int run = 0; int alarmCount = 0; int triggerTotal = 0; for (int i = 0; i < temperature.length; i++) { if (temperature[i] >= 75) { run++; } else { run = 0; } if (run == 3) { alarmCount++; triggerTotal += temperature[i]; } } float meanTrigger = triggerTotal / float(alarmCount); println(alarmCount); println(meanTrigger); }
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.
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?
Restoring colour without losing position
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:
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().
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.