Skip to content

Commit

Permalink
3
Browse files Browse the repository at this point in the history
  • Loading branch information
blackmius committed Oct 6, 2015
1 parent 83d7ad0 commit b196138
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 58 deletions.
36 changes: 18 additions & 18 deletions bin/CircuitD.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def update(self):
event = pygame.event.poll()

if event.type == KEYDOWN:
if event.key == K_BACKSPACE:
if event.key == K_BACKworkspace:
self.text = self.text[:-1]

elif event.key == K_RETURN or event.key == K_KP_ENTER:
Expand All @@ -655,7 +655,7 @@ def update(self):
if self.text != '':
try:
if key[self.key[0]]:
if self.key[0] == K_BACKSPACE:
if self.key[0] == K_BACKworkspace:
self.text = self.text[:-1]

elif self.mode == 'INPUT':
Expand Down Expand Up @@ -765,8 +765,8 @@ def draw(self):
class window:
info = display.Info()

width = info.current_w
height = info.current_h
width = 640
height = 480

minWidth = 640
minHeight = 480
Expand Down Expand Up @@ -933,7 +933,7 @@ def draw(self):

info = info()

class space:
class workspace:
surface = Surface((camera.w, camera.h))
gates = []

Expand All @@ -944,7 +944,7 @@ class space:
gateselected = False

def resize(self):
surface = Surface((camera.w, camera.h))
self.surface = Surface((camera.w, camera.h))

def create_gate(self, type):
self.gates.append(gate(type))
Expand All @@ -955,15 +955,15 @@ def update(self):
self.mousepressed = True

for gate in range(len(self.gates)):
'''

#выборка элементов
if self.gates[gate].selected:
if gate < len(self.gates) - 1:
a = self.gates[len(self.gates) - 1]
b = self.gates[gate]
self.gates[gate] = a
self.gates[len(self.gates) - 1] = b
'''


self.gates[len(self.gates)-1-gate].update()

Expand All @@ -978,7 +978,7 @@ def draw(self):

window.screen.blit(self.surface, (gui.chooseCircuitOffset + gui.chooseCircuitWidth + gui.chooseCircuitArrowsWidth, gui.pannelHeight))

space = space()
workspace = workspace()

class gate:
def __init__(self, type):
Expand All @@ -1002,13 +1002,13 @@ def __init__(self, type):
def update(self):
if collide(self.x + gui.chooseCircuitOffset + gui.chooseCircuitWidth + gui.chooseCircuitArrowsWidth, mouse.get_pos()[0] + camera.x, self.y + gui.pannelHeight, mouse.get_pos()[1] + camera.y, self.w, 1, self.h, 1):
if self.mousepressed == False:
if self.pressed == False and mouse.get_pressed()[0] and space.gateselected == False:
if self.pressed == False and mouse.get_pressed()[0] and workspace.gateselected == False:
self.mouseoffset = [mouse.get_pos()[0] + camera.x - self.x, mouse.get_pos()[1] + camera.y - self.y]

self.mousepressed = True
self.pressed = True

space.gateselected = True
workspace.gateselected = True

self.selected = True
else:
Expand All @@ -1027,7 +1027,7 @@ def update(self):
else:
self.pressed = False

space.gateselected = False
workspace.gateselected = False


if mouse.get_pressed()[0]:
Expand All @@ -1040,9 +1040,9 @@ def update(self):
def draw(self):
if camera.drawPerms(self.x, self.y, self.w, self.h):
if self.selected:
space.surface.blit(self.outline, ((self.x - camera.x - 1, self.y - camera.y - 1)))
workspace.surface.blit(self.outline, ((self.x - camera.x - 1, self.y - camera.y - 1)))

space.surface.blit(self.image, (self.x - camera.x, self.y - camera.y))
workspace.surface.blit(self.image, (self.x - camera.x, self.y - camera.y))

class gui:
chooseCircuitWidth = 200
Expand Down Expand Up @@ -1153,11 +1153,11 @@ def update(self):
self.chooseCircuitArrows.update()
self.chooseCircuitSlider.update()

space.update()
workspace.update()


def draw(self):
space.draw()
workspace.draw()

window.screen.blit(self.chooseCircuitSurface, (self.chooseCircuitOffset, self.pannelHeight))
window.screen.blit(self.chooseCircuitArrowsBg, (self.chooseCircuitOffset + self.chooseCircuitWidth, self.pannelHeight))
Expand Down Expand Up @@ -1234,7 +1234,7 @@ def events():
window.resize(e.size)
gui.resize()
camera.resize()
space.resize()
workspace.resize()

camera.update()

Expand All @@ -1260,4 +1260,4 @@ def mainloop():
display.update()

if __name__ == "__main__":
mainloop()
mainloop()
Empty file added bin/circuitImg.py
Empty file.
100 changes: 60 additions & 40 deletions bin/logic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import types

AND = lambda a, b: bool(a) and bool(b)
OR = lambda a, b: bool(a) or bool(b)
Expand All @@ -11,6 +12,7 @@ def __init__(self, owner, name):
self.owner = owner
self.name = name
self.connects = []
self.level = 0

def connect(self, inputs):
if type(inputs) != type([]):
Expand All @@ -28,20 +30,37 @@ def set(self, value):

self.value = value

self.update()


def update(self):
for con in self.connects:
con.set(value)
con.owner.eval()
con.set(self.value)

if con.owner != self.owner:
con.owner.eval()
else:
if self.level == 0:
self.level += 1
con.owner.eval()


self.level = 0

class PrimElement:
def __init__(self, name):
self.name = name
def __init__(self, name, type):
self.name = name
self.type = type

def eval(self):
return
def eval(self):
return

def update(self):
self.out.update()

class Not(PrimElement):
def __init__(self, name):
PrimElement.__init__(self, name)
PrimElement.__init__(self, name, 'not')
self.in1 = outlet(self, 'A')
self.out = outlet(self, 'B')

Expand All @@ -50,7 +69,7 @@ def eval(self):

class And(PrimElement):
def __init__(self, name):
PrimElement.__init__(self, name)
PrimElement.__init__(self, name, 'and')
self.in1 = outlet(self, 'A')
self.in2 = outlet(self, 'B')
self.out = outlet(self, 'C')
Expand All @@ -60,7 +79,7 @@ def eval(self):

class Or(PrimElement):
def __init__(self, name):
PrimElement.__init__(self, name)
PrimElement.__init__(self, name, 'or')
self.in1 = outlet(self, 'A')
self.in2 = outlet(self, 'B')
self.out = outlet(self, 'C')
Expand All @@ -70,15 +89,15 @@ def eval(self):

class Switch(PrimElement):
def __init__(self, name):
PrimElement.__init__(self, name)
PrimElement.__init__(self, name, 'switch')
self.out = outlet(self, 'A')

def eval(self):
self.out.set(NOT(self.out.value))

class Bulb(PrimElement):
def __init__(self, name):
PrimElement.__init__(self, name)
PrimElement.__init__(self, name, 'bulb')
self.value = False
self.in1 = outlet(self, 'A')

Expand All @@ -88,46 +107,47 @@ def eval(self):

class Constant(PrimElement):
def __init__(self, name, value):
PrimElement.__init__(self, name)
PrimElement.__init__(self, name, 'constant')
self.value = value

self.out = outlet(self, 'A')
self.out.value = self.value

def eval(self):
self.out.update()


class Element(PrimElement):
def __init__(self, name):
PrimElement.__init__(self, name)
self.schema = []

def eval(self):
return

S1 = Switch('s1')
S2 = Switch('s2')

N1 = Not('n1')
N2 = Not('n2')

A1 = And('a1')
A2 = And('a2')

O1 = Or('o1')
def __init__(self, name):
PrimElement.__init__(self, name, name)

def add(self, gate):
setattr(self, gate.name, gate)

def update(self):
attr = []

for i in dir(self):
if type(getattr(self, i)) is types.InstanceType:
attr.append(i)

for i in attr:
if getattr(self, i).type == 'switch':
getattr(self, i).update()

B = Bulb('b1')
El = Element('Xor')

S1.eval()
S2.eval()
El.add(Switch('s1'))
El.add(Switch('s2'))

S1.out.connect([N1.in1, A2.in1])
N = Not('n')
B1 = Bulb('b2')

S2.out.connect([N2.in1, A1.in2])
N.out.connect(N.in1)
N.out.connect(B1.in1)

N1.out.connect(A1.in1)
N2.out.connect(A2.in2)
print N.out.value, B1.value

A1.out.connect(O1.in1)
A2.out.connect(O1.in2)
N.update()

O1.out.connect(B.in1)
print S1.out.value, S2.out.value, N1.out.value, N2.out.value, A1.out.value, A2.out.value, B.value
print N.out.value, B1.value
Empty file added bin/pallete.py
Empty file.
Empty file added bin/workspace.py
Empty file.

0 comments on commit b196138

Please sign in to comment.