# Need to know how to make a draggable Tower of Hanoi game for a school project

Hi, I have a school project about to make a Tower of Hanoi game, I’ve made all the rings and stuff, but I have very little knowledge about dragging and other interaction options in Processing. I haven’t finished, but here is the rings. I’m not sure how to make the rings draggable.

``````int x = 100;

// represent the disks in each tower
int[] tower1 = {4, 3, 2, 1};
int[] tower2 = {0, 0, 0, 0};
int[] tower3 = {8, 0, 0, 0};
float r, g, b;
void setup() {
size(600, 400);
rectMode(CENTER);
r = random(0, 256);
g = random(0, 256);
b= random(0, 256);
}
void draw() {
background(255);
fill(r, g, b);
//rect(400, 350, 166, 20);
int y = 350;
int yTwo = 350;
int sizeTwo = 166;

y = 350;
// write a loop to loop 4 times
for (int i = 0; i<tower1.length; i++) {
int size = tower1[i] * 40;
rect(x, y, size, 20, 7);
y -= 50;
r=random(0, 256);
g=random(0, 256);
b =random(0, 256);
}

y = 350;
for (int i = 0; i<tower2.length; i++) {
int size = tower2[i] * 40;
rect(270, y, size, 20, 7);
y -= 50;
r=random(0, 256);
g=random(0, 256);
b =random(0, 256);
}

for (int u=0; u< tower3.length; u++) {
}
}
``````
1 Like

Example of a thing you can drag:

``````float x,y;
boolean held;

void setup(){
size(900,300);
x = 150;
y = 150;
held = false;
}

void draw(){
background(0);
if(!held){
x = lerp(x,(x<300)?(150):((x>600)?(750):(450)),.6);
y = lerp(y,150,.6);
}
fill(64);
ellipse(150,150,20,20);
ellipse(450,150,20,20);
ellipse(750,150,20,20);

fill(128);
if( over() ){ fill(200); }
ellipse(x,y,100,100);
}

boolean over(){
return(dist(x,y,mouseX,mouseY) < 50);
}

void mousePressed(){
if( !held && over() ){
held = true;
}
}

void mouseDragged(){
if( held ){
x+=mouseX-pmouseX;
y+=mouseY-pmouseY;
}
}

void mouseReleased(){
held = false;
}
``````
1 Like

Thank you, this helped me a lot!

1 Like

…and the documentation for `mouseDragged()`: