kopia lustrzana https://github.com/villares/sketch-a-day
				
				
				
			
			
			
			
				main
			
			
		
		
							rodzic
							
								
									bddcb04e5a
								
							
						
					
					
						commit
						75f49dab5a
					
				|  | @ -73,9 +73,9 @@ class Cell(): | ||||||
|         for (ni, nj) in nbs: |         for (ni, nj) in nbs: | ||||||
|             nb = Cell.grid.get((i + ni, j + nj), None) |             nb = Cell.grid.get((i + ni, j + nj), None) | ||||||
|             if nb and nb.state: |             if nb and nb.state: | ||||||
|                 rect(self.pos.x + ni * third * 1.5, |                 ellipse(self.pos.x + ni * third * 1.5, | ||||||
|                      self.pos.y + nj * third * 1.5, |                      self.pos.y + nj * third * 1.5, | ||||||
|                      third, third) |                      third, third) | ||||||
|                 #point(self.pos.x, self.pos.y) #, third, third) |                 #point(self.pos.x, self.pos.y) #, third, third) | ||||||
|                 rect(self.pos.x, self.pos.y, third, third) |                 ellipse(self.pos.x, self.pos.y, third, third) | ||||||
| 3 | 3 | ||||||
|  |  | ||||||
							
								
								
									
										
											BIN
										
									
								
								s348/s347.png
								
								
								
								
							
							
						
						
									
										
											BIN
										
									
								
								s348/s347.png
								
								
								
								
							
										
											Plik binarny nie jest wyświetlany.
										
									
								
							| Przed Szerokość: | Wysokość: | Rozmiar: 93 KiB | 
|  | @ -37,7 +37,7 @@ def p_ou_b(i, j): | ||||||
| def draw(): | def draw(): | ||||||
|     #scale(3) |     #scale(3) | ||||||
|     background(220) |     background(220) | ||||||
|     strokeWeight(1) |     #strokeWeight(1) | ||||||
|     # KeyEvent.VK_CAPS_LOCK is 20 |     # KeyEvent.VK_CAPS_LOCK is 20 | ||||||
|     capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(20) |     capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(20) | ||||||
|     if capsLocked: |     if capsLocked: | ||||||
|  |  | ||||||
|  | @ -0,0 +1,84 @@ | ||||||
|  | 
 | ||||||
|  | class Cell(): | ||||||
|  |     # neighbours list | ||||||
|  |     NL = ((-1, -1), (+0, -1), (+1, -1), | ||||||
|  |           (-1, +0), (+0, +0), (+1, +0), | ||||||
|  |           (-1, +1), (+0, +1), (+1, +1)) | ||||||
|  |     ONL = ((+0, -1), | ||||||
|  |            (-1, +0), (+0, +0), (+1, +0), | ||||||
|  |            (+0, +1)) | ||||||
|  |     DNL = ((-1, -1), (+1, -1), | ||||||
|  |            (+0, +0), | ||||||
|  |            (-1, +1), (+1, +1)) | ||||||
|  | 
 | ||||||
|  |     def __init__(self, index, cell_size, state=False): | ||||||
|  |         self.index = index | ||||||
|  |         self.state = state | ||||||
|  |         self.size_ = cell_size | ||||||
|  |         self.mouse_down = False | ||||||
|  |         i, j = index[0], index[1] | ||||||
|  |         self.pos = PVector(self.size_ / 2 + i * self.size_, | ||||||
|  |                            self.size_ / 2 + j * self.size_) | ||||||
|  | 
 | ||||||
|  |     def update(self): | ||||||
|  |         # mouse over & selection treatment | ||||||
|  |         hs = self.size_ / 2 | ||||||
|  |         px, py = self.pos.x, self.pos.y | ||||||
|  |         self.mouse_on = (px - hs < mouseX < px + hs and | ||||||
|  |                          py - hs < mouseY < py + hs) | ||||||
|  |         if self.mouse_on and mousePressed: | ||||||
|  |             self.mouse_down = True | ||||||
|  |         if self.mouse_down and not mousePressed: | ||||||
|  |             self.state = not self.state | ||||||
|  |             self.mouse_down = False | ||||||
|  |         if self.mouse_on: | ||||||
|  |             fill(128, 128) | ||||||
|  |         else: | ||||||
|  |             noFill() | ||||||
|  |         strokeWeight(1) | ||||||
|  |         stroke(200) | ||||||
|  |         #rect(self.pos.x, self.pos.y, self.size_, self.size_) | ||||||
|  | 
 | ||||||
|  |     def plot(self, mode): | ||||||
|  |         if self.state: | ||||||
|  |             strokeWeight(self.size_ / 5.) | ||||||
|  |             if mode == -1: | ||||||
|  |                 fill(0) | ||||||
|  |                 noStroke() | ||||||
|  |                 rect(self.pos.x, self.pos.y, self.size_, self.size_) | ||||||
|  |             if mode == 0: | ||||||
|  |                 stroke(0) | ||||||
|  |                 self.draw_lines(Cell.NL) | ||||||
|  |                 self.draw_lines(Cell.NL) | ||||||
|  |             elif mode == 1: | ||||||
|  |                 stroke(0, 150, 0) | ||||||
|  |                 self.draw_lines(Cell.ONL) | ||||||
|  |             elif mode == 2: | ||||||
|  |                 stroke(0, 0, 150) | ||||||
|  |                 self.draw_lines(Cell.DNL) | ||||||
|  |             elif mode == 3: | ||||||
|  |                 stroke(0, 150, 0) | ||||||
|  |                 self.draw_lines(Cell.ONL) | ||||||
|  |                 stroke(0, 0, 150) | ||||||
|  |                 self.draw_lines(Cell.DNL) | ||||||
|  |             elif mode == 4: | ||||||
|  |                 stroke(0, 150, 0) | ||||||
|  |                 self.draw_lines(Cell.DNL) | ||||||
|  |                 stroke(0, 0, 150) | ||||||
|  |                 self.draw_lines(Cell.ONL) | ||||||
|  | 
 | ||||||
|  |     def draw_lines(self, nbs): | ||||||
|  |         third = self.size_ / 3. | ||||||
|  |         i, j = self.index[0], self.index[1] | ||||||
|  |         strokeWeight(1) | ||||||
|  |         for (ni, nj) in nbs: | ||||||
|  |             nb = Cell.grid.get((i + ni, j + nj), None) | ||||||
|  |             if nb and nb.state: | ||||||
|  |                 for i in range(3): | ||||||
|  |                     s = (third + i * third) | ||||||
|  |                     ellipse(self.pos.x + ni * third * 1.5, | ||||||
|  |                       self.pos.y + nj * third * 1.5, | ||||||
|  |                       s, s) | ||||||
|  |                     #point(self.pos.x, self.pos.y) #, third, third) | ||||||
|  |                     ellipse(self.pos.x, self.pos.y, s, s) | ||||||
|  | 3 | ||||||
										
											Plik binarny nie jest wyświetlany.
										
									
								
							| Po Szerokość: | Wysokość: | Rozmiar: 48 KiB | 
|  | @ -0,0 +1,96 @@ | ||||||
|  | # Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day | ||||||
|  | SKETCH_NAME = "s349b"  # 20181213 | ||||||
|  | OUTPUT = ".png" | ||||||
|  | mode = 0 | ||||||
|  | 
 | ||||||
|  | from cell import Cell | ||||||
|  | from random import choice | ||||||
|  | from java.awt import Toolkit | ||||||
|  | 
 | ||||||
|  | CELL_SIZE = 30 | ||||||
|  | Cell.grid = dict() | ||||||
|  | 
 | ||||||
|  | xo, yo = 100, 100 | ||||||
|  | xio, yio = 0, 0 | ||||||
|  | s = 10 | ||||||
|  | 
 | ||||||
|  | def setup(): | ||||||
|  |     size(600, 600) | ||||||
|  |     global img, grid_size | ||||||
|  |     img = loadImage("a.png") | ||||||
|  |     grid_size = width / CELL_SIZE | ||||||
|  | 
 | ||||||
|  | def init_grid(f=None): | ||||||
|  |     w, h = width // CELL_SIZE, height // CELL_SIZE | ||||||
|  |     for i in range(w): | ||||||
|  |         for j in range(h):  | ||||||
|  |             if f == None: | ||||||
|  |                 f = lambda i, j: choice((True, False)) | ||||||
|  |             Cell.grid[(i, j)] = Cell((i, j), CELL_SIZE, f(i, j) ) | ||||||
|  | 
 | ||||||
|  | def p_ou_b(i, j): | ||||||
|  |      c = img.get(xo + i, yo + j) | ||||||
|  |      if c == color(0): return True | ||||||
|  |      else: return False | ||||||
|  |       | ||||||
|  | 
 | ||||||
|  | def draw(): | ||||||
|  |     #scale(3) | ||||||
|  |     background(220) | ||||||
|  |     strokeWeight(1) | ||||||
|  |     # KeyEvent.VK_CAPS_LOCK is 20 | ||||||
|  |     capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(20) | ||||||
|  |     if capsLocked: | ||||||
|  |         rectMode(CORNER) | ||||||
|  |         image(img, xio, yio) | ||||||
|  |         noFill() | ||||||
|  |         rect(xio + xo, yio + yo, grid_size, grid_size) | ||||||
|  |         init_grid(p_ou_b) | ||||||
|  |     else: | ||||||
|  |         rectMode(CENTER) | ||||||
|  |         for c in Cell.grid.values(): | ||||||
|  |             c.update() | ||||||
|  |         for c in Cell.grid.values(): | ||||||
|  |             c.plot(mode) | ||||||
|  | 
 | ||||||
|  | def keyPressed(): | ||||||
|  |     global mode | ||||||
|  |     global xo, yo, xio, yio | ||||||
|  |     if key == CODED: | ||||||
|  |          | ||||||
|  |         if keyCode == RIGHT and xo < img.width - 11: | ||||||
|  |             xo += 16 | ||||||
|  |         if keyCode == LEFT and xo > 10: | ||||||
|  |             xo -= 16 | ||||||
|  |         if keyCode == DOWN and yo < img.height - 11: | ||||||
|  |             yo += 16 | ||||||
|  |         if keyCode == UP and yo > 10: | ||||||
|  |             yo -= 16 | ||||||
|  |     else: | ||||||
|  |         if key == "s" or key == "S": | ||||||
|  |             saveFrame(SKETCH_NAME + "_###.png") | ||||||
|  |         if key in "01234567789": | ||||||
|  |             mode = int(key) | ||||||
|  |         if key == "-": | ||||||
|  |             mode = -1 | ||||||
|  |         if key == " ": | ||||||
|  |             init_grid(lambda i, j: False) | ||||||
|  |         if key == "x": | ||||||
|  |             init_grid(lambda i, j: (i + j) % 2 == 0) | ||||||
|  |         if key == "r": | ||||||
|  |             init_grid() | ||||||
|  |     if xo > width - grid_size: | ||||||
|  |         xio = width - grid_size - xo | ||||||
|  |     if yo > height - grid_size: | ||||||
|  |         yio = height - grid_size - yo | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | # print text to add to the project's README.md | ||||||
|  | def settings(): | ||||||
|  |     println( | ||||||
|  |         """ | ||||||
|  |  | ||||||
|  | 
 | ||||||
|  | {1}: [code](https://github.com/villares/sketch-a-day/tree/master/{0}) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] | ||||||
|  | """.format(SKETCH_NAME, SKETCH_NAME[1:], OUTPUT) | ||||||
|  |     ) | ||||||
										
											Plik binarny nie jest wyświetlany.
										
									
								
							| Po Szerokość: | Wysokość: | Rozmiar: 95 KiB | 
										
											Plik binarny nie jest wyświetlany.
										
									
								
							| Po Szerokość: | Wysokość: | Rozmiar: 85 KiB | 
										
											Plik binarny nie jest wyświetlany.
										
									
								
							| Po Szerokość: | Wysokość: | Rozmiar: 224 KiB | 
										
											Plik binarny nie jest wyświetlany.
										
									
								
							| Po Szerokość: | Wysokość: | Rozmiar: 102 KiB | 
		Ładowanie…
	
		Reference in New Issue
	
	 Alexandre B A Villares
						Alexandre B A Villares