From 11c90daaa2285052a2ccd0124f87b983389b7222 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Tue, 23 Apr 2024 17:05:12 +0200 Subject: [PATCH] added drawCircle --- src/logo/TestLogo.scala | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/logo/TestLogo.scala b/src/logo/TestLogo.scala index c8bb97a..a0b3fef 100644 --- a/src/logo/TestLogo.scala +++ b/src/logo/TestLogo.scala @@ -2,9 +2,23 @@ package logo import hevs.graphics.TurtleGraphics +import java.awt.Color + object TestLogo { + def drawCircle(turtle: TurtleGraphics, radius: Double, resolution: Int = 24): Unit = { + val angle: Double = 360.0 / resolution + val side: Double = radius * math.sin(angle * math.Pi / 180) + turtle.forward(-side / 2) + for (_: Int <- 0 until resolution) { + turtle.forward(side) + turtle.turn(angle) + } + } + def main(args: Array[String]): Unit = { val turtle: TurtleGraphics = new TurtleGraphics(600, 600) + turtle.drawLine(150, 300, 450, 300) + turtle.penUp() turtle.jump(300, 300) turtle.setAngle(0) @@ -15,5 +29,10 @@ object TestLogo { turtle.forward(300) turtle.turn(120) } + + turtle.jump(450, 300) + turtle.setAngle(90) + turtle.setColor(Color.RED) + drawCircle(turtle, 150) } }