jfrech.com
jblog
table of contents

Menger Sponge

2015-07-25, post № 49

programming, Pygame, Python, #black, #blue, #divide, #endless, #fractal, #infinite, #sponge

Normally, the Menger Sponge is a three-dimensional cuboid. This program works in a two-dimensional space, so it only shows one side of the sponge.
Because a computer has its capacities, I capped the maximum square count to 𝟣𝟢𝟢𝟢𝟢. After that maximum, the face will not be complete.

Controls

  • ‘Space’ divides every square once again.
menger-sponge-1.png
menger-sponge-2.png
menger-sponge-3.png
menger-sponge-4.png
menger-sponge-5.png
Source code: menger-sponge.py

Prime Spiral II

2015-07-19, post № 48

programming, Pygame, Python, #around the center, #black, #black and white, #circle, #curcular, #generates, #generator, #getCirclePos(), #gray, #prime, #primes, #spinning, #spiral

My first attempt at making a prime spiral worked, but it worked with 𝟫𝟢° angles. Trying to make it look smoother, I now used an angle and a distance, drawing circles at calculated position.
If the number is prime, it gets white. If it is not, the circle will be gray.

prime-spiral-ii.png
Source code: prime-spiral-ii.py

Sierpiński triangle

2015-07-18, post № 47

mathematics, programming, Pygame, Python, #3, #3-gon, #around the center, #black, #black and white, #fractal, #generates, #generating, #generator, #three, #triangle, #white

Having recently heard something about chaos theory, I was interested in the Sierpiński triangle. Specifically in the random generation. To prove that it can really be generated using a die, I wrote this program.

How it works

  • You start with any point inside the triangle (I chose the center).
  • A triangle has three points, let us call them 𝐴, 𝐵 and 𝐶.
  • You choose randomly between one of those three points, go half the distance and set a pixel right there.
  • Repeating this process over and over again (always starting at your last point), you eventually [1] get the Sierpiński triangle.

Controls

  • ‘Space’ toggles if the triangle is generated,
  • ‘m’ toggles if the current position is shown (indicated by a blue circle).
sierpinski-triangle-1.png
sierpinski-triangle-2.png
sierpinski-triangle-4.png
Source code: sierpinski-triangle.py

Jic-Jac-Joe

2015-07-12, post № 46

games, programming, Pygame, Python, #AI, #algorithm, #blue, #com, #computer, #pixel, #pixel graphics, #tac, #tic, #tic-tac-toe, #tictactoe, #toe, #TTT

As the name suggests, this is a computer version of the well-known game Tic-Tac-Toe. This version supports a computer player, but it is not the smartest algorithm and can lose. In this setup, the computer plays ‘O’ and starts, the player plays ‘X’.
Win detection is fully implemented.

Controls

  • The 𝟥 ⨉ 𝟥-field is projected on the numpad, so 7 sets your piece in the upper left corner and 3 puts it in the lower right corner.
  • Escape resets the game.
jic-jac-joe-1.png
jic-jac-joe-2.png
jic-jac-joe-3.png
Source code: jic-jac-joe.py

JClock III

2015-07-11, post № 45

programming, Pygame, Python, #7, #7-segment, #7 segments, #black, #clock, #current time, #green, #green and black, #numerals, #pixel, #pixels, #seven, #time

Inspired by a 7-segment clock I previously made a 7-segment font (used in Jong). I thought of an idea to make this simple way of displaying our ten numerals more interesting. I came up with this clock.
It uses a number of pixels, which get every second a new destination to the position that would form needed numeral. Because they always try to move to their destination — needing time to get there —, a reordering-effect occurs.

jclock-iii-3.png
jclock-iii-1.png
jclock-iii-2.png
Source code: jclock-iii.py

Gradient Drawer

2015-07-05, post № 44

art, programming, Pygame, Python, #around the center, #art, #artistic, #background, #black, #bright, #color, #color change, #colorful, #colors, #creating, #different colors, #draw, #drawing, #fancy, #gradient, #mouse, #neat, #pictures, #saving

This is more of an artistic program. By left-clicking you set a fix point and define a random color. Where you then move your mouse, the program will draw 𝟣𝟢𝟢 circles in between the fix point and the cursor position. By right-clicking you save those 𝟣𝟢𝟢 circles on the canvas. Holding the right mouse button is possible.

Controls

  • Left clicking sets or removes a fix point,
  • Right clicking saves current circles on canvas,
  • ‘s’ saves current canvas,
  • ‘c’ clears current canvas.
gradient-drawer-01.png
gradient-drawer-08.png
gradient-drawer-13.png
gradient-drawer-21.png
gradient-drawer-18.png
Source code: gradient-drawer.py

Circle Mover

2015-07-04, post № 43

programming, Pygame, Python, #angle, #angles, #around, #around the center, #entities, #entity, #getCirclePos(...), #red, #spinning, #turning

Playing around with angles and my getCirclePos() function, I came up with these little entities. They have a center, a distance to that center and an angle which constantly increases. Those parameters also randomly change.

circle-mover-1.png
circle-mover-3.png
circle-mover-4.png
Source code: circle-mover.py
Extra assets: circle-mover-2.png

Primes

2015-06-28, post № 42

mathematics, programming, Pygame, Python, #generates, #generator, #prime, #prime generator, #prime layout, #prime numbers, #prime pattern, #prime patterns, #primes, #red, #white

Being fascinated with how prime spirals look, I tried another layout for primes. Starting at the upper left and writing out numbers like a normal text, starting at 𝟢 and coloring every prime number red, every other number white, this is the result.

primes-8.png
primes-7.png
primes-10.png

It is interesting, that — like in prime spirals — the red squares form visible patterns. Randomly assigned squares would not as often form such patterns.

Source code: primes.py

Bubbletree

2015-06-27, post № 41

programming, Pygame, Python, #around, #bubbles, #circle, #colors, #fancy, #getCirclePos(), #gray, #gray tones, #red, #smoke

This program falls into the category ‘fancy, but not useful’. It basically starts with one circle, which spawns in new ones. The maximum number of circles is 𝟣𝟢𝟢, their color is a gray tone (rgb between 𝟧𝟢 and 𝟣𝟢𝟢).

bubbletree-1.png
bubbletree-3.png
bubbletree-5.png
Source code: bubbletree.py

FS Letters II

2015-06-21, post № 40

programming, Pygame, Python, #black, #dynamic, #file, #file check, #file system, #files, #filesystem, #fs, #red

Improving my first version — FS Letters — I changed a core behavior. Instead of going through the whole file system, saving it, interpreting it and then displaying it, I now went for a dynamic approach. As the filesystem gets checked (𝟨𝟢 times per second), the screen is also updating. This makes for both a more efficient (no freeze!) and a much nicer program. If the program is done checking the file system, the text ‘done’ will appear in the screen’s caption.

fs-letters-ii-1.png
fs-letters-ii-2.png
fs-letters-ii-4.png
Source code: fs-letters-ii.py
Extra assets: fs-letters-ii-3.png

Jake

2015-06-20, post № 39

games, programming, Pygame, Python, #apples, #simple, #simple snake, #snake, #snake game, #snakes, #video game

Continuing to clone famous and fairly easy games, I now made my own version of Snake.
In this version you cannot leave the screen, there are never more than three apples on the screen and there are no blocks inside the field.
Your current score is displayed in the screen caption.
To get more information about Snake, check this Wikipedia entry.

Controls

  • Arrow keys move the snake,
  • Escape pauses and unpauses the game,
  • ‘r’ resets the game.
jake-1.png
jake-2.png
jake-4.png
Source code: jake.py
Extra assets: jake-3.png