Skip to content

Commit

Permalink
sketch 13
Browse files Browse the repository at this point in the history
  • Loading branch information
villares committed Jan 13, 2018
1 parent 80d64c1 commit c6fa215
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 5 deletions.
8 changes: 6 additions & 2 deletions README.md
Expand Up @@ -4,13 +4,17 @@

Hi! I'm [Alexandre Villares](https://abav.lugaralgum.com), let's see if I can make one small program (*sketch*) a day.

![sketch_180113a](sketch_180113a/sketch_180113a.png)

013: [sketch_180113a](https://github.com/villares/sketch-a-day/tree/master/sketch_180113a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] 3D Graph

![s180112](s180112/s180112.png)

012: [s180112](https://github.com/villares/sketch-a-day/tree/master/s180112) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] Better graph take
012: [s180112](https://github.com/villares/sketch-a-day/tree/master/s180112) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] Another Graph Take

![s180111](s180111/s180111.png)

011: [s180111](https://github.com/villares/sketch-a-day/tree/master/s180111) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] Graph take
011: [s180111](https://github.com/villares/sketch-a-day/tree/master/s180111) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] A Graph Take

![s180110](s180110/s180110.png)

Expand Down
6 changes: 3 additions & 3 deletions s180112/s180112.pyde
Expand Up @@ -76,9 +76,9 @@ class Circle:
self.col = c

def mouseMovement(self):
cx = self.x + self.s * 0.5
cy = self.y + self.s * 0.5
maxDist = 200
cx = self.x
cy = self.y
maxDist = 100
dis = dist(cx, cy, mx, my)
ang = atan2(cy - my, cx - mx)
if (dis < maxDist):
Expand Down
2 changes: 2 additions & 0 deletions sketch_180113a/sketch.properties
@@ -0,0 +1,2 @@
mode=Python
mode.id=jycessing.mode.PythonMode
Binary file added sketch_180113a/sketch_180113a.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
156 changes: 156 additions & 0 deletions sketch_180113a/sketch_180113a.pyde
@@ -0,0 +1,156 @@
"""
s180113 3D Graphs!
(c)2018 Alexandre B A Villares
https://abav.lugaralgum.com/sketch-a-day
"""

add_library('peasycam')

mm = 0
Z_INC = 20

def setup():
size(720, 720, P3D)
cam = PeasyCam(this, 500)
generate()
#ellipseMode(CORNER)
colorMode(HSB)

def draw():
global mx, my, mm, time
mm *= 0.95
# if (mm < 0.04) mm *= 0.2
mx = mouseX - width / 2
my = mouseY - height / 2
time = millis() * 0.001
background(190)

#translate(width / 2, height / 2)

for c in circles:
c.update()
for c in circles:
c.showShadow()
for c in circles:
c.showEdges()
for c in circles:
c.show()

# if (frameCount < 200): saveFrame("###.tga") # para salvar frames


def keyPressed():
generate()

# def mouseClicked():
# sub()

def mouseMoved():
global mm
mm += 0.05
sub()

def sub():
for c in circles:
if c.isOn(mx, my):
c.sub()
break


def generate():
global circles
circles = []
circles.append(Circle(-50, -50 , 600, color(random(256), 200, 200)))


class Circle:

def __init__(self, x, y, s, c):
self.edges = set()
self.x = x
self.y = y
self.ix = x
self.iy = y
self.s = s
self.b = 12
self.ncol = color(random(256), 200, 200)
self.col = c
self.z = 0

def mouseMovement(self):
cx = self.x
cy = self.y
maxDist = 50
dis = dist(cx, cy, mx, my)
ang = atan2(cy - my, cx - mx)
if (dis < maxDist):
dd = map(dis, 0, maxDist, 1, 0)
dd = pow(dd, 0.9) * 20 * mm
self.x += cos(ang) * dd
self.y += sin(ang) * dd

def update(self):

self.x = lerp(self.x, self.ix, 0.09)
self.y = lerp(self.y, self.iy, 0.09)
self.col = lerpColor(self.col, self.ncol, 0.05)

self.mouseMovement()

def showShadow(self):
noStroke()
fill(0, 20)
ellipse(self.x , self.y, self.s, self.s)

def showEdges(self):
strokeWeight(3)
stroke(self.col)
for e in self.edges:
line(self.x, self.y, self.z, e.x, e.y, e.z)

def show(self):
stroke(self.col)
fill(self.col)
pushMatrix()
translate(0,0,self.z)
ellipse(self.x, self.y, self.b, self.b)
popMatrix()

def isOn(self, mx, my):
return dist(self.x, self.y, mx, my) < self.s/2

def sub(self):
ms = self.s * 0.5
mms = ms/2
c0 = Circle(self.ix-mms, self.iy+mms, ms, self.col)
c0.edges = self.edges
c0.z = self.z+Z_INC
#replace egges from any child
for c in circles:
if self in c.edges:
c.edges.remove(self)
c.edges.add(c0)
circles.append(c0)

c1 = Circle(self.ix-mms, self.iy-mms, ms, self.col)
c1.x += self.x - self.ix
c1.y += self.y - self.iy
c1.z = self.z+Z_INC
c1.edges.add(c0)
circles.append(c1)

c2 = Circle(self.ix+mms , self.iy-mms, ms, self.col)
c2.x += self.x - self.ix
c2.y += self.y - self.iy
c2.z = self.z+Z_INC
c2.edges.add(c0)
circles.append(c2)

c3 = Circle(self.ix+mms , self.iy+mms , ms, self.col)
c3.x += self.x - self.ix
c3.y += self.y - self.iy
c3.z = self.z+Z_INC
c3.edges.add(c0)
circles.append(c3)

circles.remove(self)

0 comments on commit c6fa215

Please sign in to comment.