adding a mood block (image+sound+light)

This commit is contained in:
Peli de Halleux 2018-01-16 14:52:49 -08:00
parent 280963d1eb
commit d1bb19e30e
7 changed files with 156 additions and 0 deletions

View File

@ -10,6 +10,7 @@
"base": "file:../base",
"core": "file:../core",
"music": "file:../music",
"mood": "file:../mood",
"color-sensor": "file:../color-sensor",
"touch-sensor": "file:../touch-sensor",
"ultrasonic-sensor": "file:../ultrasonic-sensor",

3
libs/mood/README.md Normal file
View File

@ -0,0 +1,3 @@
# mood
A package to put the EV3 in various moods.

View File

@ -0,0 +1,16 @@
{
"brick.Mood": "A mood",
"brick.Mood.show": "Shows the mood on the EV3",
"brick.angry": "An angry mood",
"brick.awake": "A awake mood",
"brick.dizzy": "A dizzy mood",
"brick.knockedOut": "A knocked out mood",
"brick.love": "In love mood",
"brick.middleLeft": "Looking around left",
"brick.middleRight": "Looking around right",
"brick.neutral": "In a neutral mood",
"brick.sad": "A sad mood",
"brick.sleeping": "A sleeping mood",
"brick.tired": "A tired mood",
"brick.winking": "In laughing mood"
}

View File

@ -0,0 +1,6 @@
{
"brick.Mood.show|block": "show mood %mood=mood_image_picker",
"brick|block": "brick",
"{id:category}Brick": "Brick",
"{id:group}Screen": "Screen"
}

115
libs/mood/mood.ts Normal file
View File

@ -0,0 +1,115 @@
namespace brick {
/**
* A mood
*/
//% fixedInstances
export class Mood {
image: Image;
sound: Sound;
light: BrickLight;
constructor(image: Image, sound: Sound, light: BrickLight) {
this.image = image;
this.sound = sound;
this.light = light;
}
/**
* Shows the mood on the EV3
*/
//% weight=90
//% blockId=moodShow block="show mood %mood=mood_image_picker"
//% weight=101 group="Screen" blockGap=8
show() {
brick.setLight(this.light);
brick.showImage(this.image);
if (this.sound)
music.playSoundEffect(this.sound);
}
}
/**
* An image
* @param image the image
*/
//% blockId=mood_image_picker block="%image" shim=TD_ID
//% image.fieldEditor="images"
//% image.fieldOptions.columns=4
//% image.fieldOptions.width=400
//% group="Screen" weight=0 blockHidden=1
export function __moodImagePicker(mood: Mood): Mood {
return mood;
}
/**
* A sleeping mood
*/
//% fixedInstance jres=images.eyesSleeping
export const sleeping = new Mood(images.eyesSleeping, sounds.expressionsSnoring, BrickLight.OrangePulse);
/**
* A awake mood
*/
//% fixedInstance jres=images.eyesAwake
export const awake = new Mood(images.eyesAwake, sounds.informationActivate, BrickLight.Orange);
/**
* A tired mood
*/
//% fixedInstance jres=images.eyesTiredMiddle
export const tired = new Mood(images.eyesTiredMiddle, sounds.expressionsSneezing, BrickLight.OrangeFlash);
/**
* An angry mood
*/
//% fixedInstance jres=images.eyesAngry
export const angry = new Mood(images.eyesAngry, sounds.animalsDogGrowl, BrickLight.RedPulse);
/**
* A sad mood
*/
//% fixedInstance jres=images.eyesTear
export const sad = new Mood(images.eyesTear, sounds.animalsDogWhine, BrickLight.Red);
/**
* A dizzy mood
*/
//% fixedInstance jres=images.eyesDizzy
export const dizzy = new Mood(images.eyesDizzy, sounds.expressionsUhOh, BrickLight.OrangeFlash);
/**
* A knocked out mood
*/
//% fixedInstance jres=images.eyesKnockedOut
export const knockedOut = new Mood(images.eyesKnockedOut, sounds.informationError, BrickLight.RedFlash);
/**
* Looking around left
*/
//% fixedInstance jres=images.eyesMiddleLeft
export const middleLeft = new Mood(images.eyesMiddleLeft, sounds.informationAnalyze, BrickLight.Off);
/**
* Looking around right
*/
//% fixedInstance jres=images.eyesMiddleRight
export const middleRight = new Mood(images.eyesMiddleRight, sounds.informationAnalyze, BrickLight.Off);
/**
* In love mood
*/
//% fixedInstance jres=images.eyesLove
export const love = new Mood(images.eyesLove, sounds.expressionsMagicWand, BrickLight.GreenPulse);
/**
* In laughing mood
*/
//% fixedInstance jres=images.eyesWinking
export const winking = new Mood(images.eyesWinking, sounds.expressionsLaughing1, BrickLight.GreenFlash);
/**
* In a neutral mood
*/
//% fixedInstance jres=images.eyesNeutral
export const neutral = new Mood(images.eyesNeutral, undefined, BrickLight.Green);
}

14
libs/mood/pxt.json Normal file
View File

@ -0,0 +1,14 @@
{
"name": "mood",
"description": "The EV3 mood library",
"files": [
"README.md",
"mood.ts"
],
"testFiles": [
],
"public": true,
"dependencies": {
"core": "file:../core"
}
}

View File

@ -16,6 +16,7 @@
"libs/infrared-sensor",
"libs/gyro-sensor",
"libs/chassis",
"libs/mood",
"libs/ev3",
"libs/storage",
"libs/datalog",