kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
a08714d913
commit
6e717fb2de
|
@ -0,0 +1,19 @@
|
|||
|
||||
|
||||
class Ponto():
|
||||
|
||||
SIZE = 5
|
||||
|
||||
def __init__(self, x, y):
|
||||
self.ox = x
|
||||
self.oy = y
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.f = 255
|
||||
|
||||
def __getitem__(self, i):
|
||||
return (self.x, self.y)[i]
|
||||
|
||||
def draw(self):
|
||||
fill(self.f)
|
||||
circle(self.x, self.y, Ponto.SIZE)
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 268 KiB |
|
@ -0,0 +1,87 @@
|
|||
from random import sample
|
||||
from itertools import product
|
||||
|
||||
from villares.line_geometry import * # github.com/villares/villares
|
||||
|
||||
from ponto import Ponto
|
||||
|
||||
BORDER = 100
|
||||
SIZE = 50
|
||||
|
||||
pontos = []
|
||||
dragg = []
|
||||
|
||||
def setup():
|
||||
global grid
|
||||
size(400, 400)
|
||||
grid = list(product(range(BORDER, height - BORDER + 1, SIZE),
|
||||
range(BORDER, height - BORDER + 1, SIZE)))
|
||||
|
||||
make_points()
|
||||
|
||||
|
||||
|
||||
def draw():
|
||||
background(200)
|
||||
|
||||
if len(dragg) == 2:
|
||||
d_line = Line(*dragg)
|
||||
strokeWeight(0.5)
|
||||
d_line.draw()
|
||||
lines = inter_lines(d_line, pontos)
|
||||
for inter_line in lines:
|
||||
strokeWeight(2)
|
||||
inter_line.draw()
|
||||
|
||||
|
||||
noFill()
|
||||
strokeWeight(1)
|
||||
beginShape()
|
||||
for p in pontos:
|
||||
vertex(p.x, p.y)
|
||||
endShape(CLOSE)
|
||||
|
||||
|
||||
for p in pontos:
|
||||
if len(dragg) == 2:
|
||||
if area(p, dragg[0], dragg[1]) > 0:
|
||||
p.f = color(255, 0, 0)
|
||||
else:
|
||||
p.f = color(0, 0, 255)
|
||||
else:
|
||||
p.f = 255
|
||||
p.draw()
|
||||
|
||||
|
||||
def keyPressed():
|
||||
if key == ' ': make_points()
|
||||
if key == 'm': move_points()
|
||||
|
||||
def mousePressed():
|
||||
dragg[:] = [(mouseX, mouseY)]
|
||||
|
||||
def mouseDragged():
|
||||
if len(dragg) == 1:
|
||||
dragg.append((mouseX, mouseY))
|
||||
else:
|
||||
dragg[1] = (mouseX, mouseY)
|
||||
|
||||
def area(p0, p1, p2):
|
||||
a = (p1[0] * (p2[1] - p0[1]) +
|
||||
p2[0] * (p0[1] - p1[1]) +
|
||||
p0[0] * (p1[1] - p2[1]))
|
||||
return a
|
||||
|
||||
# def mouseReleased():
|
||||
# dragg[:] = []
|
||||
|
||||
|
||||
def make_points():
|
||||
pontos[:] = []
|
||||
for x, y in sample(grid, 6):
|
||||
pontos.append(Ponto(x, y))
|
||||
|
||||
def make_points():
|
||||
pontos[:] = []
|
||||
for x, y in sample(grid, 6):
|
||||
pontos.append(Ponto(x, y))
|
|
@ -26,6 +26,12 @@ Some of the tools I have used:
|
|||
|
||||
---
|
||||
|
||||

|
||||
|
||||
[sketch_2020_09_22a](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_09_22a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
||||
---
|
||||
|
||||

|
||||
|
||||
[sketch_2020_09_21a](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_09_21a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
|
Ładowanie…
Reference in New Issue