Critique my code!

I’ve just started working on my first coding for the eyesy, largely cobbled together from watching a couple of youtube videos.

It is very simple, and seems to work (yay!) but I don’t really know what some of the code is actually doing.

In essence, I have some circles moving across the screen to form a sine wave. I can change the colour and width of this wave.

What I want to be able to do, is to slow down the speed at which the balls are moving, and to change the number of balls on screen. Any idea how I might do this?

Would anyone be able to look at my code and tell me what the different parts are actually doing?


import pygame
import random
import time
import math

def setup(screen, etc):

def draw(screen, etc):

color_bg = etc.color_picker_bg(etc.knob5)
color = etc.color_picker(etc.knob4)

for i in range(720):

    radius = int(etc.knob1 * 50)
    x = int(1280 / 2 + etc.knob2 * 640 * math.sin(i * etc.knob3 / 2 + time.time()))
    pygame.gfxdraw.filled_circle(screen, x, i, radius, color)

Oh, well. Was worth asking.

Not an Eyesy or Python guy (C++/Java) but I will take shot since no one else will:

In the existing code:
Knob 5 Sets the Background colour
Knob 4 Sets the Foreground colour
Knob 3 and Knob 2 Set values in the equation that determines the X (horizontal) coordinate for the center of each circle (so effects the width of the wave) I did not try to work out what the equation is doing, but it looks like Knob 2 is some kind of offset and Knob 3 affects spacing (perhaps?)
Knob 1 sets the radius of the circles.

The equation (the line that starts with "x = ") is the part that would affect the apparent horizontal movement, since it is determining where the circle appear from horizontally.
I think you want to modify or replace this code to make the kind of changes you are interested in.

Hope this helps. Sorry I can’t make specific suggestions, but it has been a long time since I worked on this kind of code.


Thanks, John - that’s a very helpful starting point for me :slight_smile: