/* Bak-Tang-Wiesenfeld sandpile animation (version 2.02 - Windows)
 *
 * Copyright (C) 2005 N.R. Moloney 
 *
 * Distributed under the Qt Non-Commercial license version 1.0
 */

#ifndef BTW_H
#define BTW_H

#include <qlcdnumber.h>
#include <qwidget.h>

const int L = 149;
const unsigned int pixel = 4;

const int boxWidth = 160;
const int boxHeight = 100;
const int leftAlign = 20;
const int offsetx = 200;

const int RUN_FREE = 0;
const int MANUAL_SPRINKLE = 1;
const int FRACTALSAND0 = 2;
const int FRACTALSAND1 = 3;
const int FRACTALSAND2 = 4;

const int FAST = 0;
const int SLOW = 1;
const int PAUSE = 2;

class Sandpile : public QWidget
{
  Q_OBJECT

 public:

  Sandpile( QWidget * parent = 0, const char * name = 0 );
  
  int * h;
  int * toppling;
  int * newToppling;
  int * redraw;
  int numToppling;

  int hits, s, sMax;
  
  int targetSite;
  int mode;
  bool burn,display;
  int speed;

  QLCDNumber * grainsLCD;
  QLCDNumber * slopeLCD;
  QLCDNumber * sLCD;
  QLCDNumber * largestLCD;

  void initialiseLattice();
  void relax();
  void burnEdges();

 public slots:

  void slotRunningStyle( int index );
  void slotBurn( bool toggle );
  void slotDisplay( bool toggle );
  void slotSpeed( int S );
  void slotStartAgain();

 protected:

  void paintEvent( QPaintEvent * );
  void mousePressEvent( QMouseEvent * );

 private slots:   

  void sprinkle();
  void update();

};


#endif 
