Showing posts with label Game. Show all posts
Showing posts with label Game. Show all posts

Tuesday, November 4, 2014

Tic-Tac-Toe (井字遊戲)



Let f(a,b,x,y) = 1/exp(1/(a² - x²)²) + 1/exp(1/(a² - y²)²) - b

Equations:

Blue grid (#) ..... f(2, 0.999, x, y) = 0
Green nought (o) ..... f(0.125, 0.85, x, y) = 0
Red cross (x) ..... f(0.125, 0.999, 2(y+x), 2(y-x)) = 0


(Tessellations)


When the parameter 'a' changes from 0 to 2, the graph
changes shape from a plus sign(+) to a number sign(#).


In order to avoid discontinuities, we redefine f as follows:
f(a,b,x,y) = 1/exp(1/(s + (a² - x²)²)) + 1/exp(1/(s + (a² - y²)²)) - b,
where s(=0.001) is a small positive number.


Graph example:
  • Click here to download the example file (tic_tac_toe.zip).


( Mathematical software used: Graph )

Sunday, September 30, 2012

Gnuplot example: Math Invaders - Remember Space Invaders and Galaxian?



This is a parameter animation (plotted upside down) for the modified Thomae function:



gnuplot script:

d = 0.001
m = 250
f(n,k,x) = k > m ? 3.2 : ( abs(k*x - int(k*x)) < d ? \
3.2-(1+0.1*n*n)/(k*k-abs(k*x)) : f(n,k+1,x) )
set xrange [-1.6:1.6]
set yrange [0:3.2]
set size ratio -1
set samples 10000
unset key
unset xtics
unset ytics
unset border
set bmargin 0
set lmargin 0
set rmargin 0
set tmargin 0
set term gif size 400, 400 animate background rgb "black"
set output "C:\math_invaders.gif"
set pointsize 0.5
do for [i=0:150]{
  plot f(i,1,sin(x)) with points pt 11 lc rgb "white"
}
set output


Note that we set less samples(10000). By incresing samples to 200000,
we can obtain a more accurate (but less fun) picture.



( Mathematical software used: gnuplot )


Related posts: