Cov txheej txheem:

Cov Duab Roulette Nrog Obniz: 5 Kauj Ruam
Cov Duab Roulette Nrog Obniz: 5 Kauj Ruam

Video: Cov Duab Roulette Nrog Obniz: 5 Kauj Ruam

Video: Cov Duab Roulette Nrog Obniz: 5 Kauj Ruam
Video: txhob hnov qab kuv lub npe - Bee lee [Official MV] 2022-23 2024, Kaum ib hlis
Anonim
Image
Image

Kuv tau ua daim duab roulette. Yog tias koj nias lub pob, tus roulette pib tig. Yog tias koj nias dua, tus roulette nres tig thiab nrov nrov!

Kauj ruam 1: Circuit Court

Tig Rulette Duab
Tig Rulette Duab

Peb siv tsuas yog tus hais lus txuas thiab khawm.

Tus lej xov tooj ntawm tus xov tooj tau sau rau ntawm qhov program.

khawm = obniz.wired ("Button", {signal: 6, gnd: 7}); speaker = obniz.wired ("Speaker", {signal: 0, gnd: 1});

Kauj Ruam 2: Hloov Daim Duab Rulette

Hauv HTML, koj tuaj yeem siv "CSS hloov pauv". Piv txwv li, qhov no yog cov cai ntawm cov duab tig 90 degree.

document.getElementById ("roulette"). style = "hloov pauv: tig (90deg);";

Txhawm rau pib thiab nres tig qeeb, ntxiv qhov hloov pauv ceev rau kev hloov qib ntawm ib tus ncej.

cia ceev = 0; tso deg = 0; muaj nuj nqi tig () {deg += ceev; document.getElementById ("roulette"). style = "hloov pauv: tig ("+deg+"deg);"

}

setInterval (tig, 10);

Kauj ruam 3: Pib

Koj puas xav beep ntawm roulette tsis hloov? Nrog rau qhov no, koj tuaj yeem beep ntawm 440Hz 10ms.

hais lus.play (440); tos obniz.wait (10); hais lus.stop ();

Nov yog yuav ua li cas thiaj paub txog kev hloov pauv ntawm roulette no.

yog (Math.floor ((deg + ceev) / (360 / 7.0)) - Math.floor (deg / (360 / 7.0))> = 1) {onRouletteChange (); }

Yog li, qhov no yog txoj cai ntawm tig thiab beep.

cia ceev = 0; tso deg = 0; muaj nuj nqi tig () {// ntawm qhov hloov pauv tus nqi yog (Math.floor ((deg + nrawm) /(360 /7.0)) - Math.floor (deg /(360 /7.0))> = 1) {onRouletteChange (); } deg += ceev; document.getElementById ("roulette"). style = "hloov pauv: tig ("+deg+"deg);"

}

setInterval (tig, 10);

async muaj nuj nqi onRouletteChange () {

yog (! hais lus) {rov qab;} hais lus.play (440); tos obniz.wait (10); hais lus.stop (); }

Kauj ruam 4: Pib ntawm Khawm Thawb

Txhawm rau paub khawm lub xeev, ntxiv cov khawm khawm Lub Xeev thiab teeb tus nqi ntawm lub xeev khawm tam sim no.

button.onchange = muaj nuj nqi (nias) {buttonState = nias; };

Thiab tseem ntxiv var theem rau lub xeev tam sim no ntawm roulette.phase tau teeb tsa ib qho ntawm no.

const PHASE_WAIT_FOR_START = 0; const PHASE_ROTATE = 1; const PHASE_STOPPING = 2; const PHASE_STOPPED = 3;

Piv txwv li, thaum theem PHASE_WAIT_FOR_START thiab koj xav mus rau theem tom ntej.

yog (theem == PHASE_WAIT_FOR_START) {ceev = 0; yog (buttonState) {theem = PHASE_ROTATE; }}

Txhawm rau ua kom cov txheej txheem nrawm dua, hloov pauv nrawm.

yog (theem == PHASE_ROTATE) {nrawm = nrawm+0.5; }

Txhawm rau txo txoj cai, hloov pauv nrawm.

:

yog (theem == PHASE_STOPPING) {nrawm = nrawm-0.2; }

Cov no yog ib feem ntawm roulette. Cia peb ua!

Kauj Ruam 5: Txoj Haujlwm

Thov saib ntawm no rau txoj haujlwm

Pom zoo: