int wide=270, high=75; float batt=225; //PERCENT TAB LENGTH float percentB; //PERCENT int dx=1; //DIRECTION OF PERCENT TAB -> '1' + , '0' - void setup() { size(350, 250); } void draw() { int x=70; int y=110; String status; background(51); strokeWeight(4); stroke(0); // make battery charge/uncharge if (dx==1) { batt++; if (batt>225)batt=225; } if (dx==0) { batt--; if (batt<=0)batt=0; } percentB=batt/225*100; //Drawing draw_battery(x, y, wide, high); //INDICATE COLOR AND STATUS TEXT status="OK"; if (percentB<=100) { fill(#3BC149); status="OK"; if (percentB<=80) { fill(#95FF03); status="Below 80%"; if (percentB<=50) { fill(255, 0, 0); status="Please Charge"; } } } //DRAW PERCENTAB rect(x+(wide/12), y, batt, high); textSize(30); text(int(percentB) + "% " + status, x, y-30); //PERCENT TEXT //DRAW + AND - SIGNS positive_sign(x+0.1*wide, y+0.4*high, 5); negative_sign(x+0.8*wide, y+0.4*high, 5); } void mousePressed() { if (mouseButton==LEFT) { dx=1; } else { dx=0; } } void draw_battery(int posX, int posY, int wide, int high) { fill(255); //HEAD rect(posX, posY+(0.2*high), wide/12, high*3/5); //Body Battery rect(posX+(wide/12), posY, wide*5/6, high); } void positive_sign(float x, float y, int sizebox) { noStroke(); fill(51, 0, 0); rect(x+sizebox, y, sizebox, sizebox); rect(x+2*sizebox, y+sizebox, sizebox, sizebox); rect(x+sizebox, y+sizebox, sizebox, sizebox); rect(x+sizebox, y+2*sizebox, sizebox, sizebox); rect(x, y+sizebox, sizebox, sizebox); } void negative_sign(float x, float y, int sizebox) { noStroke(); fill(51, 0, 0); rect(x+2*sizebox, y+sizebox, sizebox, sizebox); rect(x+sizebox, y+sizebox, sizebox, sizebox); rect(x, y+sizebox, sizebox, sizebox); }
วันอาทิตย์ที่ 30 สิงหาคม พ.ศ. 2558
Lab03 : Battery Charge/Uncharge
สมัครสมาชิก:
ส่งความคิดเห็น (Atom)
commit เพิ่มเติม : เพื่ม userstory, bookmark
>> add userstory ทำการเพิ่ม userstory ใน functional tests >> add bookmark for user เพิ่มระบบ Bookmark โดยการสร้าง model ขึ...
-
1 2 3 4 5 6 7 8 9 def setup (): print (d2b( 8 )) def d2b (num): x = "" while num > 0 : x = str ( int (n...
-
1 2 3 4 5 6 7 8 9 10 11 12 13 def test_layout_and_styling ( self ): # Edith goes to the home page self . brow...
-
การใช้ template inheritence คือการสืบทอดเทมเพลต เพื่อให้ไม่ต้องเขียนโค้ดหน้าเว็บๆซ้ำๆ เราจะมีหน้าหลักอันเดียว (base.html or parent) ภายในนั...
ไม่มีความคิดเห็น:
แสดงความคิดเห็น