jblog
toc

Rand pix

2015-04-11, post № 17

programming, Pygame, Python, #background, #beautiful, #black, #change, #changing, #colro, #color change, #colors, #different colors, #fancy, #generates, #gradient, #movement, #moving, #random, #randomly, #snake, #snakes, #walk, #walking, #wallpaper

This program generates a snake of pixels which is randomly moving across the screen. If it leaves the screen, it (as in snakes) gets out the other side. It is also restricted to a length of 𝟣𝟢𝟢𝟢 pixels. As in ‘Colors V’ there are other ways the snake can look, based on the code used (I may post another color variant in the future).

rand-pix-2.png
rand-pix-3.png
rand-pix-5.png
Source code: rand-pix.py

Hangman

2015-04-10, post № 16

games, programming, Python, #ASCII, #based on terminal, #based on text, #black, #black and white, #game, #guess, #guessing, #guessing game, #hangman, #on terminal, #playable on terminal, #terminal, #terminal game, #terminal output, #text, #text-based, #words

On a recent train ride I made a little Python program to play Hangman.
My version has 7 stages (you could implement more by changing the STAGES variable) and is at best playable if you have someone else who gives you a word (you can also type ‘r’ for a random word, but the list of random words is not very long).

hangman-1.png
hangman-2.png
hangman-3.png
Source code: hangman.py

𝜑 generator

2015-04-09, post № 15

mathematics, programming, Python, #Fibonacci, #generates, #generator, #golden ratio, #𝜑, #phi, #ratio, #simulation, #terminal, #the golden ratio

This program generates 𝜑, also called the golden ratio. It creates the fibonacci sequence \big\{1,1,2,3,5,8,13,\dots\big\} and divides the newly generated number by the last one. In theory this program would generate exactly [1] 𝜑.

phi-generator.png

Fibonacci sequence

  • \text{Start: }x_1=1\text{ and }x_2=1
  • \text{Generation: }x_n=x_{n-1}+x_{n-2}
  • 1+1=2
  • 1+2=3
  • 2+3=5
  • 3+5=8
  • 5+8=13
  • 8+13=\dots

The golden ratio (𝜑)

  • \phi\text{ is the ratio between }x_n\text{ and }x_{n-1}\text{.}
  • \phi=\frac{x_n}{x_{n-1}}
Source code: phi-generator.py
Jonathan Frech's blog; built 2021/04/16 20:21:20 CEST