# Trigonometric Function (Live Mode)

Trigonometric Function (Live Mode)

In the example, values calculated by using the trigonometric function of the math library are visualized on the screen of CyberPi.

This is a simple project. You can see that the values are calculated by the computer and displayed as graphics on the screen of CyberPi. It makes good use of the drawing feature of CyberPi (though you can draw the graphics on your computer).

Or you can reverse the process, using a computer to visualize data collected by CyberPi. For example, you can display the result of an online vote of a class on the screen of a computer, or design a mobile app or cmputer client for CyberPi through Python programming.

import os

import sys

from time import sleep

import random

import math

import cyberpi

# Display the phase difference between the sin and cos functions

# Green indicates the cos function, and white indicates the sin function

print(“ready!”)

count = 0

while True:

val = int(math.sin(count / 2) * 50 + 50)

cyberpi.display.set_brush(0,255,0)

# Currently, only integers are valid, and so the values are changed into the int type

cyberpi.linechart.add(int(val))

val = int(math.cos(count / 2) * 50 + 50)

cyberpi.display.set_brush(255,255,255)

# Currently, only integers are valid, and so the values are changed into the int type

cyberpi.linechart.add(int(val))

# Set the drawing spacing of the line charts. Try to modify the spacing

count += 1