كلمات بالأمثلة
من كلِمَات
محتويات |
Statements
| اطبع "مرحبا"،1+2 | Print statement |
| اطبع "مرحبا"، …
اطبع " بكم" | Print both strings on the same line |
| اقرأ "ما اسمك؟"، س
اقرأ #س،#ص | - The read statement can have an optional message before the variables to be read
- The read statements always reads string values, except when putting a # symbol before the variable name - Variable in kalimat have no type declarations. the types are for values, not variables |
| إذا س>5 وأيضا س<20:
اطبع "القيمة سليمة" وإلا: اطبع "القيمة خطأ" تم
إذا ص<20 : اطبع "نعم" وإلا اطبع "لا"
إذا أ=ب: اطبع "متساويان" وإلا إذا أ >ب: اطبع أ، " هو الأكبر" وإلا: اطبع ب، " هو الأكبر" تم | If statements
س وأيضا ص => and س أو ص => or ليس س => not ليس س ولا ص => nor |
| اطبع 6=6
اطبع 5>10 | This will print صحيح, the 'true' boolean value.
This will print خطأ, the 'false' boolean value. |
| لكل أ من 1 إلى 12:
اطبع أ تابع | Traditional for loop
the range is inclusive, in this examples 1,2,3...12 will be printed |
| أ=1
طالما أ<= 12: اطبع أ أ = أ +1 تابع | While loop |
| إجراء اطبع.مجموع(س، ص):
اطبع س+ص نهاية
| Defining procedures
- Procedures return no values. - Parameters have no type declarations. - If the procedure takes no parameters and empty parameter list must still be supplied (like C). - A procedure definition can be at the beginning of a program, at its end or even at its middle. |
| دالة مجموع(س، ص):
ارجع ب: س+ص نهاية | Defining functions
Functions are like procedures, except they must return a value. |
| ارسم.خط (س1، ص1)- (س2،ص2)، اللون | The color is optional, it is a value from 0 to 15 of predefined colors |
| ارسم.مستطيل(س1، ص1)-(س2،ص2)، اللون، ملء | The color and fill are optional
the fill is صحيح or خطأ, meaning to draw the rectangle & fill it or just draw it |
| ارسم.دائرة(س، ص)، نصف.القطر، اللون،ملء | Again, color and fill are optional |
| ارسم.نقطة(س،س)، اللون | Again, color is optional |
| ط = حمل.طيف(“اسم الملف") | Load a sprite (moving image used e.g in games) from a picture file like .bmp or .png and store the sprite object in a variable |
| ارسم.طيف ط في (س،ص) | put the sprite on screen. a sprite can only exist in one location so drawing the same sprite in 2 different places erases the first one. also, a sprite does not destroy the background behind it |
| اخف.طيف(ط)
اظهر.طيف(ط) | Show and hide sprites |
| يمين.الطيف(ط)، يسار.الطيف(ط)، قمة.الطيف(ط)، قاع.الطيف(ط)، عرض.الطيف(ط)، ارتفاع.الطيف(ط) | Various functions to read the position and size of sprites. |
| فصيلة شخص:
له اسم، سن نهاية
اسم ن = “سمير" سن ن = 13
اطبع اسم $ ن اطبع سن $ ن | Define a class, create an instance and write and read its fields. Instead of obj.field like C++ we can use either
field obj or field $ obj I think not using the $ is more natural since it sounds like natural Arabic. |
Some built in functions
| م = مصفوفة(5)
ن = مصفوفة.متعددة([2،3]) اطبع عدد(م) م[1] = 5 ن[1،1] = “مرحبا" م = [1، 2، 3، 4] | - Create a single dimensional array
- Create a multidimensional array - Print the number of elements in a 1d array - Write an array element (arrays are one-based) - Write a 2d array element - Array values can be created by listing members between brackets. They can have values of mixed types. Note: like all variables, arrays have no type declarations, and its possible to put differently-typed values in the same array |
| عشوائي(50) | random number from 0 to n-1 |
| كعدد(“12”)
كنص(12) | Convert strings to numbers.
Convert numbers to strings. |
| س = “كلية الحاسبات"
اطبع طول(س) اطبع أول(س، 4) اطبع آخر(س، 8) اطبع وسط(س، 4، 1) م = تفصيص(“دجاجة بقرة اوزة") | - String length
- First n characters of a string - n characters last - mid(m, n) → middle n characters starting from position m, zero based - Returns an array of the individual words. |
| جا(س)
جتا(س) ظا(س) جذر(س) لو(س) لو.ه(س) باقي.قسمة(أ، ب) | Sin, cos, tan, square root, log10, ln, modulus. |
| انتظر (س)
امسح.الشاشة( ) امسح.الكتابة() حدد.مكان.المؤشر(الصف، العمود) الصف = سطر.المؤشر() العمود = عمود.المؤشر() حدد.لون.النص(اللون) | Wait for a number of milliseconds
Erase all drawing (but not sprites) Erase all text Set cursor position Get cursor line Get cursor column
|
Event handling
إجراء تعامل.مع.الماوس(س،ص):
اطبع "أنت ضغطت في"، س، "و"، ص
نهاية
عند حادثة ضغط.زر.ماوس نفذ تعامل.مع.الماوس
اطبع "اضغط بالماوس في أي مكان"
Types of events
ضغط.زر.ماوس
رفع.زر.ماوس
تحريك.ماوس
ضغط.مفتاح
رفع.مفتاح
ادخال.حرف
- Mouse events always take x,y values as parameters
- Keyboard events always take 2 parameters: an integer representing the key code (for the physical key itself, regardless of current input language) and a string representing the input character (depends on input language).
Sprite collision detection
ط1 = حمل.طيف("...")
ط2 = حمل.طيف("...")
ارسم.طيف ط2 في (400، 400)
عند حادثة تصادم نفذ الأطياف.اصطدموا
لكل أ من 300 إلى 450:
ارسم.طيف ط1 في (أ، 400)
تابع
إجراء الأطياف.اصطدموا(طيف1،طيف2):
اطبع "تصادم!"
نهاية
General notes
Entering Symbols on the Arabic keyboard:
- shift + خ = ×
- shift + هـ = ÷
- shift + ي = ]
- shift + ب = [
- shift + د = >
- shift + ج = <
Defining methods in classes
فصيلة نقطة:
له س، ص
يستجيب ل: ارسم()، حرك(س، ص)
يرد على المسافة.من(نقطة.اخرى)
نهاية
استجابة نقطة ن ل: ارسم():
ارسم.نقطة (س ن، ص ن)
نهاية
استجابة نقطة ت ل: حرك(س.الجديدة، ص.الجديدة):
س ت = س.الجديدة
ص ت = ص.الجديدة
نهاية
رد نقطة ن على المسافة.من(ن2):
فرق.س = س ن – س ن2
فرق.ص = ص ن – ص ن2
النتيجة = جذر(فرق.س×فرق.س + فرق.ص × فرق.ص)
ارجع ب: النتيجة
نهاية
ن1 = نقطة جديد
ن2 = نقطة جديد
س ن1 = 4
ص ن1 = 3
س ن2 = 1
ص ن2 = 1
ن1:ارسم()
ن2: حرك(0، 0)
اطبع ن1:المسافة.من(ن2)
Files
| م = انشيء.ملف("...”)
م = افتح.ملف(“...”) م = الحق.بملف(“...”) اغلق.ملف(م) نهاية.الملف(م) | Create an empty new file for writing
Open an existing file for reading Opens a file for writing from the end of the existing data. Closes the file. Returns true if at the end of the file (e.g all data has been read). |
| اطبع في م: “النتيجة"، س
اقرأ من م: س، ص | Print to an open file
Read from an open file |
| م: اكتب.سطر(“هذه هي البيانات")
م: اكتب(“وهذه أيضا") م: اكتب.بعرض(“وهذه"، 5) ب = م: اقرأ.سطر() ن = م: منته() |
Object-oriented file input/output. |
Units
| خزّن هذا الملف باسم myunit.k
وحدة الجمع دالة مجموع(أ، ب): ارجع ب: أ+ب نهاية | -The unit name is an identifier, not a string.
- The unit name is currently unused, but still mandatory (it could be used in future versions for namespacing). - Only definitions (procedures, functions, classes, global variables) could be included in a module, no statements. |
| باستخدام "myunit.k"
اطبع مجموع(12، 13) | - Units are used by their file name, not unit name.
-The file name is a string. - It is possible to use a unit multiple times or for units to include each other (possibly indirectly). |