60 likes | 155 Views
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) { }
E N D
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() { } }
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); }
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(); }
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(); }
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)
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(); }