/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.PnRL3HuP3Uo/rev.2226
*
* authors:
* Sayantan Chaudhuri
* Joy Bhattacherjee
* Joy
*
*
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
Machh m1;
void setup() { //RUNS ONLY ONCE
size(300, 500); //sets the size, as well as height and width vars
frameRate(30);
smooth(); //antialiasing
randomSeed(5310);
fill(0);
stroke(0);
m1 = new Machh(width/2, height/2, 0);
}
void draw() { //RUNS EVERY FRAME
//draws
fill(255, 10);
rect(0, 0, width, height);
m1.draw();
//updates
m1.update();
}
void mousePressed() {
setup();
}
class Machh {
float r; //radius, not used
float x, y;
float dx, dy;
float d; //direction, polar and in radians (processing has PI const)
float m; //magnitude of the vector
int f;
Machh(float _x, float _y, float _d){
r=10;
x=_x;
y=_y;
dx=0;
dy=0;
m=0;
}
//ebar, vector bishleshon!
void update() {
_move();
_loop();
}
//ebong drawing
void draw() {
pushMatrix();
//pushStyle();
fill(0);
noStroke();
translate(x, y);
rotate(d);
triangle(r, 0, -r, r, -r, -r);
//popStyle;
popMatrix();
}
void _polToCart(){
dx=cos(d)*m;
dy=sin(d)*m;
}
void _cartToPol(){
d=atan( ((mouseY-y)/(mouseX-x)));
if(mouseX-x < 0)
d-=PI;
}
void _move() {
x+=(mouseX-x)/50;
y+=(mouseY-y)/50;
_cartToPol();
}
void _loop() {
if (x > width+r) x=-r/2;
else if (x < -r) x=width+r/2;
if (y > height+r)y=-r/2;
else if (y < -r) y=height+r/2;
}
}