Cov txheej txheem:

Coding Yooj Yim Playdoh Cov Duab W/ P5.js & Makey Makey: 7 Kauj Ruam
Coding Yooj Yim Playdoh Cov Duab W/ P5.js & Makey Makey: 7 Kauj Ruam

Video: Coding Yooj Yim Playdoh Cov Duab W/ P5.js & Makey Makey: 7 Kauj Ruam

Video: Coding Yooj Yim Playdoh Cov Duab W/ P5.js & Makey Makey: 7 Kauj Ruam
Video: Night 2024, Hlis ntuj nqeg
Anonim
Coding Yooj Yim Playdoh Cov Duab W/ P5.js & Makey Makey
Coding Yooj Yim Playdoh Cov Duab W/ P5.js & Makey Makey

Makey Makey Cov Haujlwm »

Nov yog qhov phiaj xwm kev suav lub cev uas tso cai rau koj los tsim cov duab nrog Playdoh, tus lej uas siv lub p5.js thiab ua kom lub ntsej muag ntawd tshwm rau ntawm lub computer screen los ntawm kev kov Playdoh cov duab siv Makey Makey.

p5.js yog qhov chaw qhib, web based, muaj tswv yim tsim ib puag ncig hauv Javascript. Kawm paub ntau ntxiv ntawm no:

Koj tsis xav tau ib qho kev paub coding los ua txoj haujlwm no. Qhov no tuaj yeem siv los ua kev taw qhia rau cov ntawv raws coding (tsis zoo li thaiv cov lus raws li Kos). Koj tsuas yog yuav tsum sau 4 kab ntawm txoj cai kom ua tiav txoj haujlwm no. Muaj ntau txoj hauv kev koj tuaj yeem hloov pauv thiab nthuav dav ntawm lub tswv yim yooj yim no.

Khoom siv

Makey Makey Kit (w/ 2 Alligator Clips)

Playdoh (Txhua Yam Xim)

Laptop nrog internet txuas

Kauj ruam 1: Ua Playdoh Shape

Ua Playdoh Shape
Ua Playdoh Shape

Ua tus qauv tawm ntawm Playdoh. Qhov no tuaj yeem yog lub voj voog, oval, xwmfab, duab plaub lossis duab plaub. Nco ntsoov tias koj yuav xav tau tus lej no tom qab, yog li cov qauv yooj yim dua, qhov yooj yim ntawm cov lej yuav yog. Txawm li cas los xij, p5.js muaj peev xwm sau ntau yam duab sib txawv, txawm tias yog tus kheej, yog li koj tuaj yeem txiav txim siab ntawm qib nyuaj uas koj xav sim.

Kauj Ruam 2: Pib Pib hauv P5.js

Pib Pib hauv P5.js
Pib Pib hauv P5.js

Yog tias koj tsis tau siv p5.js ua ntej, Kuv pom zoo tshuaj xyuas nplooj ntawv pib ntawm lub vev xaib:

Kuv kuj pom zoo kom txheeb xyuas Tus Coding Train youtube channel rau kev qhia zoo txog kev siv p5.js. Nov yog qhov txuas rau playlist uas hla txhua qhov pib:

Txij li p5.js yog lub vev xaib, koj tuaj yeem ua txhua yam koj coding ntawm lub vev xaib siv p5 Web Editor. Koj tsis xav tau tus account los ua txoj haujlwm no, tab sis yog tias koj xav txuag koj txoj haujlwm, koj yuav tsum tau sau npe rau tus as khauj.

Web Editor:

P5.js lub vev xaib khoos phis tawj muaj thaj tsam sau cov cai ntawm sab laug thiab daim duab uas yuav nthuav tawm cov txiaj ntsig ntawm cov cai ntawm sab xis.

Txhua p5.js kos duab suav nrog teeb tsa () muaj nuj nqi thiab kos () muaj nuj nqi. Kev teeb tsa () muaj nuj nqi yuav ua haujlwm ib zaug thaum kos duab pib ua ntej. Hauv kev teeb tsa () muaj nuj nqi yog createCanvas muaj nuj nqi uas tsim qhov chaw uas koj cov duab yuav raug kos. Cov lej nyob hauv kab ntawv ntawm kev tsim cov Canvas ua haujlwm teeb tsa X axis (sab laug mus rau sab xis) thiab Y axis (saum toj mus rau hauv qab) ntawm daim ntaub. Cov lej tsis yog 400, 400 uas txhais tau tias koj daim ntaub yog 400 pixels los ntawm sab laug mus rau sab xis thiab 400 pixels los ntawm saum toj mus rau hauv qab (Koj ib txwm tuaj yeem hloov cov no kom haum rau koj cov kev xav tau). Nco ntsoov tias sab laug sab tes laug ntawm daim ntaub yog lub ntsiab lus 0, 0. Qhov no yuav yog qhov tseem ceeb kom paub thaum koj cim koj lub cev.

Qhov kos () ua haujlwm khiav raws lub voj uas txhais tau tias nws tau hloov kho tas li, kwv yees li. 60 zaug ib pliag. Qhov no tuaj yeem tso cai rau peb los tsim cov duab kos hauv peb cov duab kos. Sab hauv kos () ua haujlwm yog keeb kwm yav dhau los uas ntxiv xim rau peb daim duab. Lub neej ntawd yog 220 uas yog tus nqi greyscale. 0 = dub, 255 = dawb thiab tus lej nyob nruab nrab yuav sib txawv ntxoov txho. Kev ua haujlwm tom qab kuj tseem tuaj yeem coj tus nqi RGB uas tso cai rau peb ntxiv xim. Xav paub ntau ntxiv txog qhov no hauv cov kauj ruam tom ntej.

Kauj Ruam 3: Code Koj Cov Duab hauv P5.js

Code Koj Cov Duab hauv P5.js
Code Koj Cov Duab hauv P5.js
Code Koj Cov Duab hauv P5.js
Code Koj Cov Duab hauv P5.js

Txhawm rau cim koj lub cev, koj tsuas yog yuav tsum tau ntxiv rau kab ntawm cov cai sab hauv ntawm kos () ua haujlwm.

Txhua tus duab nws muaj nws tus kheej ua haujlwm kom nws tshwm rau ntawm daim ntaub. Nov yog nplooj ntawv siv rau txhua daim duab hauv p5.js:

Txhawm rau ua lub voj voog, peb yuav siv txoj haujlwm ellipse. Txoj haujlwm no siv 3 qhov kev sib cav (cov lej uas nkag mus rau hauv kab lus). Thawj tus lej yog X txoj haujlwm ntawm nruab nrab ntawm lub voj voog ntawm daim ntaub thiab tus lej thib ob yog Y txoj haujlwm ntawm daim ntaub. Nco ntsoov tias lub kaum sab laug sab saud yog 0, 0 thiab daim ntaub yog 400 x 400 pixels. Yog li yog tias kuv xav kom lub voj voos tshwm nyob hauv nruab nrab ntawm daim ntaub kuv yuav muab nws tso rau ntawm 200 ntawm X axis thiab 200 ntawm Y axis. Koj tuaj yeem sim nrog cov lej no kom nkag siab yuav ua li cas tso khoom rau ntawm daim ntaub.

Tus lej thib peb teev qhov loj ntawm lub voj voog. Rau qhov piv txwv no, nws tau teeb tsa rau 100 pixels hauv txoj kab uas hla. Txoj haujlwm ellipse tseem tuaj yeem siv plaub qhov kev sib cav uas yuav hloov qhov kev sib cav zaum peb los cuam tshuam rau X txoj kab uas hla thiab plaub qhov kev sib cav yuav yog Y txoj kab uas hla. Qhov no tuaj yeem siv los ua cov duab oval es tsis siv lub voj voos kheej kheej.

Txhawm rau teeb cov xim ntawm peb cov duab, peb siv qhov ua kom tiav. Qhov no siv 3 qhov kev sib cav uas yog RGB qhov tseem ceeb (R = liab, G = ntsuab, B = xiav). Txhua tus nqi tuaj yeem yog tus lej nruab nrab ntawm 0 thiab 255. Piv txwv li, kom ua liab, peb yuav tso 255, 0, 0 uas yuav yog tag nrho cov liab uas tsis muaj ntsuab lossis xiav. Kev sib xyaw ua ke sib txawv ntawm cov lej no yuav tsim xim sib txawv.

Muaj ntau lub vev xaib uas muab RGB tus nqi rau ntau yam xim sib txawv, zoo li qhov no:

Thaum koj tau pom tus nqi RGB kom phim koj cov xim ntawm PlayDoh, sau qhov sau ua haujlwm saum cov duab ua haujlwm.

Tom qab ntawd koj tuaj yeem nyem khawm ua si hauv lub vev xaib khoos phis tawm thiab koj yuav tsum pom koj lub ntsej muag tshwm ntawm qhov screen.

Kauj Ruam 4: Ua Kom Koj Lub Cev Zoo Li Pom Nrog Tus Xov Tooj Tseem Ceeb

Ua kom koj lub ntsej muag tshwm nrog nias lub pob
Ua kom koj lub ntsej muag tshwm nrog nias lub pob
Ua kom koj lub ntsej muag tshwm nrog nias qhov tseem ceeb
Ua kom koj lub ntsej muag tshwm nrog nias qhov tseem ceeb
Ua kom koj lub ntsej muag tshwm nrog nias qhov tseem ceeb
Ua kom koj lub ntsej muag tshwm nrog nias qhov tseem ceeb

Txij li thaum peb xav kom peb daim duab p5.js sib cuam tshuam nrog Makey Makey, peb yuav tsum ntxiv qee cov cai txhawm rau ua qee yam tshwm sim thaum peb nias tus yuam sij ntawm cov keyboard. Hauv qhov no, peb xav kom cov duab tsuas yog tshwm sim yog tias peb nias tus yuam sij. Txhawm rau ua qhov no peb xav tau cov lus hais raws cai. Qhov no txhais tau tias qee yam hauv peb cov cai tsuas yog tshwm sim yog tias muaj qee qhov xwm txheej tau ntsib, hauv qhov no, tus yuam sij raug nias.

Txhawm rau ua kom raug raws li cov lus pom zoo no, peb pib nrog lo lus yog ua raws los ntawm kab lus. Sab hauv ntawm kab ntawv yuav yog qhov xwm txheej peb xav kom tau ntsib. Hauv p5.js, muaj qhov ua tau hloov pauv hu ua keyIsPressed (nco ntsoov tias koj siv cov tsiaj ntawv loj tib yam nkaus li tau sau ntawm no). keyIsPressed yog qhov sib txawv boolean. Qhov no txhais tau tias nws tuaj yeem muaj tus nqi ntawm qhov tseeb lossis tsis tseeb. Thaum tus yuam sij raug nias, nws tus nqi yog qhov tseeb thiab thaum nws tsis raug nias, nws tus nqi tsis yog.

Thaum kawg peb ntxiv txheej txheej nkhaus {}. Sab hauv ntawm cov kab nkhaus yuav yog cov cai peb xav kom ua yog tias peb qhov xwm txheej tau ntsib. Yog li peb tsuas yog yuav tso peb cov cai los ua cov duab nyob nruab nrab ntawm cov ntawv nkhaus.

Tam sim no thaum peb khiav peb daim duab, peb yuav tsis pom lub ntsej muag kom txog thaum peb nias tus yuam sij ntawm cov keyboard.

CEEB TOOM CEEB TOOM: Thaum ntxiv qhov tseem ceeb nias rau hauv peb tus lej, tus kws kho lub vev xaib yuav tsum paub yog tias peb tab tom nias tus yuam sij los sau cov cai hauv kab ntawv sau lossis peb tab tom nias tus yuam sij los ua qhov peb tau sau tus lej tseem ceeb ua. Thaum koj nyem lub pob ua si, txav tus nas hla daim ntaub thiab nyem rau ntawm daim ntaub. Qhov no yuav coj kev tsom mus rau tus kws kho duab kos thiab nias tus yuam sij yuav ua rau tus yuam sij nias tus lej peb xav kom tshwm sim

Kauj Ruam 5: Teeb Makey Makey

Teeb Makey Makey
Teeb Makey Makey
Teeb Makey Makey
Teeb Makey Makey
Teeb Makey Makey
Teeb Makey Makey

Tawm ntawm Makey Makey lub rooj tsavxwm, USB cable thiab ob tus nab kuab. Txuas ib tus nab kuab mus rau lub Ntiaj Teb thiab ib qho rau Qhov Chaw Tseem Ceeb (txij li peb tsis tau hais qhia tus yuam sij hauv peb tus lej, ib tus yuam sij twg peb nias yuav ua rau lub ntsej muag tshwm tuaj).

Nqa tus nab kuab clip uas txuas rau Qhov Chaw Tseem Ceeb thiab nias lwm qhov kawg rau hauv Playdoh cov duab.

Txuas lub USB cable rau hauv lub laptop.

Kauj Ruam 6: Kov Playdoh Shape

Image
Image
Kov Playdoh Shape
Kov Playdoh Shape

Tuav cov hlau kawg ntawm tus nab kuab xov uas txuas rau Lub Ntiaj Teb ntawm Makey Makey thiab kov Playdoh cov duab. Thaum koj kov Playdoh cov duab, cov duab cim yuav tsum tshwm ntawm daim duab ntawm koj daim duab.

Nov yog qhov txuas rau p5.js kos duab rau txoj haujlwm no:

Yog tias cov duab tsis tshwm:

1. Nco ntsoov tias koj tau nyem tus nas ntawm daim ntaub p5.js kos ua ntej kov Playdoh.

2. Nco ntsoov tias koj tau tuav cov hlau txuas ntawm lub ntiaj teb xaim.

Kauj Ruam 7: Cov Duab Sib Txawv

Cov Duab Sib Txawv
Cov Duab Sib Txawv
Cov Duab Sib Txawv
Cov Duab Sib Txawv
Cov Duab Sib Txawv
Cov Duab Sib Txawv
Cov Duab Sib Txawv
Cov Duab Sib Txawv

Daim duab peb sab daj:

Blue Square:

Pom zoo: