kopia lustrzana https://github.com/villares/sketch-a-day
				
				
				
			
			
			
			
				main
			
			
		
		
							rodzic
							
								
									bba4185fa4
								
							
						
					
					
						commit
						d4177566ca
					
				| 
						 | 
					@ -1,15 +1,15 @@
 | 
				
			||||||
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
 | 
					# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
 | 
				
			||||||
SKETCH_NAME, OUTPUT = "s147", ".gif"  # 180527
 | 
					SKETCH_NAME, OUTPUT = "s148", ".gif"  # 180528
 | 
				
			||||||
 | 
					
 | 
				
			||||||
add_library('gifAnimation')
 | 
					add_library('gifAnimation')
 | 
				
			||||||
from gif_export_wrapper import *
 | 
					from gif_export_wrapper import *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GRID_SIZE = 32
 | 
					GRID_SIZE = 25
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def setup():
 | 
					def setup():
 | 
				
			||||||
    size(500, 500)
 | 
					    size(500, 500)
 | 
				
			||||||
    print_text_for_readme(SKETCH_NAME, OUTPUT)
 | 
					    print_text_for_readme(SKETCH_NAME, OUTPUT)
 | 
				
			||||||
    border = 20
 | 
					    border = 12.5
 | 
				
			||||||
    spacing = (width - border * 2) / GRID_SIZE
 | 
					    spacing = (width - border * 2) / GRID_SIZE
 | 
				
			||||||
    Ponto.spacing = spacing
 | 
					    Ponto.spacing = spacing
 | 
				
			||||||
    for j in range(GRID_SIZE):
 | 
					    for j in range(GRID_SIZE):
 | 
				
			||||||
| 
						 | 
					@ -28,7 +28,7 @@ def draw():
 | 
				
			||||||
        p.update()
 | 
					        p.update()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if frameCount > 100 and not frameCount % 2:
 | 
					    if frameCount > 100 and not frameCount % 2:
 | 
				
			||||||
        gif_export(GifMaker, frames=200, filename=SKETCH_NAME)
 | 
					        pass #gif_export(GifMaker, frames=200, filename=SKETCH_NAME)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Ponto():
 | 
					class Ponto():
 | 
				
			||||||
    PONTOS = []
 | 
					    PONTOS = []
 | 
				
			||||||
| 
						 | 
					@ -38,7 +38,7 @@ class Ponto():
 | 
				
			||||||
        self.y = y
 | 
					        self.y = y
 | 
				
			||||||
        self.px = x
 | 
					        self.px = x
 | 
				
			||||||
        self.py = y
 | 
					        self.py = y
 | 
				
			||||||
        self.link_count = 4
 | 
					        self.link_count = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def set_neighbours(self):
 | 
					    def set_neighbours(self):
 | 
				
			||||||
        self.ort_ngb = []  # orthogonal neighbours
 | 
					        self.ort_ngb = []  # orthogonal neighbours
 | 
				
			||||||
| 
						 | 
					@ -54,36 +54,28 @@ class Ponto():
 | 
				
			||||||
    def update(self):
 | 
					    def update(self):
 | 
				
			||||||
        rx = random(-0.5, 0.5)
 | 
					        rx = random(-0.5, 0.5)
 | 
				
			||||||
        ry = random(-0.5, 0.5)
 | 
					        ry = random(-0.5, 0.5)
 | 
				
			||||||
        if abs(self.px + rx - self.x) < Ponto.spacing * .5:
 | 
					        if abs(self.px + rx - self.x) < Ponto.spacing * .25:
 | 
				
			||||||
            self.px += rx
 | 
					            self.px += rx
 | 
				
			||||||
        if abs(self.py + ry - self.y) < Ponto.spacing * .5:
 | 
					        if abs(self.py + ry - self.y) < Ponto.spacing * .25:
 | 
				
			||||||
            self.py += ry
 | 
					            self.py += ry            
 | 
				
			||||||
        if self.link_count > 8:
 | 
					 | 
				
			||||||
            self.link_count = 8
 | 
					 | 
				
			||||||
        if self.link_count < 0:
 | 
					 | 
				
			||||||
            self.link_count = 0
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
        self.plot()
 | 
					        self.plot()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def plot(self):
 | 
					    def plot(self):
 | 
				
			||||||
 | 
					        self.link_count = 0
 | 
				
			||||||
        for p in self.ngb:
 | 
					        for p in self.ngb:
 | 
				
			||||||
            d = dist(p.px, p.py, self.px, self.py)
 | 
					            d = dist(p.px, p.py, self.px, self.py)
 | 
				
			||||||
            if Ponto.spacing * .9 < d <= Ponto.spacing * 1.2:
 | 
					            if  p in self.ort_ngb and d > Ponto.spacing * 1:
 | 
				
			||||||
                self.link_count += 1
 | 
					 | 
				
			||||||
            elif d < Ponto.spacing * 0.9:
 | 
					 | 
				
			||||||
                self.link_count += 1
 | 
					 | 
				
			||||||
            else:
 | 
					 | 
				
			||||||
                self.link_count -= 1
 | 
					 | 
				
			||||||
        for p in self.ngb:
 | 
					 | 
				
			||||||
            if p.link_count + self.link_count > 3:
 | 
					 | 
				
			||||||
                if p in self.dia_ngb:
 | 
					 | 
				
			||||||
                    stroke(0, 0, 255)
 | 
					 | 
				
			||||||
                else:
 | 
					 | 
				
			||||||
                    stroke(0, 150, 0)
 | 
					                    stroke(0, 150, 0)
 | 
				
			||||||
                line(p.px, p.py, self.px, self.py)
 | 
					                    line(p.px, p.py, self.px, self.py)
 | 
				
			||||||
 | 
					                    self.link_count += 1
 | 
				
			||||||
 | 
					            elif p in self.dia_ngb and d > Ponto.spacing * 1.45:
 | 
				
			||||||
 | 
					                    stroke(0, 0, 255)
 | 
				
			||||||
 | 
					                    line(p.px, p.py, self.px, self.py)
 | 
				
			||||||
 | 
					                    self.link_count += 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if dist(mouseX, mouseY, self.x, self.y) < Ponto.spacing * 2:
 | 
					        if dist(mouseX, mouseY, self.x, self.y) < Ponto.spacing * 2:
 | 
				
			||||||
            fill(255)
 | 
					            fill(255)
 | 
				
			||||||
            textSize(6)
 | 
					            textSize(8)
 | 
				
			||||||
            text(str(self.link_count), self.x, self.y)
 | 
					            text(str(self.link_count), self.x, self.y)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Ładowanie…
	
		Reference in New Issue