Cycloids

A cycloid is the curve generated by tracing a point on a smaller circle rolling around an bigger circle.
The word cycloid comes from the greek word κύκλος meaning circle. There are epicycloids and hypocycloids (smaller circle located above and beneath the bigger circle).
The cycloid is determined by the ratio between the two circle’s radii k = \frac{R}{r}.
More information can be found on this Wikipedia entry.

Hypocycloid with k = 2.1 Hypocycloid with k = 2.1 Hypocycloid with k = 7.2


# Python 2.7.7 Code
# Pygame 1.9.1 (for Python 2.7.7)
# Jonathan Frech 3rd of June, 2016
#         edited 4th of June, 2016

Continue reading

π Approximation

Using an infinite series shown by Euler, π can be approximated.
The series goes as follows: \sum\limits_{n=1}^{\infty} \frac{1}{n^2} = \frac{1}{1^2} + \frac{1}{2^2} + \frac{1}{3^2} + \frac{1}{4^2} + \dots = \frac{\pi^2}{6}
By rearranging the equation, you get the following: \pi = \sqrt{6\cdot\big(\frac{1}{1^2} + \frac{1}{2^2} + \frac{1}{3^2} + \frac{1}{4^2} + \dots\big)}

Approximating π...


# Python 2.7.7 Code
# Jonathan Frech 14th of December, 2015

Continue reading

Pygame Bug

Tinkering around with circles and colors, I created a program which creates interesting images, both with pygame.draw.circle() (left) and pygame.gfxdraw.circle() (right). (Both images at 400×400 pixels)

pygame.draw.circle() pygame.gfxdraw.circle()
To get a smoother and nicer result, I tried using the pygame.gfxdraw.aacircle() function, which draws antialiased circles.

pygame.gfxdraw.aacircle()
As expected, the antialiased function gets rid of the black spots between the colored circles.

Wanting a higher resolution, I used the same code on a 1000×1000 pixel wide surface.

img4 (1000x1000;aagfx)
Again, it is a smooth and neat result. But as I got higher and higher resolutions, I got this interesting result. (At 3000×3000 pixels)

img7 (3000x3000;aagfx)
To make sure, the problem is on pygame.gfxdraw.aacircle()’s side, I created images of equal size with both pygame.draw.circle() (left) and pygame.gfxdraw.circle() (right). (Both images again at 3000×3000 pixels)

To ensure, the problem is not on my Operating System’s side, I used the exact same code on Mac OSX, Debian Linux and Windows 7 and 8.1 and got the same result each time.

img9 (3000x3000;draw) pygame.gfxdraw.circle()
At last, I used all three functions at 4000×4000 pixels. (pygame.draw.circle() on the left, pygame.gfxdraw.cirlce() on the right and pygame.gfxdraw.aacircle() on the bottom)

pygame.draw.circle() pygame.gfxdraw.circle() pygame.gfxdraw.aacircle()


# Python 2.7.7 Code
# Pygame 1.9.1 (for Python 2.7.7)
# Jonathan Frech 19th of August,    2015
#         edited 20th of August,    2015
#         edited 21st of August,    2015
#         edited  5th of September, 2015
#         edited 26th of September, 2015

Continue reading