added drawCircle
This commit is contained in:
parent
a280dfd564
commit
11c90daaa2
@ -2,9 +2,23 @@ package logo
|
|||||||
|
|
||||||
import hevs.graphics.TurtleGraphics
|
import hevs.graphics.TurtleGraphics
|
||||||
|
|
||||||
|
import java.awt.Color
|
||||||
|
|
||||||
object TestLogo {
|
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 = {
|
def main(args: Array[String]): Unit = {
|
||||||
val turtle: TurtleGraphics = new TurtleGraphics(600, 600)
|
val turtle: TurtleGraphics = new TurtleGraphics(600, 600)
|
||||||
|
turtle.drawLine(150, 300, 450, 300)
|
||||||
|
|
||||||
turtle.penUp()
|
turtle.penUp()
|
||||||
turtle.jump(300, 300)
|
turtle.jump(300, 300)
|
||||||
turtle.setAngle(0)
|
turtle.setAngle(0)
|
||||||
@ -15,5 +29,10 @@ object TestLogo {
|
|||||||
turtle.forward(300)
|
turtle.forward(300)
|
||||||
turtle.turn(120)
|
turtle.turn(120)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
turtle.jump(450, 300)
|
||||||
|
turtle.setAngle(90)
|
||||||
|
turtle.setColor(Color.RED)
|
||||||
|
drawCircle(turtle, 150)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user