[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [gcompris/gsoc_pulkit_digital_electricity] src/activities/digital_electricity: digital_electricity: 
From:       Rudra Nil Basu <null () kde ! org>
Date:       2017-08-16 13:58:49
Message-ID: E1dhyqP-0006oF-5X () code ! kde ! org
[Download RAW message or body]

Git commit 5fa155597ef1d9e1c1a431d1c88119442c10c894 by Rudra Nil Basu.
Committed on 16/08/2017 at 13:15.
Pushed by rudranilbasu into branch 'gsoc_pulkit_digital_electricity'.

digital_electricity: NOR gates, Comparator

Levels 16 - 19 aims at teaching the implementation of other gates using
NOR gate. They are explained as follows:
* Level 16: Implementing NOT gate using NOR gate
* Level 17: Implementing AND gate using NOR gate
* Level 18: Implementing OR gate using NOR gate
* Level 19: Implementing NAND gate using NOR gate

Level 20 introduces comparator, with a simple task requiring the use of
comparator and asks the user to compute the following result using it:

  S = A <= B

where A and B are two respective switchKeys and S is the output of the
digitalLight.

Signed-off-by: Rudra Nil Basu <rudra.nil.basu.1996@gmail.com>

M  +68   -0    src/activities/digital_electricity/Dataset.qml
M  +63   -3    src/activities/digital_electricity/digital_electricity.js

https://commits.kde.org/gcompris/5fa155597ef1d9e1c1a431d1c88119442c10c894

diff --git a/src/activities/digital_electricity/Dataset.qml \
b/src/activities/digital_electricity/Dataset.qml index f33ba320..2e3d3f8a 100644
--- a/src/activities/digital_electricity/Dataset.qml
+++ b/src/activities/digital_electricity/Dataset.qml
@@ -92,6 +92,13 @@ QtObject {
         'height': 0.15,
         'toolTipText': qsTr("Switch")
     }
+    property var comparator: {
+        'imageName': 'comparator.svg',
+        'componentSource': 'Comparator.qml',
+        'width': 0.3,
+        'height': 0.25,
+        'toolTipText': qsTr("Comparator")
+    }
     // tutorial levels
     property var tutorialLevels: [
         // level 1
@@ -285,6 +292,67 @@ QtObject {
             introMessage: [
                 qsTr("Create a circuit using the components provided such that the \
bulb glows only when both of the switches are turned off.")  ]
+        },
+        // level 16
+        {
+            inputComponentList: [norGate],
+            playAreaComponentList: [one, switchKey, digitalLight],
+            determiningComponentsIndex: [1, 2],
+            wires: [ [0, 0, 1, 0] ],
+            playAreaComponentPositionX: [0.1, 0.3, 0.8],
+            playAreaComponentPositionY: [0.5, 0.5, 0.5],
+            introMessage: [
+                qsTr("Use the gates such that the bulb will glow only when the \
switch is turned off and remain off when the switch is turned on.") +            ]
+        },
+        // level 17
+        {
+            inputComponentList: [norGate],
+            playAreaComponentList: [one, switchKey, switchKey, digitalLight],
+            determiningComponentsIndex: [1, 2, 3],
+            wires: [ [0, 0, 1, 0], [0, 0, 2, 0] ],
+            playAreaComponentPositionX: [0.0, 0.2, 0.2, 0.8],
+            playAreaComponentPositionY: [0.5, 0.4, 0.6, 0.5],
+            introMessage: [
+                qsTr("Create a circuit using the components provided such that the \
bulb glows only when both of the switches are turned on.") +            ]
+        },
+        // level 18
+        {
+            inputComponentList: [norGate],
+            playAreaComponentList: [one, switchKey, switchKey, digitalLight],
+            determiningComponentsIndex: [1, 2, 3],
+            wires: [ [0, 0, 1, 0], [0, 0, 2, 0] ],
+            playAreaComponentPositionX: [0.0, 0.2, 0.2, 0.8],
+            playAreaComponentPositionY: [0.5, 0.4, 0.6, 0.5],
+            introMessage: [
+                qsTr("Create a circuit using the components provided such that the \
bulb glows when either of the switches are turned on.") +            ]
+        },
+        // level 19
+        {
+            inputComponentList: [norGate],
+            playAreaComponentList: [one, switchKey, switchKey, digitalLight],
+            determiningComponentsIndex: [1, 2, 3],
+            wires: [ [0, 0, 1, 0], [0, 0, 2, 0] ],
+            playAreaComponentPositionX: [0.0, 0.2, 0.2, 0.8],
+            playAreaComponentPositionY: [0.5, 0.4, 0.6, 0.5],
+            introMessage: [
+                qsTr("Create a circuit using the components provided such that the \
bulb will glow when at least one of the switches are turned off.") +            ]
+        },
+        // level 20
+        {
+            inputComponentList: [one, andGate, notGate, norGate, xorGate, nandGate, \
orGate], +            playAreaComponentList: [switchKey, switchKey, comparator, \
digitalLight], +            determiningComponentsIndex: [0, 1, 3],
+            wires: [  ],
+            playAreaComponentPositionX: [0.0, 0.0, 0.4, 0.9],
+            playAreaComponentPositionY: [0.2, 0.4, 0.5, 0.5],
+            introMessage: [
+                qsTr("A comparator takes two numbers (A and B) as input and produces \
3 values as output. First value is 1 if A < B, second value is 1 for A = B and third \
value is 1 for A > B."), +                qsTr("Create a circuit using the components \
provided such that the bulb will glow when the value of the current flowing through \
the first switch is less than or equal to that of the second switch.") +            ]
         }
     ]
 }
diff --git a/src/activities/digital_electricity/digital_electricity.js \
b/src/activities/digital_electricity/digital_electricity.js index 2ef3311e..a1e41066 \
                100644
--- a/src/activities/digital_electricity/digital_electricity.js
+++ b/src/activities/digital_electricity/digital_electricity.js
@@ -354,7 +354,7 @@ function checkAnswer() {
             }
         }
         items.bonus.good('tux')
-    } else if (currentLevel == 12) {
+    } else if (currentLevel == 12 || currentLevel == 16) {
         var switch1 = determiningComponents[0]
 
         var digitalLight = determiningComponents[1]
@@ -376,7 +376,7 @@ function checkAnswer() {
             }
         }
         items.bonus.good('tux')
-    } else if (currentLevel == 13) {
+    } else if (currentLevel == 13 || currentLevel == 17) {
         var switch1 = determiningComponents[0]
         var switch2 = determiningComponents[1]
 
@@ -406,7 +406,7 @@ function checkAnswer() {
             }
         }
         items.bonus.good('tux')
-    } else if (currentLevel == 14) {
+    } else if (currentLevel == 14 || currentLevel == 18) {
         var switch1 = determiningComponents[0]
         var switch2 = determiningComponents[1]
 
@@ -466,6 +466,66 @@ function checkAnswer() {
             }
         }
         items.bonus.good('tux')
+    }  else if (currentLevel == 19) {
+        var switch1 = determiningComponents[0]
+        var switch2 = determiningComponents[1]
+
+        var digitalLight = determiningComponents[2]
+
+        var switch1InitialState = switch1.imgSrc
+        var switch2InitialState = switch2.imgSrc
+
+        for (var A = 0; A <= 1; A++) {
+            for (var B = 0; B <= 1; B++) {
+                switch1.imgSrc = A == 1 ? "switchOn.svg" : "switchOff.svg"
+                switch2.imgSrc = B == 1 ? "switchOn.svg" : "switchOff.svg"
+
+                updateComponent(switch1.index)
+                updateComponent(switch2.index)
+
+                var operationResult = !(A & B)
+
+                if (operationResult != digitalLight.inputTerminals.itemAt(0).value) \
{ +                    switch1.imgSrc = switch1InitialState
+                    switch2.imgSrc = switch2InitialState
+                    updateComponent(switch1.index)
+                    updateComponent(switch2.index)
+                    items.bonus.bad('tux')
+                    return
+                }
+            }
+        }
+        items.bonus.good('tux')
+    } else if (currentLevel == 20) {
+        var switch1 = determiningComponents[0]
+        var switch2 = determiningComponents[1]
+
+        var digitalLight = determiningComponents[2]
+
+        var switch1InitialState = switch1.imgSrc
+        var switch2InitialState = switch2.imgSrc
+
+        for (var A = 0; A <= 1; A++) {
+            for (var B = 0; B <= 1; B++) {
+                switch1.imgSrc = A == 1 ? "switchOn.svg" : "switchOff.svg"
+                switch2.imgSrc = B == 1 ? "switchOn.svg" : "switchOff.svg"
+
+                updateComponent(switch1.index)
+                updateComponent(switch2.index)
+
+                var operationResult = A <= B
+
+                if (operationResult != digitalLight.inputTerminals.itemAt(0).value) \
{ +                    switch1.imgSrc = switch1InitialState
+                    switch2.imgSrc = switch2InitialState
+                    updateComponent(switch1.index)
+                    updateComponent(switch2.index)
+                    items.bonus.bad('tux')
+                    return
+                }
+            }
+        }
+        items.bonus.good('tux')
     }
     else {
         if (determiningComponents[0].inputTerminals.itemAt(0).value == 1)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic