main
Alexandre B A Villares 2020-10-18 17:43:14 -03:00
rodzic f31779c3d0
commit 51c62edcaa
5 zmienionych plików z 200 dodań i 9 usunięć

Wyświetl plik

@ -2,6 +2,7 @@
# Added a GrowingLine class that inherits from Line
from random import choice
# github.com/villares/villares
from villares.line_geometry import Line, point_in_screen
def setup():
@ -27,7 +28,7 @@ def draw():
gl.check_collision(other_gl)
strokeWeight(2)
gl.stroke_from_growth()
# # red line
# red line
# if gl.point_over(int(frameCount) % width, height / 2):
# stroke(255, 0, 0)
gl.draw()
@ -46,7 +47,7 @@ class GrowingLine(Line):
self.grow_b = True
def stroke_from_growth(self):
stroke(200 * self.grow_a, 128, 200 * self.grow_b)
stroke(200 * self.grow_a, 128, 200 * self.grow_b)
def grow(self):
v = PVector(*self.a) - PVector(*self.b)
@ -63,19 +64,19 @@ class GrowingLine(Line):
# circle(self.b.x, self.b.y, 3)
def check_collision(self, other):
if self is not other:
if self is not other:
if self.grow_a and other.contains_point(self.a.x,
self.a.y,
tolerance=0.01):
self.grow_a = False
if self.grow_b and other.contains_point(self.b.x,
self.b.y,
tolerance=0.01):
self.grow_b = False
def check_screen_limit(self):
if self.grow_a and not point_in_screen(self.a):
self.grow_a = False
if self.grow_b and not point_in_screen(self.b):
self.grow_b = False
if self.grow_a and not point_in_screen(self.a):
self.grow_a = False
if self.grow_b and not point_in_screen(self.b):
self.grow_b = False

Wyświetl plik

@ -0,0 +1,92 @@
from random import choice
from villares.line_geometry import Line, point_in_screen
def setup():
size(400, 400)
generate_lines()
def generate_lines():
global glines
rw = lambda: choice(range(-width / 2, width / 2, 10))
glines = []
while len(glines) < 60:
gl = GrowingLine((rw(), rw()), (rw(), rw()))
for other_gl in glines:
if gl.intersect(other_gl) or gl.a == gl.b:
break
else:
glines.append(gl)
def draw():
fill(0, 10)
rect(0, 0, width, height)
translate(width / 2, height / 2)
# scale(.5)
rotate(frameCount / 200.0)
# background(0)
for gl in glines:
for other_gl in glines:
gl.check_collision(other_gl)
strokeWeight(2)
gl.stroke_from_growth()
# red line
# if gl.point_over(int(frameCount) % width, height / 2):
# stroke(255, 0, 0)
gl.draw()
gl.check_screen_limit()
gl.grow()
def keyPressed():
if key == ' ':
generate_lines()
class GrowingLine(Line):
def __init__(self, *args):
Line.__init__(self, *args)
self.grow_a = True
self.grow_b = True
def stroke_from_growth(self):
stroke(200 * self.grow_a, 128, 200 * self.grow_b)
def grow(self):
v = PVector(*self.a) - PVector(*self.b)
v.normalize()
# noStroke()
# fill(0, 255, 200)
if self.grow_a:
self.a += v / 2.0
# else:
# circle(self.a.x, self.a.y, 3)
if self.grow_b:
self.b -= v / 2.0
# else:
# circle(self.b.x, self.b.y, 3)
def check_collision(self, other):
if self != other:
if self.grow_a and other.contains_point(self.a.x,
self.a.y,
tolerance=0.01):
self.grow_a = False
# glines.remove(other)
# glines.append(GrowingLine(self.a, other.b))
if self.grow_b and other.contains_point(self.b.x,
self.b.y,
tolerance=0.01):
self.grow_b = False
# if other in glines: glines.remove(other)
# glines.append(GrowingLine(other.a, self.b))
# else:
# glines.remove(self)
def check_screen_limit(self):
sp = lambda p: PVector(screenX(p.x, p.y), screenY(p.x, p.y))
if self.grow_a and not point_in_screen(sp(self.a)):
self.grow_a = False
if self.grow_b and not point_in_screen(sp(self.b)):
self.grow_b = False

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 1.5 MiB

Wyświetl plik

@ -0,0 +1,92 @@
from random import choice
from villares.line_geometry import Line, point_in_screen
def setup():
size(400, 400)
generate_lines()
def generate_lines():
global glines
rw = lambda: choice(range(-width / 2, width / 2, 10))
glines = []
while len(glines) < 60:
gl = GrowingLine((rw(), rw()), (rw(), rw()))
for other_gl in glines:
if gl.intersect(other_gl) or gl.a == gl.b:
break
else:
glines.append(gl)
def draw():
fill(0, 10)
rect(0, 0, width, height)
translate(width / 2, height / 2)
# scale(.5)
rotate(frameCount / 200.0)
# background(0)
for gl in glines:
for other_gl in glines:
gl.check_collision(other_gl)
strokeWeight(2)
gl.stroke_from_growth()
# red line
# if gl.point_over(int(frameCount) % width, height / 2):
# stroke(255, 0, 0)
gl.draw()
gl.check_screen_limit()
gl.grow()
def keyPressed():
if key == ' ':
generate_lines()
class GrowingLine(Line):
def __init__(self, *args):
Line.__init__(self, *args)
self.grow_a = True
self.grow_b = True
def stroke_from_growth(self):
stroke(200 * self.grow_a, 128, 200 * self.grow_b)
def grow(self):
v = PVector(*self.a) - PVector(*self.b)
v.normalize()
# noStroke()
# fill(0, 255, 200)
if self.grow_a:
self.a += v / 2.0
# else:
# circle(self.a.x, self.a.y, 3)
if self.grow_b:
self.b -= v / 2.0
# else:
# circle(self.b.x, self.b.y, 3)
def check_collision(self, other):
if self != other:
if self.grow_a and other.contains_point(self.a.x,
self.a.y,
tolerance=0.01):
self.grow_a = False
# glines.remove(other)
# glines.append(GrowingLine(self.a, other.b))
if self.grow_b and other.contains_point(self.b.x,
self.b.y,
tolerance=0.01):
self.grow_b = False
# if other in glines: glines.remove(other)
# glines.append(GrowingLine(other.a, self.b))
# else:
# glines.remove(self)
def check_screen_limit(self):
sp = lambda p: PVector(screenX(p.x, p.y), screenY(p.x, p.y))
if self.grow_a and not point_in_screen(sp(self.a)):
self.grow_a = False
if self.grow_b and not point_in_screen(sp(self.b)):
self.grow_b = False

Wyświetl plik

@ -26,6 +26,12 @@ Here are listed some of the tools I have been using:
---
![sketch_2020_10_18b](2020/sketch_2020_10_18b/sketch_2020_10_18b.gif)
[sketch_2020_10_18b](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_10_18b) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
---
![sketch_2020_10_17a](2020/sketch_2020_10_17a/sketch_2020_10_17a.gif)
[sketch_2020_10_17a](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_10_17a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]