sai sandeep :
walker w;
void setup(){
size(800,600);
w=new walker();
background(255);
}
void draw(){
w.step();
w.render();
}
class walker{
int x,y;
walker(){
x=width/2;
y=height/2;
}
void render(){
stroke(0);
point(x,y);
}
void step(){
int choice = int(random(4));
if (choice==0){
x++;
} else if(choice==2){
y++;
} else if (choice==1){
x--;
}else{
y--;
}
x=constrain(x,0,width-1);
y=constrain(y,0,height-1);
}
}
how to convert this java code into python . this code is random walk algorthim and how to convert this code to python. this is done on processing editor. can anyone please covert this code
Rabbid76 :
One way to convert it is to employ someone to do the conversion work for you.
I feel employed:
def setup ():
global w
size(800, 600)
w = walker()
background(255)
def draw ():
w.step()
w.render()
class walker:
def __init__(self):
self.x = width // 2
self.y = height // 2
def render(self):
stroke(0);
point(self.x, self.y);
def step(self):
choice = int(random(4))
if choice == 0:
self.x += 1
elif choice == 2:
self.y += 1
elif choice == 1:
self.x -= 1
else:
self.y -= 1
self.x = constrain(self.x, 0, width-1);
self.y = constrain(self.y, 0, height-1);
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=349146&siteId=1