sin_wave.py

Created by wperez274

Created on September 20, 2023

928 Bytes


from kandinsky import *
from math import sin, pi, cos

WIDTH = 320
HEIGHT = 222

rect_width = 20
rect_height = 20
rect_color = color(255, 0, 0)

amplitude = 40
frequency = 0.02
x = WIDTH - rect_width
y = HEIGHT - rect_height

while x >= -rect_width and y >= -rect_height:
    fill_rect(0, 0, WIDTH, HEIGHT, color(255, 255, 255))
    y = int(HEIGHT / 2 + amplitude * sin(2 * pi * frequency * (WIDTH - x) / WIDTH))
    fill_rect(x, y, rect_width, rect_height, rect_color)

    # Add circular movement
    circular_radius = 10  # Adjust this for the size of the circular movement
    circular_speed = 0.03  # Adjust this for the speed of the circular movement
    circular_x = x + int(circular_radius * cos(circular_speed * x))
    circular_y = y + int(circular_radius * sin(circular_speed * x))
    fill_rect(circular_x, circular_y, rect_width, rect_height, color(0, 0, 255))  # Blue circle

    x -= 1
    y -= 3

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.