1 / 6

DrawingGizmo Example

DrawingGizmo Example. public class Driver { private DrawingGizmo pencil; private void drawSquare(int sideLength) { } private void drawRectangle(int width, int height) { } private void drawRightTriangle(int side1, int side2) { }

orde
Download Presentation

DrawingGizmo Example

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DrawingGizmo Example public class Driver { private DrawingGizmo pencil; private void drawSquare(int sideLength) { } private void drawRectangle(int width, int height) { } private void drawRightTriangle(int side1, int side2) { } public Driver() { } }

  2. DrawingGizmo Example public Driver() { pencil = new DrawingGizmo(); pencil.dontDraw(); pencil.moveBy(50); pencil.turnBy(-90); pencil.moveBy(50); pencil.turnBy(90); drawSquare(50); pencil.turnBy(90); pencil.moveBy(70); pencil.turnBy(-90); drawRectangle(70, 30); pencil.turnBy(90); pencil.moveBy(90); pencil.turnBy(-90); drawRightTriangle(40, 30); }

  3. DrawingGizmo Example private void drawSquare(int sideLength) { pencil.draw(); pencil.turnBy(90); pencil.moveBy(sideLength); pencil.turnBy(90); pencil.moveBy(sideLength); pencil.turnBy(90); pencil.moveBy(sideLength); pencil.turnBy(90); pencil.moveBy(sideLength); pencil.dontDraw(); }

  4. DrawingGizmo Example private void drawRectangle(int width, int height) { pencil.draw(); pencil.turnBy(90); pencil.moveBy(width); pencil.turnBy(90); pencil.moveBy(height); pencil.turnBy(90); pencil.moveBy(width); pencil.turnBy(90); pencil.moveBy(height); pencil.dontDraw(); }

  5. Geometry Review Side12+Side22 = Hypotenuse2 Sin α = Side2/Hypotenuse Cos α = Side1/Hypotenuse Tan α = Side2/Side1 Angle α Hypotenuse Side1 Side2 Arctan (Side2/Side1) = α Degrees = Radians * (180/π) Right Angle (90)

  6. DrawingGizmo Example private void drawRightTriangle(int side1, int side2) { pencil.draw(); pencil.turnBy(180-(int)(Math.atan(side2/(double)side1)*180/Math.PI)); pencil.moveBy((int) Math.sqrt(side1*side1+side2*side2)); pencil.turnBy(90+(int)(Math.atan(side2/(double)side1)*180/Math.PI)); pencil.moveBy(side2); pencil.turnBy(90); pencil.moveBy(side1); pencil.dontDraw(); }

More Related