### XY model, Metropolis updating

$$S=K\sum_{\langle i,j\rangle} \cos(\theta_i-\theta_j)$$ where the $$\theta_i \in [0,2\pi)$$ is the orientation of local spin.

visulization of $$\theta_i$$:

1. arrows: simple and easy
2. color wheels: need some background theories about color [see below]

pseudo-code:

1. randomly find a site, and randomly change its state
2. compare with neighour, and find out the change: dS
3. Metropolisily accept or reject

color arrow
updating speed=6000 Coupking $$K$$=-200.0

### a short introduction to color theory

Red-Green-Blue system: light, used for TV or computer screen.

Cyan-Magenta-Yellow-(Key) system: printing on the paper, check your ink color.

Red-Yellow-Blue system: artists, painters. blending pigment.

since I'm using a computer screen, RGB color is my choice. However, it is not natural to draw a color wheel using RGB parameter. HSL or HSV is better.

Hue(色相) ranges from 0,1,2,3 to 359. Saturation(饱和度) and Light(亮度) can be set to 50%. $\text{hue}= \frac{\theta}{2\pi}\times 360$ the javascript syntax is: (don't forget the quotation marks)

context.fillStyle='hsl(220.7, 50%, 50%)';
context.fillStyle='hsl('+ 360*Math.random() +', 50%, 50%)';


references: color theory HSL and HSV
similar applets: 1 , 2