تمرين: الشرائح
تمرين: الشرائح
نفّذ Pic. ينبغي أن تُعيد شريحة طولها dy، كل عنصر فيها شريحة من dx عدد صحيح غير موقّع بحجم 8 بت. عندما تشغّل البرنامج، سيعرض صورتك، مفسّرًا الأعداد الصحيحة على أنها قيم تدرّج رمادي (حسنًا، تدرّج أزرق).
اختيار الصورة متروك لك. من الدوال المثيرة للاهتمام (x+y)/2، وx*y، وx^y.
(تحتاج إلى استخدام حلقة لتخصيص ذاكرة لكل []uint8 داخل [][]uint8.)
(استخدم uint8(intValue) للتحويل بين الأنواع.)
النص الأصلي بالإنجليزية
Exercise: Slices
Implement Pic. It should return a slice of length dy, each element of which is a slice of dx 8-bit unsigned integers. When you run the program, it will display your picture, interpreting the integers as grayscale (well, bluescale) values.
The choice of image is up to you. Interesting functions include (x+y)/2, x*y, and x^y.
(You need to use a loop to allocate each []uint8 inside the [][]uint8.)
(Use uint8(intValue) to convert between types.)
هذا الدرس للقراءة فقط؛ جرّب المثال في الدرس التالي.