Shapes

Shapes are the most basic building-blocks of any Code Shrew program. Drawing is achieved by creating shape objects. For example, if you type Circle(color='red') in the Code Shrew editor, you will immediately see a red circle.

There are currently 7 basic shapes in Code Shrew: Rectangle, Square, Ellipse, Circle, Line, Polygon, and Text. Don't worry, though - the icons module contains 995 more!

The appearance of a shape can be modified using its properties. Different kinds of shapes have different properties, as described below. You can set a value of a property when creating a shape or anytime later. So those are both equally valid methods of creating a brown square:

Shapes also have methods that perform different actions. For example to create a mirror image of a text you can use the flip_horizontal() method:

Shapes are drawn on a 100x100 plane. Of course, you can add as many shapes to a single drawing as you like.

You will find a detail description of each shape's properties and methods below.

Rectangle

Rectangle's properties

  • width (default: 100) - the width of the rectangle
  • height (default: 100) - the height of the rectangle
  • x (default: 50) - the horizontal coordinate describing where the center of the rectangle should be
  • y (default: 50) - the vertical coordinate describing where the center of the rectangle should be
  • color (default: "black") - the color or color gradient of the rectangle
  • transparency (default: 0) - how transparent the rectangle should be (from 0 to 100)
  • rotation (default: 0) - the amount of rectangle's rotation (from 0 to 360 degrees)

Rectangle's methods

  • copy() - create a new rectangle with the same properties as the original one
  • flip_horizontal() - flip the rectangle horizontally
  • flip_vertical() - flip the rectangle vertically
  • enlarge(amount) - make the rectangle amount times bigger (for example, my_rectangle.enlarge(2) will make the rectangle two times bigger)

Example


Square

Square is just an alias for the Rectangle and has the exact same methods and properties. This may change in the future.

Example


Ellipse

  • width (default: 100) - the width of the ellipse
  • height (default: 100) - the height of the ellipse
  • x (default: 50) - the horizontal coordinate describing where the center of the ellipse should be
  • y (default: 50) - the vertical coordinate describing where the center of the ellipse should be
  • color (default: "black") - the color or color gradient of the ellipse
  • transparency (default:0) - how transparent the ellipse should be (from 0 to 100)
  • rotation (default: 0) - the amount of ellipse's rotation (from 0 to 360 degrees)

Ellipse's methods

  • copy() - create a new ellipse with the same properties as the original one
  • flip_horizontal() - flip the ellipse horizontally
  • flip_vertical() - flip the ellipse vertically
  • enlarge(amount) - make the ellipse amount times bigger (for example, my_ellipse.enlarge(2) will make the ellipse two times bigger)

Example


Circle

Circle is just an alias for the Ellipse and has the exact same methods and properties. This may change in the future.

Example


Line

  • points (default: [(0,0), (100, 100)]) - a list containing coordinates of the line's points (for example, a value of [(10, 10), (50, 50)] would create a line going from point (10, 10) to point (50, 50)). The list may contain more than two points - this will result in a line containing multiple segments.
  • width (default: determined by points) - the width of the line
  • height (default: determined by points) - the height of the line
  • x (default: 50) - the horizontal coordinate describing where the center of the line should be
  • y (default: 50) - the vertical coordinate describing where the center of the line should be
  • color (default: "black") - the color or color gradient of the line
  • transparency (default: 0) - how transparent the line should be (from 0 to 100)
  • rotation (default: 0) - the amount of line's rotation (from 0 to 360 degrees)

Line's methods

  • copy() - create a new line with the same properties as the original one
  • flip_horizontal() - flip the line horizontally
  • flip_vertical() - flip the line vertically
  • enlarge(amount) - make the line amount times bigger (for example, my_line.enlarge(2) will make the line two times bigger)

Example


Polygon

  • points (default: [(50,0), (0,100), (100,100)]) - a list containing coordinates of the polygon's points (for example, a value of [(10, 10), (50, 50), (10,50)] would create a triangle with vertices in points (10, 10), (50, 50) and (10, 50)). The list may contain more than two points - this will result in a polygon containing multiple segments.
  • width (default: determined by points) - the width of the polygon
  • height (default: determined by points) - the height of the polygon
  • x (default: 50) - the horizontal coordinate describing where the center of the polygon should be
  • y (default: 50) - the vertical coordinate describing where the center of the polygon should be
  • color (default: "black") - the color or color gradient of the polygon
  • transparency (default: 0) - how transparent the polygon should be (from 0 to 100)
  • rotation (default: 0) - the amount of polygon's rotation (from 0 to 360 degrees)

Polygon's methods

  • copy() - create a new polygon with the same properties as the original one
  • flip_horizontal() - flip the polygon horizontally
  • flip_vertical() - flip the polygon vertically
  • enlarge(amount) - make the polygon amount times bigger (for example, my_polygon.enlarge(2) will make the polygon two times bigger)

Example


Text

  • text (default: "Hello World!") - the text that should be displayed; can be a string of quoted characters, a number or even... a shape object.
  • font_size (default: 10) - controls the size of the text
  • x (default: 50) - the horizontal coordinate describing where the center of the text should be
  • y (default: 50) - the vertical coordinate describing where the center of the text should be
  • color (default: "black") - the color or color gradient of the text
  • transparency (default: 0) - how transparent the text should be (from 0 to 100)
  • rotation (default: 0) - the amount of text's rotation (from 0 to 360 degrees)

Text's methods

  • copy() - create a new text with the same properties as the original one
  • flip_horizontal() - flip the text horizontally
  • flip_vertical() - flip the text vertically
  • enlarge(amount) - make the text amount times bigger (for example, my_text.enlarge(2) will make the text two times bigger)

Example