วันจันทร์ที่ 27 กรกฎาคม พ.ศ. 2558

Workshop Raspberrypi 27 - 28 July 2015

27 Luly 2015

   เรียนการใช้โปรแกรม Scratch


   Picture&Code การเปลี่ยน Background ทุกๆ 1 วินาที จำนวน 10 ครั้ง


   Picture&Code ในการ move ตัวละครไปข้างหน้า 100 เมื่อกดรูปธงเขียว และ ให้ตัวละครพูดทีละคำ 
   จาก array ทุกๆ 5 วินาที












28 July 2015
   จากที่ได้เข้าร่วมศึกษาในวันนี้ได้มีการใช้โปรแกรม Wolfram Mathematica ในตัวของ raspberry pi  ใน    การเขียนโค๊ชโดยมีแบบฝึกหัดที่ผู้จัดทำได้ให้ไว้ ก็มีการศึกษาด้านคณิตศาสตร์ เลขาคณิต และ และ      การคำนวณต่างๆในด้วยการเขียนโค้ช โปรแกรมจะดึงคำสั่งต่างๆ มาจาก internet








======================================================


 เรียนเกี่ยวกับ ภาษา Phython 3
เข้าแถบเมนู Raspberrypi  และเลือก แถบเมนู อันที่3


เรียนเกี่ยวกับส่วนประกอบของCode







ตัวอย่างเช่น  a = "abcde"
                       print (a)
                       b   =  13
                       c   =  'q'
                       str (b)
                       print  (b+'num')
กดเข้าไปในโปรแกรม Run โปรแกรมจะให้save file และโปรแกรมจะrun ค่าออกมา   ในตัวอย่างนี้คือ ชนิดString   


การแปลง int เป็น String  จะมีฟังก์ชัน อยู่แล้วเช่น
 
                       a = "abcde"
                       print (a)
                       b   =  13
                       c   =  'q'
                       str (b)
                       print  (b+'num')



เงื่อนไข
ตัวอย่าง เงื่อนไข if
                      i = 3
                      if i < 5 ;
                                        print ( 'hello world')
                      elif i > 5;
                                        print  ('hi')
                      else;
                                        print ('i = 5')

ตัวอย่าง Loop
while loop  (ถ้าเป็นจริงทำต่อไปเรื่อยๆถ้าเป็นเท็จออกจากLoop)
                        i = 1
                                               while ( i < 5 ) ;
                                                       i = i+1
                                                       print ("asd")
output  ที่ได้ คือ asd 4ครั้ง

forloop   (แตกต่างจาก java หรือprocessing แต่ในโปรแกรมนี้จะเป็นการวนเข้าไปใน array ในแต่ละตัวจนกว่าจะครบ)

                                                        q = [1,2,3,4,5]

                                                        for  a in q;
                                                                           print (str(a))

output ที่ได้คือ 1 2 3 4 5




                                                        q = "abcde"
                                                        for  a in q;
                                                                           print (a)


 output ที่ได้คือ a b c d e



                                                       

                                                        for  a in range(100);
                                                                           print (str(a))
output  ที่ได้คือ 1->100

===========================================
บทเรียน Phyton

คำสั่งพื้นฐาน
ตัวอย่าง
from  mcpi import minecrarf
mc = minecraft.Minecraft.create()
x,y,z = mc.player.getPos()
print (str(x))
print (str(y))
print (str(z))


 พอสั่ง print จะขึ้นตำแหน่งของตัวละคร   และเช็คตำแหน่ง ID คำสั่งสร้างบล๊อกในเกมส์ว่าอยู่ตำแหน่งที่เท่าไหร่
คำสั่ง การสร้างบล็อก
    ในเกม  minecraft จะมีการสร้างบล็อกชนิดต่างๆเพื่อการใช้งาน ในที่นี้จะสร้างบล็อกจากคำสั่งใน python
 mc.setBlocks(x ,y ,z ,id)
จะมีการส่งค่าแกน x ,y ,z เพื่อทำการบอกตำแหน่งของบล็อกที่จะสร้าง และสามารถกำหนดชนิดของบล็อกได้ด้วยการส่งค่า ไปในพารามิเตอร์ id โดย id ของบล็อกต่างๆสามารถดูได้จาก www.raspberrypi-spy.co.uk/2014/09/raspberry-pi-minecraft-block-id-number-reference/
ตัวอย่างการสร้างบล๊อก
from  mcpi import minecrarf
mc = minecraft.Minecraft.create()
x,y,z = mc.player.getPos()
ma.setblock (x , y+3 , z , 2( จุดนี้คือจุด ID หรือชนิดบล๊อก  ))
ขั้นตอนนี้จะยังสร้างได้แค่บล๊อกเดียว หรือ มีดินในตัวเกมส์เพิ่มขึ้นมา 1 อัน


from  mcpi import minecrarf
mc = minecraft.Minecraft.create()
x,y,z = mc.player.getPos()
ma.setblock (x , y+3 , z , x , y+10 , z+10 , 46 ( จุดนี้คือจุด ID หรือชนิดบล๊อก  ))


การระบุหรือดูdata ของ ID
 www.stuffaboutcode.com/p/minecraft-api-reference.html
mc.setBlock(x ,y ,z ,id ,data)

from  mcpi import minecrarf
mc = minecraft.Minecraft.create()
x,y,z = mc.player.getPos()
ma.setblock (x , y+3 , z , x , y+10 , z+10 , 46 ( จุดนี้คือจุด ID หรือชนิดบล๊อก  ), 1 (จุดนี้คือจุดดาต้า))
if   id == 2;
ma.setBlock(x,y-1,z,46,1)


ทั้งหมดนี้คือตัวอย่างการประยุกต์ใช้ โปรแกรมpython 3 ใน raspberry pi








วันพฤหัสบดีที่ 23 กรกฎาคม พ.ศ. 2558

Soccer variable x,y,w,h (line&ellipse not rect)

VERSION 7
i can expand the soccer picture in x-plane,y-plane (used line&ellipse not rect)











ใน VERSION 7 ได้มีการสร้างตัวแปร w และ ตัวแปร h เพื่อใช้ในการขยายภาพในแกน x และแกน y (used line&ellipse not rect)

void setup() {
       size(800, 800);
       stroke(0);
       background(255, 255, 255);
       
        int x=300;
        int y=300;
        int w=0;//40
        int h=0;//100
        
      
       line(x-w,y-h,x+150+w,y-h);
       line(x-w,y+140+h,x+150+w,y+140+h);
       line(x-w,y-h,x-w,y+140+h);
       line(x+150+w,y-h,x+150+w,y+140+h);
       
       
       
       
       
       ellipse(x+75, y+70, 10+w, 10+h);
       line(x-w,y+70,x+150+w,y+70);
       
       
      
       
       
       stroke(126);
       
     } 


Spoon&Fox variable x,y,w,h (line&ellipse not rect)

VERSION 6
i can expand the spoon and fox picture in x-plane,y-plane (used line&ellipse not rect)











ใน VERSION 6 ได้มีการสร้างตัวแปร w และ ตัวแปร h เพื่อใช้ในการขยายภาพในแกน x และแกน y (used line&ellipse not rect)

void setup() {
       size(800, 800);
       stroke(0);
       background(255, 255, 255);
       
        int x=300;
        int y=300;
        int w=0;//40
        int h=100;//100
        
       //rect(x-w,y, 20+w+w,130+h);
       line(x-5-w,y+20,x+25+w,y+20);
       line(x-5-w,y+140+h,x+25+w,y+140+h);
       line(x-5-w,y+20,x-5-w,y+140+h);
       line(x+25+w,y+20,x+25+w,y+140+h);
       
       ellipse(x+10, y-60-(h/2), 70+w, 90+h);
       
       
       line(x+145-w,y+20,x+175+w,y+20);
       line(x+145-w,y+140+h,x+175+w,y+140+h);
       line(x+145-w,y+20,x+145-w,y+140+h);
       line(x+175+w,y+20,x+175+w,y+140+h);
       
       line(x+130-w,y-10,x+190+w,y-10);
       line(x+130-w,y-10,x+130-w,y-100-(h)+10);
       line(x+160,y-10,x+160,y-100-(h)+10);
       line(x+190+w,y-10,x+190+w,y-100-(h)+10);
       
       
       
       stroke(126);
       
     } 

วันพุธที่ 22 กรกฎาคม พ.ศ. 2558

Soccer variable x,y,w,h

VERSION 6
i can expand the star picture in x-plane,y-plane by add variable w,h for expand.










ใน VERSION 6 ได้มีการสร้างตัวแปร w และ ตัวแปร h เพื่อใช้ในการขยายภาพในแกน x และแกน y 

void setup() {
       size(800, 800);
       stroke(0);
       background(255, 255, 255);
       
        int x=100;
        int y=300;
        int w=0;//100
        int h=100;//200
        
       rect(x-w,y-h, 300+w+w,300+h+h);
       ellipse(x+150, y+150,20+(w/2),20+h);
       
       line(x-w,y+150,x+300+w,y+150);
       
       line(x+130-(w/2),y-h,x+130-(w/2),y+20);
       line(x+170+(w/2),y-h,x+170+(w/2),y+20);
       line(x+130-(w/2),y+20,x+170+(w/2),y+20);
       
       line(x+130-(w/2),y+300+h,x+130-(w/2),y+280);
       line(x+170+(w/2),y+300+h,x+170+(w/2),y+280);
       line(x+130-(w/2),y+280,x+170+(w/2),y+280);
       
       
       
       
       stroke(126);
       
     } 


Spoon&Fox variable x,y,w,h

VERSION 5
i can expand the spoon and fox picture in x-plane,y-plane by add variable w,h for expand.










ใน VERSION 5  ได้มีการสร้างตัวแปร w และ ตัวแปร h เพื่อใช้ในการขยายภาพในแกน x และแกน y 

void setup() {
       size(800, 800);
       stroke(0);
       background(255, 255, 255);
       
        int x=200;
        int y=300;
        int w=0;//50
        int h=0;//25
        
       rect(x-w,y, 20+w+w,130+h);
       ellipse(x+10, y-60, 70+w, 90+h);
       
       
       rect(x+150-w,y, 20+w+w,130+h);
       line(x+130-w,y-10,x+190+w,y-10);
       line(x+130-w,y-10,x+130-w,y-100-(h/2)+10);
       line(x+160,y-10,x+160,y-90-(h/2));
       line(x+190+w,y-10,x+190+w,y-90-(h/2));
       
       
       
       stroke(126);
       

     } 


Star variable x,y,w,h

VERSION 4
i can expand the star picture in x-plane,y-plane by add variable w,h for expand.












ใน VERSION 4  ได้มีการสร้างตัวแปร w และ ตัวแปร h เพื่อใช้ในการขยายภาพในแกน x และแกน y 

void setup() {
       size(800, 800);
       stroke(0);
       background(255, 255, 255);
     
        int x=200;
        int y=300;
        int w=0;
        int h=0;
 
     
 
     
       line(x-w,y-h,x+100,y-h);
       line(x+100,y-h,x+200,y-100-h);
       line(x+200,y-100-h,x+300,y-h);
       line(x+300,y-h,x+400+w,y-h);
       line(x+400+w,y-h,x+300+w,y+100);
       line(x-w,y-h,x+100-w,y+100);
       line(x+100-w,y+100,x-w,y+200+h);
       line(x-w,y+200+h,x+200,y+100+h);
       line(x+200,y+100+h,x+400+w,y+200+h);
       line(x+400+w,y+200+h,x+300+w,y+100);
       stroke(126);
     
     }

วันพุธที่ 15 กรกฎาคม พ.ศ. 2558

VARIABLE FOR EXPAND

VERSION 3
i can expand the picture by add variable width for expand.








ใน VERSION 3  ได้มีการสร้างตัวแปร x และ ตัวแปร y เพื่อใช้ในการขยับภาพในแกน x และแกน y และสร้างตัวแปร width เพื่อใช้ในการขยายภาพ

ในการขยับภาพในแกน x และแกน y คงใช้หลัการเดิมเหมือนใน version 2

ส่วนหลักการในการขยายภาพของรูปสามเหลี่ยมคือเมื่อมีการเปลี่ยนค่าตัวแปร width เป็นเท่าไหร่ก็ตาม จุดทั้งสามจุดของรูปสามเหลี่ยมจะมีการขยายออกตามค่าของตัวแปร width เช่นถ้าค่าตัวแปร w = 200 จุด x1,x2,x3 ของรูปสามเหลี่ยมจะอยู่ห่างกัน 200 เช่นกัน ถ้าค่าตัวแปร width = 300 จุด x1,x2,x3 ของรูปสามเหลี่ยมจะอยู่ห่างกัน 300 

ส่วนการขยายพระอาทิตย์ ใช้ตัวแปร width ขยายในแนวแกน x, ขยายในแนวแกน y ของคำสั่ง ellipse


void setup() {
       size(1000, 1000);
       stroke(0);
       background(255, 255, 255);
       
        
        int x=100;
        int y=400;
        int width=100;
      
        
        triangle(x+width       ,    y,     x+(2*width) ,     y-width,    x+ (3*width),     y);
        triangle (x+(3*width)    ,    y,    x+(4*width),     y-width,     x+(5*width),     y);
        triangle( x+(5*width)    ,    y,    x+(6*width),     y-width,     x+(7*width),     y);
       
       
       ellipse(x, y-300, width, width);
       

       
       stroke(126);
       
     }