Skip to content

Commit 069232a

Browse files
committed
Mass update
Yeah, so much for incremental
1 parent 1ca0b23 commit 069232a

23 files changed

+812
-133
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
Handles.
3+
4+
Click and drag the white boxes to change their position.
5+
"""
6+
from handle import Handle
7+
8+
9+
def setup():
10+
size(640, 360)
11+
num = height / 15
12+
hsize = 10
13+
for i in range(num):
14+
Handle(width / 2, 10 + i * 15, 50 - hsize / 2, 10)
15+
16+
17+
def draw():
18+
background(153)
19+
for h in Handle.handles:
20+
h.update()
21+
h.display()
22+
fill(0)
23+
rect(0, 0, width / 2, height)
24+
25+
26+
def mouseReleased():
27+
for h in Handle.handles:
28+
h.releaseEvent()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
class Handle(object):
2+
3+
handles = []
4+
5+
def __init__(self, x, y, stretch, size):
6+
self.x = x
7+
self.y = y
8+
self.stretch = stretch
9+
self.size = size
10+
self.boxX = self.x + self.stretch - self.size / 2
11+
self.boxY = self.y - self.size / 2
12+
self.over = False
13+
self.press = False
14+
self.locked = False
15+
self.othersLocked = False
16+
Handle.handles.append(self)
17+
18+
def update(self):
19+
self.boxX = self.x + self.stretch
20+
self.boxY = self.y - self.size / 2
21+
22+
self.othersLocked = False
23+
for handle in Handle.handles:
24+
if handle.locked:
25+
self.othersLocked = True
26+
break
27+
if not self.othersLocked:
28+
self.overEvent()
29+
self.pressEvent()
30+
if self.press:
31+
self.stretch = constrain(mouseX - width / 2 - self.size / 2,
32+
0, width / 2 - self.size - 1)
33+
34+
def overEvent(self):
35+
self.over = overRect(self.boxX, self.boxY, self.size, self.size)
36+
37+
def pressEvent(self):
38+
if self.over and mousePressed or self.locked:
39+
self.press = True
40+
self.locked = True
41+
else:
42+
self.press = False
43+
44+
def releaseEvent(self):
45+
self.locked = False
46+
47+
def display(self):
48+
line(self.x, self.y, self.x + self.stretch, self.y)
49+
fill(255)
50+
stroke(0)
51+
rect(self.boxX, self.boxY, self.size, self.size)
52+
if self.over or self.press:
53+
line(self.boxX, self.boxY,
54+
self.boxX + self.size, self.boxY + self.size)
55+
line(self.boxX, self.boxY + self.size,
56+
self.boxX + self.size, self.boxY)
57+
58+
59+
def overRect(x, y, width, height):
60+
return x <= mouseX <= x + width and y <= mouseY <= y + height

Crawlers/Crawlers.pyde

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from crawler import Crawler
2+
3+
# TODO:
4+
# - Get Width, Height from image.
5+
6+
Width = 1024
7+
Height = 680
8+
HalfWidth = Width / 2.0
9+
HalfHeight = Height / 2.0
10+
Crawler.HalfWidth = HalfWidth
11+
Crawler.HalfHeight = HalfHeight
12+
NumCrawlers = 30
13+
14+
15+
def rightHanded():
16+
# Fix flippin' coordinate system.
17+
# Not the *same* as right-handed, but good enough.
18+
# `-Z` comes out of the screen.
19+
rotateX(TAU / 2) # Positive `Y` up.
20+
translate(HalfWidth, -HalfHeight, 0) # Centered.
21+
22+
23+
def update():
24+
for c in Crawler.instances:
25+
c.imgColor = img.pixels[int((c.position.y * Width)) + int(c.position.x)]
26+
c.update()
27+
28+
29+
def setup():
30+
global img
31+
size(Width, Height, P3D)
32+
img = loadImage('_DSC5309.jpg')
33+
img.loadPixels()
34+
noStroke()
35+
background(128)
36+
colorMode(HSB, 360, 100, 100)
37+
rightHanded()
38+
for _ in range(NumCrawlers):
39+
Crawler()
40+
41+
42+
def draw():
43+
rightHanded()
44+
update()

Crawlers/crawler.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
class Crawler(object):
3+
4+
HalfWidth = 0
5+
HalfHeight = 0
6+
instances = []
7+
8+
def __init__(self):
9+
self.position = self.rndPositionVector()
10+
self.velocity = PVector(0, 0)
11+
self.accel = PVector(0, 0)
12+
self.color = color(0, 0, 100)
13+
# This property keeps us from needing a global.
14+
self.imgColor = self.color
15+
self.instances.append(self)
16+
17+
def rndPositionVector(self):
18+
x = int(random(-self.HalfWidth, self.HalfWidth))
19+
y = int(random(-self.HalfHeight, self.HalfHeight))
20+
return PVector(x, y)
21+
22+
def update(self):
23+
# Image pixel's saturation becomes crawler's brightness.
24+
self.color = color(0, 0, saturation(self.imgColor))
25+
self.velocity = PVector.fromAngle(hue(self.imgColor))
26+
# Thanks to Shiffman's NOC!
27+
b = brightness(self.imgColor)
28+
if b <= 50:
29+
self.accel.add = b / -10
30+
else:
31+
self.accel.add = b / 10
32+
self.velocity.add(self.accel)
33+
self.position.add(self.velocity)
34+
self.display()
35+
36+
def display(self):
37+
fill(self.color)
38+
# point(self.position.x, self.position.y)
39+
# print('self.position.x = {0}, self.position.y = {1}'
40+
# .format(self.position.x, self.position.y))
41+
ellipse(self.position.x, self.position.y, 2, 2)

Crawlers/data/Color-map-icon.png

78.8 KB
Loading

Crawlers/data/_DSC5309.jpg

413 KB
Loading

Crawlers/data/mischka.png

711 KB
Loading

LTree/LTree.pyde

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from square import Square
2+
3+
4+
baseRadius = 75.0
5+
angleDelta = 5.08
6+
radiusDelta = 1.618
7+
levels = 4
8+
9+
10+
def setup():
11+
size(512, 512, P2D)
12+
global halfWidth, halfHeight, baseSquare, baseLocation
13+
noLoop()
14+
rectMode(CENTER)
15+
shapeMode(CENTER)
16+
halfWidth = width / 2.0
17+
halfHeight = height / 2.0
18+
baseLocation = PVector(halfWidth, height - baseRadius)
19+
baseSquare = Square(baseRadius, position=baseLocation)
20+
baseSquare.display()
21+
22+
23+
# base = Square.squares[0]
24+
# odd indices are RH
25+
# even indices are LH
26+
def draw():
27+
# Append two squares to the list each time through the loop
28+
for i in range(1, levels):
29+
Square(baseRadius / (radiusDelta * i),
30+
PVector(Square.squares[i - 1].position.x,
31+
Square.squares[i - 1].position.y
32+
- Square.squares[i - 1].radius),
33+
angleDelta * i)
34+
Square(baseRadius / (radiusDelta * i),
35+
PVector(Square.squares[i - 1].position.x,
36+
Square.squares[i - 1].position.y
37+
- Square.squares[i - 1].radius),
38+
angleDelta * i)
39+
for s in Square.squares:
40+
print('Index: {0}, rotation: {1}'
41+
.format(Square.squares.index(s), s.rotation))
42+
s.display()

LTree/square.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class Square(object):
2+
''' '''
3+
squares = []
4+
5+
def __init__(self, radius=1, position=PVector(0, 0),
6+
rotation=0):
7+
Square.squares.append(self)
8+
self.radius = radius
9+
self.dia = 2 * self.radius
10+
self.shape = createShape()
11+
self.position = position
12+
if Square.squares.index(self) == 0:
13+
self.color = color(0) # black
14+
self.rotation = rotation
15+
elif Square.squares.index(self) % 2 != 0:
16+
self.color = color(255, 0, 0) # red
17+
self.rotation = rotation
18+
elif Square.squares.index(self) % 2 == 0:
19+
self.color = color(0, 0, 255) # blue
20+
self.rotation = rotation
21+
self.makeSelf()
22+
23+
def makeSelf(self):
24+
self.shape.beginShape(QUADS)
25+
self.shape.fill(self.color)
26+
self.shape.noStroke()
27+
self.shape.vertex(0, 0)
28+
self.shape.vertex(self.dia, 0)
29+
self.shape.vertex(self.dia, self.dia)
30+
self.shape.vertex(0, self.dia)
31+
self.shape.endShape(CLOSE)
32+
33+
def display(self):
34+
resetMatrix()
35+
rotate(radians(self.rotation))
36+
shape(self.shape, self.position.x, self.position.y, self.dia, self.dia)

OrbitingSquares_HYPE/OrbitingSquares_HYPE.pyde

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# add_library('hype')
1+
# add_library('hype')
22
'''
33
1. One hundred `HRect`
44
2. Of randomly-selected size
@@ -16,22 +16,27 @@ Implementation by Ben Alkov 7-12 August 2014
1616
'''
1717
from hype.core.util import H
1818
from hype.extended.colorist import HColorField
19-
from hype.extended.drawable import HGroup
20-
from hype.extended.drawable import HRect
19+
from hype.extended.drawable import HGroup, HRect
20+
21+
from gifAnimation import GifMaker, Gif
2122

2223
import util
2324

2425
from parentcallback import ParentCallback
2526
from rectcallback import RectCallback
2627

28+
gifExport = GifMaker(this, "export.gif")
29+
2730

2831
def setup():
29-
size(512, 512)
32+
size(1080, 1080)
33+
frameRate(24)
34+
gifExport.setRepeat(0) # make it an "endless" animation
35+
# gifExport.setTransparent(255, 255, 255)
3036
util.centerX = width / 2
3137
util.centerY = height / 2
32-
frameRate(30)
3338
H.init(this).background(0xff595E6E) # #595E6E
34-
smooth()
39+
# smooth()
3540
util.colorfield = (HColorField(width, height)
3641
.addPoint(0, util.centerY, 0xff001CDD, 0.7) # #001CDD
3742
.addPoint(width, util.centerY, 0xff71BB00, 0.7) # #71BB00
@@ -48,6 +53,8 @@ def setup():
4853

4954
def draw():
5055
H.drawStage()
51-
# saveFrame('C:/Users/IBM_ADMIN/Documents/frames/####.tif')
52-
# if frameCount == 900:
53-
# exit()
56+
gifExport.setDelay(41)
57+
# gifExport.addFrame()
58+
if frameCount == 480:
59+
gifExport.finish()
60+
exit()

OrbitingSquares_HYPE/rectcallback.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def run(drawable):
1616
drawable.strokeWeight(2)\
1717
.stroke(0xff000000, 196)\
1818
.fill(0xff000000, 100)\
19-
.size(random(22, 38))\
19+
.size(random(int(width / 25), int(width / 16)))\
2020
.rounding(2)\
2121
.rotation(random(360))\
2222
.loc(creationX, creationY)\

OrbitingSquares_HYPE/util.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def positionOnOrbit():
2222
angle = random(TAU)
2323
# `randint` slightly offsets the position so we don't end up with the
2424
# visible HRects orbiting on *exact* circles.
25-
radius = chooseOrbit() + randint(0, 22)
25+
radius = chooseOrbit() + randint(0, int(width / 23))
2626
createX = centerX + (cos(angle) * radius) # `angle` *must* be radians.
2727
createY = centerY + (sin(angle) * radius) #
2828
return createX, createY
@@ -31,32 +31,34 @@ def positionOnOrbit():
3131
def chooseOrbit():
3232
'''
3333
Randomly choose an orbit, based on a set of weights.
34+
The returns can be adjusted to account for a larger / smaller sketch size.
3435
'''
3536
chance = random(1)
3637
if chance < 0.18:
37-
return 64
38+
return width / 8
3839
elif chance < 0.50:
39-
return 128
40+
return width / 4
4041
elif chance < 0.78:
41-
return 208
42+
return width / 2.46
4243
elif chance < 1.0:
43-
return 288
44+
return width / 1.7777
4445

4546

4647
def applyRotation(obj, speed, tolerance):
4748
'''
48-
Attach an HRotate to the given object, with speed `speed`.
49+
Attach an HRotate to the given object, calling `avoidZero` to set the
50+
speed (angular speed in degrees per draw()).
4951
'''
5052
HRotate(obj, avoidZero(speed, tolerance))
5153

5254

5355
# This is specifically used to avoid zero or synchronous rotation. We want all
54-
# visible HRects to *appear* to rotate in place.
56+
# visible HRects to *appear* to rotate "in place".
5557
def avoidZero(limit, tolerance):
5658
'''
57-
Return a random value in the range from `-limit` to `limit - 1`, excluding
58-
the inner range from `-tolerance` to `tolerance - 1` (and, logically, zero
59-
as well).
59+
Return a random value in the range from `-limit` to strictly less than
60+
`limit`, excluding the inner range +/-`tolerance` (and, logically, zero as
61+
well).
6062
'''
6163
value = random(-limit, limit)
6264
while -tolerance < value < tolerance:

0 commit comments

Comments
 (0)