As the user presses one of the following keys, background is cleared and corresponding lines are drawn. h : horizontal lines v : vertical lines g : grid lines - : dotted horizontal lines (hyphen...

1 answer below »
Please see the attached files below for assignment instructions, also there is a video to show an example of the successful code.


As the user presses one of the following keys, background is cleared and corresponding lines are drawn. h : horizontal lines v : vertical lines g : grid lines - : dotted horizontal lines (hyphen key) (moderate challenge) i : dotted vertical lines  (moderate challenge) / : forward slanted lines \ : backward slanted lines  (moderate challenge) c : cursive lettering guide lines (moderate challenge)  e : end If user presses any other key, you can make the system beep - look into slides that dealt with nested loops & keyboard 1. Write separate functions to draw each style of line and name it accordingly.  Example : function names can be horizontal_lines(), vertical_lines(). Each of those functions will typically make use of one or two for-loop to get the job done; in some cases, nested for loop might be needed. 2. Call those functions at the appropriate places inside keyPressed(). 3. Check processing reference setTitle() for displaying info on the title of the canvas - if you are unsure, you can display it on the console using println (use this option as the worst case scenario). **all homework done in processing.org software Lavf58.12.100
Answered Same DaySep 14, 2021

Answer To: As the user presses one of the following keys, background is cleared and corresponding lines are...

Ramachandran answered on Sep 15 2021
152 Votes
Order-91214/Line_Drawing/Line_Drawing.pde
import java.awt.Toolkit;
// validKey title
String validKeys = "Valid keys are h v
g c / \\ - i e";
// default title
String defaultTitle = "Click on the canvas. ";
// title when 'e' is pressed
String endTitle = "BYE - SEE YOU LATER";
// combined title
String title = defaultTitle+validKeys;
// default selected key
char curKey = '\0';
//max width of the window
int maxX = 800;
//max height of the window
int maxY = 800;
//gap between lines
int gap = 25;
// gap within dotted lines
int dotGap = 10;
// allowed keys for operation
char[] ALLOWED_KEYS = {'h', 'v', 'g', 'c', '/', '\\', '-', 'i', 'e'};
//setup method that is called once application is loaded
void setup() {
//setting the size of the screen
size(800, 800);
// disable continious drawing
noLoop();
}
//draw method that is called continously based on the framerate
void draw() {
//clearing the background 255 is setting the background as white
background(255);
//set the title of the window based on curKey
surface.setTitle(title);
//similar to if else, decides which method to call based on the key pressed
switch (curKey) {
case 'h':
horizontal_lines();
break;
case 'v':
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here