vendredi 10 février 2023

the power of Trigonometric functions!












اليوم اقدم برنامج يبين ما مدى اهمية الدوال الجيبية في محاكات حركة دوران عقرب الساعة مكتوب بلغة جافا , عدد اسطره لا يتجاوز 40 كما هو موضح ا


/* CLOCK */

PImage clock;
float rh,rm,rs;
float xh,yh,thetah;
float xm,ym,thetam;
float xs,ys,thetas;
void setup() {
size(600,600);
clock=loadImage("e:/processing/clock0.jpg");
rh = 80; rm = 120; rs = 160;
}
void draw() {
thetah = 2*PI*hour()/12-PI/2;
xh = rh* cos(thetah)+width/2; yh = rh* sin(thetah)+height/2;
thetam = 2*PI*minute()/(60)-PI/2;
xm = rm* cos(thetam)+width/2; ym = rm* sin(thetam)+height/2;
thetas = 2*PI*second()/(60)-PI/2;
xs = rs* cos(thetas)+width/2; ys = rs* sin(thetas)+height/2;
background(0);
image(clock,0,0);
textSize(20);
fill(0);
textAlign(CENTER);
text(hour()+":"+minute()+":"+second(),width/2,180);
stroke(0,0,255); strokeWeight(3);
line(width/2,height/2,xs,ys);
stroke(0,255,0); strokeWeight(5);
line(width/2,height/2,xm,ym);
stroke(255,0,0); strokeWeight(8);
line(width/2,height/2,xh,yh);
}