Created
August 4, 2021 16:50
-
-
Save silkyland/057991dda22c6964120ee595b13977c9 to your computer and use it in GitHub Desktop.
[Dart Lang] Algorithm : แสดงผลรูปหัวใจ และ เลื่อนรูปหัวใจลงทีละ step
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
for (var i = 0; i <= 5; i++) { | |
show(i); | |
} | |
} | |
void show(int n) { | |
// กำหนด list ของจุดค่าเริ่มต้น | |
print("Step ที่ " + n.toString() + " : "); | |
var myList = [ | |
["*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*"], | |
["*", "*", "*", "*", "*", "#", "#", "#", "*", "*", "*", "*", "#", "#", "#", "*", "*", "*", "*", "*"], | |
["*", "*", "*", "*", "#", "#", "#", "#", "#", "*", "*", "#", "#", "#", "#", "#", "*", "*", "*", "*"], | |
["*", "*", "*", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "*", "*", "*"], | |
["*", "*", "*", "*", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "*", "*", "*", "*"], | |
["*", "*", "*", "*", "*", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "*", "*", "*", "*", "*"], | |
["*", "*", "*", "*", "*", "*", "#", "#", "#", "#", "#", "#", "#", "#", "*", "*", "*", "*", "*", "*"], | |
["*", "*", "*", "*", "*", "*", "*", "#", "#", "#", "#", "#", "#", "*", "*", "*", "*", "*", "*", "*"], | |
["*", "*", "*", "*", "*", "*", "*", "*", "#", "#", "#", "#", "*", "*", "*", "*", "*", "*", "*", "*"], | |
["*", "*", "*", "*", "*", "*", "*", "*", "*", "#", "#", "*", "*", "*", "*", "*", "*", "*", "*", "*"], | |
["*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*"], | |
["*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*"], | |
["*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*"], | |
]; | |
// กำหนดให้ข้อความเริ่มต้นเป็น "" | |
String txt = ""; | |
// เริ่มต้น i ด้วย 0 - n เช่น ถ้า n = 5 จะเริ่มต้นด้วย 0 - 5 = -5 | |
int i = 0 - n; | |
// กำหนดความยาวของของ list โดยนำความยาวทั้งหมดมาลบออกด้วย n เช่น 13-5 = 8 | |
int listLength = myList.length - n; | |
// ระหว่าง -5 ถึง 8 จะมีความยาวของ list คือ 13 เช่นเดิม | |
//เริ่มต้น loop จาก i ที่ 0 ถึง listLength - 1 | |
for (i; i < listLength; i++) { | |
for (var j = 0; j < myList[i % myList.length].length; j++) { | |
// บันทึกค่าแต่ละแถวใน txt | |
txt += myList[i % myList.length][j]; | |
} | |
// ขึ้นบรรทัดใหม่ | |
txt += "\n"; | |
} | |
// แสดงผลของ txt | |
print(txt); | |
// แสดงรหัสนักศึกษา | |
print("64112123 นายสมชาย ใจดี"); | |
print("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment