Kojo Wiki

docs for Kojo

View source on GitHub

The shape-block method - blocks move along ellipse

Step 1

Type in the following code and run it:


def shape() {

// the radii of the ellipse
val r1 = 200
val r2 = 100

// x and y are calculated based on the parametric form of the equation of an ellipse
def posx(a: Int) = r1 * math.cos(a.toRadians)
def posy(a: Int) = r2 * math.sin(a.toRadians)

def block(a: Int) {
    setPosition(posx(a), posy(a))

repeatFor(rangeTill(0, 360, 10)) { a =>

// viewRotate(45)

Q1a In the above design, what’s the shape?

Q1b In the above design, what’s the block? Why does the block command take an input?

Q1c How many times is the block repeated to make the above design?

Q1d Are posx and posy commands or functions? What do they do? How are they used?

Q1e How can you center the ellipse used by the block at (100, 50) instead of (0, 0)

Q1f How can you align the ellipse used by the block at an angle of 45 degrees to the horizontal?


Here’s how designs are made using this method:

  • You define a shape.
  • You define a block.
    • The block calls the shape, picks the pen up, moves the turtle along an ellipse, and then puts the pen down, to be ready to make the next shape.
  • You repeat the block the desired number of times to make the pattern.

Command Description

  • viewRotate(angle) - rotates the contents of the drawing canvas by the given angle.


Use the above idea to make a design.

Contribute Content
Copyright © Kogics Foundation