hp
toc

Graph sim

2015-05-17, post № 29

programming, Pygame, Python, #bar, #bar graph, #bars, #color, #color change, #colors, #different colors, #generates, #generator, #graph, #pseudo random, #random, #WolframAlpha

Thinking of graphs — especially bar graphs — as a pretty piece of art I wanted to create something related. But due to me not having any data I could graph, I decided to just use randomly generated data. It has no real purpose rather than look good.

graph-sim-1.png
graph-sim-2.png
graph-sim-3.png

Some calculations

  • All of these calculations are based on random.randint() being perfectly random. Due to it being pseudo-random this will just be an approximation. To get further information, click on the equation to view them in Wolfram Alpha.
  • The chance of two adjacent bars having the same color:
  • \Big(\big(\frac{1}{256}\big)^3\Big)^{2-1}=5.96\cdot 10^{-8}=\text{basically }0
  • The chance of two adjacent bars having the same color and size, where
  • \text{max. size}=\text{window height}=720:
  • \Big(\big(\frac{1}{256}\big)^3\cdot\frac{1}{720}\Big)^{2-1}=8.28\cdot 10^{-11}=\text{basically }0
  • The chance of the screen not showing anything, which means every bar has the background color and
  • \text{max. quantity of bars on screen}=\frac{\text{window height}}{\text{bar width}}=\frac{720}{4}=180:
  • \Big(\big(\frac{1}{256}\big)^3\Big)^{180}=3.55\cdot 10^{-1301}=\text{basically }0.0
  • Although these probabilities are very unlikely, they — theoretically — could occur.
Source code: graph-sim.py
Jonathan Frech's blog; built 2024/04/13 20:55:09 CEST