Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE READ SCREENSHOTS Posting again as I was given wrong answer, for some reason someone decided to give me code on how to draw a

PLEASE READ SCREENSHOTS

Posting again as I was given wrong answer, for some reason someone decided to give me code on how to draw a face. They also mentioned you can only answer 1 question. This is in fact one task. Task (spirograph) is on top this time to prevent confusion. Everything below is information for you to answer the question using the given information. Use formulas given please.

Please write in java USING STDDRAW AND METHODS PROVIDED. Please do not overcomplicate and import anything not provided in the screenshots. The code is supposed to be relatively simple. The classes and methods to be used are seen in the screenshots, I just need help putting them into action to make spirograph. There is also a link at the bottom for how to use StdDraw ( how to set pen and background color) along with screenshot example of implementing background and color. There is also a screenshot of what I have so far (won't compile missing canvas size, background and pen color). WILL UPVOTE IF DONE USING GIVEN METHODS AND CLASSES. Thank you!

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribed

example of stddraw code drawing a square (I need a spirograph) and link on stddraw:

https://introcs.cs.princeton.edu/java/stdlib/javadoc/StdDraw.html

image text in transcribed

my code I have so far that is wrong ( maybe you can edit to make right) :

public class Spirograph { public static void main (final String[] args) { double R = Double.parseDouble(args[0]); double r = Double.parseDouble(args[1]); double a = Double.parseDouble(args[2]); for (double t = 0.0; t

Draw a Spirograph which is a curve that is formed rolling a curve inside or outside of another circle. The trick to drawing such a curve is to place the pen at any point on the rolling circle. If the radius of the fixed circle is R, the radius of the moving circle is r, and the offset of the pen point is a then the resulting curve is defined by: x=(R+r)cos(t)(r+a)cos(((R+r)/r)t)y=(R+r)sin(t)(r+a)sin(((R+r)/r)t) where t is a parameter that ranges from 0t100 in small increments (say 0.01 ) Input All Input for the above Task needs to taken as Commandline Arguments. No Input will be taken from the Standard Input Stream. The input consists of three numbers namely R, r, a which presents the following quantities R - Radius of the Larger Circle r - Radius of the smaller Circle a - Offset of the pen point in the moving circle Output java Spirograph 1804015 results in the following output: The authors of the textbook provide a class called StdDraw. It provides a simple interface for creating a window on the display. There are two kinds of methods: drawing commands that cause the device to take an action (such as drawing a line or drawing a point) and control commands that set parameters such as the pen size or the scale of the coordinate system. Please use this class. Drawing command examples: void line (double x, double y, double x1, double y1 ) void point (double x, double y ) static void square(double x, double y, double r ) Control Command Examples: StdDraw. setPencolor (Color c); // i.e. c= StdDraw.GRAY By default, all drawing takes places in the unit square, with (0,0) at lower left and (1,1) at upper right. but we often want to draw plots at different scales. Also, we often want to draw lines of different thickness and points of different size than the standard. The x - and y coordinates must be in the drawing area (between 0 and 1 and by default) or the points and lines will not be visible. The following method sets the canvas (drawing area) to be width-by-height pixels. This also erases the current drawing and resets the coordinate system, pen radius, pen color, and font back to their default values. Ordinarly, this method is called once, at the very beginning of a program. setCanvasSize(int canvasWidth, int canvasHeight) These scale methods change the coordinate system for subsequent drawing commands; they do not affect previous drawings. These methods do not change the canvas size; so, if the x - and y-scales are different, squares will become rectangles and circles will become ellipsoidal. Pen size. The pen is circular, so that when you set the pen radius to r and draw a point, you get a circle of radius r. Also, lines are of thickness 2r and have rounded ends. The default pen radius is 0.005 and is not affected by coordinate scaling. This default pen radius is about 1/200 the width of the default canvas, so that if you draw 100 points equally spaced along a horizontal or vertical line, you will be able to see individual circles, but if you draw 200 such points, the result will look like a line. The methods StdDraw. clear(StdDraw. BLACK), StdDraw. setPenRadius 0 and StdDraw. setPenColor() can be used to control the background color of the canvas, the line thickness and color of the pen. StdDraw also includes methods to draw circles, rectangles, and arbitrary polygons. Take a look at the StdDraw API documentation for more information. How To Use StdDraw Download the file stddraw.jar and keep it in your working directory. You can also use the StdDraw.java your working directory. You can use this external library when you are running your program through the command line as follows: Windows (semicolon before stddraw.jar): javac -cp . jstddraw.jar spirograph.java java -cp .jstddraw.jar Spirograph 1804015 Mac/Linux/Unix (colon before stddraw.jar): javac -cp . :stddraw.jar Spirograph.java java -cp .:stddraw.jar Spirograph 1804015 The stddraw.jar and your java file should be in the same folder. Here is an example of using StdDraw: public class Drawsquare \{ public static void main (final string[] args) \{ double x=0.5,y=0.5;// center of square double size =0.5;// side length of square // plot a square, centered on (x,y) of the given side length // with a light gray background and black border StdDraw. setPencolor (StdDraw. LIGHT_GRAY); StdDraw.filledSquare (x, y, size/2); StdDraw.setPenColor (StdDraw.BLACK); StdDraw. square ( x,y, size/2); \} \}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

JDBC Database Programming With J2ee

Authors: Art Taylor

1st Edition

0130453234, 978-0130453235

More Books

Students also viewed these Databases questions

Question

Distinguish between poor and good positive and neutral messages.

Answered: 1 week ago

Question

Describe the four specific guidelines for using the direct plan.

Answered: 1 week ago