mirror of
https://github.com/dancojocaru2000/logic-circuits-simulator.git
synced 2025-02-21 16:49:36 +02:00
Added examples: standard library and scripts
This commit is contained in:
parent
b34e65544b
commit
3cdee540fc
3 changed files with 52 additions and 0 deletions
10
examples/componentTest.ht
Normal file
10
examples/componentTest.ht
Normal file
|
@ -0,0 +1,10 @@
|
|||
fun simulate(inputs) -> Map {
|
||||
final result = Map()
|
||||
if (inputs['A'] && inputs['B']) {
|
||||
result['OUT'] = true
|
||||
} else {
|
||||
result['OUT'] = false
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
42
examples/simulateTest.ht
Normal file
42
examples/simulateTest.ht
Normal file
|
@ -0,0 +1,42 @@
|
|||
var inputsValue = 0
|
||||
|
||||
fun onLoad {
|
||||
snackBar("Script loaded", "Start", start)
|
||||
}
|
||||
|
||||
fun getFunctions {
|
||||
return ["start", "random"]
|
||||
}
|
||||
|
||||
fun start {
|
||||
inputsValue = 0
|
||||
simSetPartiallySimulating(false)
|
||||
simRestart()
|
||||
tick()
|
||||
}
|
||||
|
||||
fun tick {
|
||||
final inputs = getInputs()
|
||||
final inputsLength = inputs.length
|
||||
|
||||
simSetInputsBinary(inputsValue)
|
||||
inputsValue += 1
|
||||
|
||||
if (inputsValue >= Math.pow(2, inputsLength)) {
|
||||
inputsValue = 0
|
||||
snackBar("Finished going through all possible values", "Restart", () {
|
||||
start()
|
||||
})
|
||||
}
|
||||
else {
|
||||
setTimeout(1000, tick)
|
||||
}
|
||||
}
|
||||
|
||||
fun random {
|
||||
final inputs = getInputs()
|
||||
final inputsLength = inputs.length
|
||||
|
||||
simSetInputsBinary(Math.randomInt(Math.pow(2, inputsLength)))
|
||||
}
|
||||
|
BIN
examples/standard.lcsproj
Normal file
BIN
examples/standard.lcsproj
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue