Due: Wednesday 10/09 10:00am
Submission name: w13_thermometer
Write A Processing Program:
Over the next few days, we will be making a processing program to display thermometers, showing temperatures in Fahrenheit and Celsius. This is but phase 0. This program should display a single thermometer made of:
- A large rectangle to contain the entire thermometer.
- A smaller interior rectangle to contain the temperature reading.
- A smaller rectangle containing the actual temperature reading (red part).
- Hashmarks along the side for numbers.
Improve on Yesterday’s Work
Make the following modifications to yesterday’s work.
- Add these global constants to the top of your program to allow us to switch between temperature scales:
int CELSIUS = 0; int FAHRENHEIT = 1;
- Modify
drawThermometer
- Add a
float temperature
parameter to provide a temperature amount. - Add an
int scale
parameter which will set the correct scale. - When calling
drawReading
, make the reading area 40% of the width of the thermometer and 90% of the height. - Display the
temperature
on top of the reading area.
- Add a
- Modify
drawReading
- Include
float temperature
andint scale
parameters. - In addition to the rectangle that represents the entire reading area, add a red rectangle that should represent the value of
temperature
.
- Include
- Modify
drawScale
- Include
int scale
as a parameter. - The scale should go from freezing to boiling in the appropriate range (32-212 or 0-100)
- Only draw hash marks on multiples of 5.
- Include
- Add a new function
float fToC(float fahrenheit)
- It will return the Celsius value of
fahrenheit
. - Conversion: c = \((f-32)\dfrac{5}{9}\)
- It will return the Celsius value of
- Use the following
setup
anddraw
when done (when working, you should just calldrawThermometer
insetup
and omitdraw
until you get everything working):void setup() { size(300, 600); textAlign(CENTER, CENTER); frameRate(30); }//setup void draw() { background(150); if (frameCount % 30 == 1) { ft = random(32, 212); } drawThermometer(50, 50, 100, 500, ft, FAHRENHEIT); drawThermometer(150, 50, 100, 500, fToC(ft), CELSIUS); }//draw
Reference Image:
The reference image includes numbers, you do not need to add them.