%matplotlib notebook

import pew # setting up tools for the pewpew
from microqiskit import QuantumCircuit, simulate # setting up tools for quantum

pew.init() # initialize the game engine...
screen = pew.Pix() # ...and the screen

qc = QuantumCircuit(2,2) # create an empty circuit with two qubits and two output bits
# put a hadamard on both qubits
qc.h(0) 
qc.h(1)
# put a measurement on both qubit, whose results go to the corresponding output bit
qc.measure(0,0)
qc.measure(1,1)

# loop over the square centered on (1,2) and make all dim
(X,Y) = (1,2)
for dX in [+1,0,-1]:
    for dY in [+1,0,-1]:
        screen.pixel(X+dX,Y+dY,2)
        
screen.pixel(X,Y,0) # turn off pixel at (1,2) 

while True: # loop which checks for user input and responds

    # execute the circuit and get a single sample of memory
    m = simulate(qc,shots=1,get='memory')
    
    # the resulting bit string m[0] is converted to the corresponding number and used as brightness
    screen.pixel(X,Y,int(m[0],2))

    pew.show(screen) # update screen to display the above changes

    pew.tick(1/6) # pause for a sixth of a second

import pew # setting up tools for the pewpew
from microqiskit import QuantumCircuit, simulate # setting up tools for quantum

pew.init() # initialize the game engine...
screen = pew.Pix() # ...and the screen

qc = QuantumCircuit(2,2) # create an empty circuit with two qubits and two output bits
# put a hadamard on both qubits
qc.h(0) 
qc.h(1)
# put a measurement on both qubit, whose results go to the corresponding output bit
qc.measure(0,0)
qc.measure(1,1)

# loop over the squares centered on (1,2) and (6,2) and make all dim
for (X,Y) in [(1,2),(6,2)]:
    for dX in [+1,0,-1]:
        for dY in [+1,0,-1]:
            screen.pixel(X+dX,Y+dY,2)
        
for (X,Y) in [(1,2),(6,2)]:
    screen.pixel(X,Y,0) # turn off the center pixels of the squares  

while True: # loop which checks for user input and responds

    # execute the circuit and get a single sample of memory
    m = simulate(qc,shots=1,get='memory')
    
    # turn the pixel (1,2) on or off depending on whether the first bit value is 1 or 0
    if m[0][0]=='1':
        screen.pixel(1,2,3)
    else:
        screen.pixel(1,2,0)
    # do the same for pixel (6,2)
    if m[0][1]=='1':
        screen.pixel(6,2,3)
    else:
        screen.pixel(6,2,0)

    pew.show(screen) # update screen to display the above changes

    pew.tick(1/6) # pause for a sixth of a second

