Tychos Docs
  • Tychos Documentation and Reference
  • General
  • Change Log
  • Python Demonstrations
  • MathJs Demonstrations
  • Our Team
  • Learn
    • Overview
    • Creating and Managing Scenarios
    • The Interface
    • Tychos Python Language Reference
    • Tychos MathJs Language Reference
    • Video Guides
      • Video Tutorial: An Overview
      • Video Tutorial: Settings
      • Video Tutorial: Animating Motion
      • Video Tutorial: Meters and Gauges
      • Video Tutorial: Graphs and Bar Charts
      • Video Tutorial: Arrows and Lines
      • Video Tutorial: Tables
  • For Teachers
    • Getting Started
    • Creating and Managing Classes
    • Giving Feedback: Comments
    • Tutorials (Python)
      • Python Tutorial 1: Introduction to Coding in Tychos
      • Python Tutorial 2: Circles and Rectangles
      • Python Tutorial 3: Arrows and Lines (and Poly Lines)
      • Python Tutorial 4: Simulating Change
      • Python Tutorial 5: Simulating Constant Velocity
      • Python Tutorial 6: Using Graphs
      • Python Tutorial 7: Modeling The Momentum Principle
      • Python Tutorial 8: Modeling A Projectile
      • Python Tutorial 9: Conditional Forces
    • Tutorials (MathJs)
      • MathJs Tutorial 1: Introduction to Coding in Tychos
      • MathJs Tutorial 2: Circles and Rectangles
      • MathJs Tutorial 3: Arrows and Lines
      • MathJs Tutorial 4: Simulating Change
      • MathJs Tutorial 5: Simulating Constant Velocity
      • MathJs Tutorial 6: Using Motion Graphs
      • MathJs Tutorial 7: Modeling The Momentum Principle
      • MathJs Tutorial 8: Modeling A Projectile
      • MathJs Tutorial 9: Conditional Forces
    • Writing Goals (Python)
    • Writing Goals (MathJs)
    • Canvas LTI Installation Guide
    • Lesson Worksheets (Google Docs)
Powered by GitBook
On this page
  • Tutorial Overview and Objectives
  • Creating Circles
  • The Position Attribute
  • Creating Rectangles
  • Using Images to Represent Your Objects

Was this helpful?

  1. For Teachers
  2. Tutorials (Python)

Python Tutorial 2: Circles and Rectangles

PreviousPython Tutorial 1: Introduction to Coding in TychosNextPython Tutorial 3: Arrows and Lines (and Poly Lines)

Last updated 1 year ago

Was this helpful?

Tutorial Overview and Objectives

In this tutorial, you will learn two of the important objects of the Tychos world, namely the object, and the object as well as how to use the object to visualize vector quantities.

You will learn:

  • How to create objects.

  • How to create objects.

  • How to change certain attributes such as the position, size and color of these objects.

  • How to represent these objects using images rather than the default graphic representations.

Click on the link below to open the Tychos scenario in a new browser tab where you can follow along, or use the embedded frame that contains the scenario below:

Now it's time to actual simulate something in the simulated environment, and we are going to define the simplest, most basic objects of our simulation - the rectangle and circle objects.

Let's learn how you can create simulated objects in Tychos and how you can place those objects at different positions within the simulated 2D space.

Creating Circles

objects are meant to be representative of any object in your simulated world. They could represent a spherical object such as a planet or a ball, but could also represent any object, as long as it serves your purpose of simply representing the position of the object.

If all you need is a general sense of the object's size and position, then a Tychos is probably the object that you are going to use.

c1 = circle()
c1 = circle(radius=10, color="green")

  • image — A URL that identifies a JPEG, GIF, SVG or PNG image.

  • motion_map — This flag tells Tychos to attach a series of strobe images called a motion map. Note: You also have to have the Motion Map setting turned on in the Settings pane.

  • label_color - This specifies the color of the label text.

c1 = circle(pos=vec(10,10), radius=10, color="red")

Notice that the attributes follow a pattern:

name = value

The first text is the name of the attribute, and then an equals sign, and then the value of the attribute. The order that you have them in does not matter, just as long as you get the names correct:

c1 = circle(radius=10, color="red", pos=vec(10,10))
g_car = circle(pos=vec(0, 100), radius=10, color="green")
r_car = circle(pos=vec(100, 0), radius=10, color="red")

The Position Attribute

c1.pos = vec(100, 0)

This line of code is read "The object c1's position is now x = 100 and y = 0".

Creating Rectangles

r1 = rectangle()
r1 = rectangle(pos=vec(10, 10), size=vec(10, 20), color="purple")
  • image — A URL that identifies a JPEG, GIF, SVG or PNG image.

  • motion_map — This flag tells Tychos to attach a series of strobe images called a motion map. Note: You also have to have the Motion Map setting turned on in the Settings pane.

  • label_color - This specifies the color of the label text.

Using Images to Represent Your Objects

You are not limited to visually representing your objects using only simple circles and rectangles. You can also use any image from the web.

This is done by changing the image attribute like this:

c1.image = "https://upload.wikimedia.org/wikipedia/en/thumb/e/ec/Soccer_ball.svg/240px-Soccer_ball.svg.png"

Tychos will now replace the simple image of a solid colored circle with this image:

It is recommended that you use either svg images that are scalable, or png and gif files that allow you to store transparency values.

Keep in mind that the physical dimensions of the image will be scaled to the object size defined in either the radius attribute or the size attribute of the object.

To create a in the simulation, you need to first identify a valid variable name to store the reference to the object. You then assign the variable to the result of a command that invokes or essentially brings the object into existence:

This particular object is created and placed in the virtual world at the position of x = 0 and y = 0 with a default radius of 10 and a default color.

The above code uses the default attributes of a object, but you can actually create one with your own initial values. For example, you can also define the size of the .

Here is how you can create a object with a radius of 10, and a color of green:

This changes the visual size of the particle on the screen. The text inside the parentheses is a list of name and value pairs that define the attributes of the object. There a number of these attributes that can be set or changed in your simulation:

pos — The initial position of your in x,y coordinates.

radius — The radius of the that is drawn in the World View to represent this particle.

color — The will be drawn in this color. Use HTML colors e.g. "#ff3300", "blue".

opacity — The will be drawn with an opacity between 1 and 0, representing 100% opaque to 100% transparent.

visible — The can be hidden from view by setting this flag to false.

label_text - You can attach a label to the object by indicating the text and color of the label.

border_size - The object can be displayed with a border with a stroke width.

border_color - The object's border color.

border_style - The object's border can be set to dash or dot, or none by default.

So for example, you can also change the initial position or color of the object when you create one:

You can create more than one , you just have to assign it a different variable name. The code below creates two different objects. The names that you use can be almost anything:

Again, here the objects are representing a green car and another representing a red car.

You can change the position of a object by referencing its "pos" attribute. This is done by using a common computer science notation called "dot" notation. Its quite easy:

The object is another Tychos object that you can use to represent of an object in your simulated world. They could represent objects such as a box, or a table top, but could also represent any object. The big difference between a object and a object is that objects have a length and a width rather than a radius.

If you need an object that visually represents the important difference between the length and width of the object, then a Tychos object is probably the object that you are going to use.

To create a object in the simulation, once again you need to first identify a valid variable name to store the reference to the object. Just like with the the object, you create a object by assigning the variable to the result of a command that invokes or essentially brings the object into existence:

This object is created and placed in the virtual world at the position of x = 0 and y = 0 with a default length and width of 5 and 5.

Just as with the object, you can override the default attribute values of your object by giving it a set of name: value pairs in a list:

Rather than defining a radius as the visual size attribute, the size attribute here gives your object a width (or X size value) and length (or Y size value).

The other attributes of the object are very similar to the object. Here is a full listing of those attributes:

pos — The initial position of your in x, y coordinates.

size — The width and height of the that is drawn in the World View to represent this particle.

color — The will be drawn in this color. Use HTML colors e.g. "#ff3300", "blue".

opacity — The will be drawn with an opacity between 1 and 0, representing 100% opaque to 100% transparent.

visible — The can be hidden from view by setting this flag to false.

label_text - You can attach a label to the object by indicating the text and color of the label.

border_size - The object can be displayed with a border with a stroke width.

border_color - The object's border color.

border_style - The object's border can be set to dash or dot, or none by default.

Lesson 2: Circles and Rectangles
svg image of a soccer ball
Circle
circle
rectangle
arrow
circle
rectangle
circle
circle
circle
circle
circle
circle
circle
circle
circle
circle
circle
circle
circle
circle
circle
circle
circle
circle
circle
circle
circle
circle
circle
rectangle
rectangle
rectangle
rectangle
rectangle
rectangle
rectangle
rectangle
rectangle
circle
rectangle
rectangle
rectangle
circle
rectangle
rectangle
rectangle
rectangle
rectangle
rectangle
rectangle
rectangle
rectangle