added drawCircle

This commit is contained in:
Louis Heredero 2024-04-23 17:05:12 +02:00
parent a280dfd564
commit 11c90daaa2
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7

View File

@ -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)
}
}