Skip to content

Commit 0dee61a

Browse files
committed
- Rename **OrbitingSquares**, **spinning_top**.
- Update **SpinningTop** to reflect most recent commits in the HYPE version. - Add HYPE version of **SpinningTop**. - Add **TwentyfiveSquares**.
1 parent 21ae3c7 commit 0dee61a

17 files changed

+3291
-17
lines changed

OrbitingSquares/OrbitingSquares.pyde renamed to OrbitingSquares_HYPE/OrbitingSquares_HYPE.pyde

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ from rectcallback import RectCallback
2626

2727

2828
def setup():
29-
size(800, 800)
29+
size(512, 512)
3030
util.centerX = width / 2
3131
util.centerY = height / 2
32+
frameRate(30)
3233
H.init(this).background(0xff595E6E) # #595E6E
3334
smooth()
3435
util.colorfield = (HColorField(width, height)
@@ -47,3 +48,6 @@ def setup():
4748

4849
def draw():
4950
H.drawStage()
51+
saveFrame('C:/Users/IBM_ADMIN/Documents/frames/####.tif')
52+
if frameCount == 900:
53+
exit()

OrbitingSquares/rectcallback.py renamed to OrbitingSquares_HYPE/rectcallback.py

Lines changed: 1 addition & 1 deletion
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(35, 60))\
19+
.size(random(22, 38))\
2020
.rounding(2)\
2121
.rotation(random(360))\
2222
.loc(creationX, creationY)\

OrbitingSquares/util.py renamed to OrbitingSquares_HYPE/util.py

Lines changed: 5 additions & 5 deletions
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, 35)
25+
radius = chooseOrbit() + randint(0, 22)
2626
createX = centerX + (cos(angle) * radius) # `angle` *must* be radians.
2727
createY = centerY + (sin(angle) * radius) #
2828
return createX, createY
@@ -34,13 +34,13 @@ def chooseOrbit():
3434
"""
3535
chance = random(1)
3636
if chance < 0.18:
37-
return 100
37+
return 64
3838
elif chance < 0.50:
39-
return 200
39+
return 128
4040
elif chance < 0.78:
41-
return 325
41+
return 208
4242
elif chance < 1.0:
43-
return 450
43+
return 288
4444

4545

4646
def applyRotation(obj, speed, tolerance):

spinning_top/spinning_top.pyde renamed to SpinningTop/SpinningTop.pyde

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,22 @@ from getPaletteCSV import getPaletteCSV
1313
from top import Top
1414

1515
Top.Palette = getPaletteCSV('Less-Angry_Rainbow_hex.csv')
16+
Top.StrokeWeight = 2
17+
Top.Radius = 1.5
1618
top = None
1719

1820

1921
def setup():
20-
size(800, 800)
22+
size(800, 800, OPENGL)
23+
frameRate(60)
2124
# Initial position in the center of the screen.
2225
top = Top(width / 2, height / 2)
23-
strokeWeight(1)
26+
ellipseMode(RADIUS)
2427
smooth()
2528

2629

2730
def draw():
28-
fill(255, 10)
31+
fill(0, 10)
2932
noStroke()
3033
rect(0, 0, width, height)
3134
top.move(width, height, radians(frameCount))
File renamed without changes.
File renamed without changes.

spinning_top/top.py renamed to SpinningTop/top.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ class Top(object):
33
Palette = []
44
MinDelta = 0.5
55
MaxDelta = 1
6+
StrokeWeight = 1
7+
Radius = 0.5
68

79
def __init__(self, x, y):
810
self.pathX = x
@@ -55,27 +57,28 @@ def drawMe(self):
5557
tipColor = Top.getColor(self.findAngle('tip'))
5658
handColor = Top.getColor(self.findAngle('hand'))
5759
fill(tipColor)
58-
ellipse(self.tipX, self.tipY, 3, 3)
60+
ellipse(self.tipX, self.tipY, Top.Radius, Top.Radius)
5961
fill(handColor)
60-
ellipse(self.handX, self.handY, 3, 3)
62+
ellipse(self.handX, self.handY, Top.Radius, Top.Radius)
63+
strokeWeight(Top.StrokeWeight)
6164
stroke(lerpColor(tipColor, handColor, 0.5))
6265
line(self.tipX, self.tipY, self.handX, self.handY)
6366

6467
# For debug.
6568
def drawMeNot(self):
6669
noStroke()
6770
fill(0, 0, 255)
68-
ellipse(self.pathX, self.pathY, 3, 3)
71+
ellipse(self.pathX, self.pathY, Top.Radius, Top.Radius)
6972
fill(0, 255, 0)
70-
ellipse(self.tipX, self.tipY, 3, 3)
73+
ellipse(self.tipX, self.tipY, Top.Radius, Top.Radius)
7174
fill(255, 0, 0)
72-
ellipse(self.handX, self.handY, 3, 3)
75+
ellipse(self.handX, self.handY, Top.Radius, Top.Radius)
7376

7477
@classmethod
75-
def getColor(cls, index):
78+
def getColor(cls, angle):
7679
# Map the range of angles to the range of the entire palette.
7780
# We retrieve the color as rgb.
78-
r, g, b = Top.Palette[int(map(index, 0, TAU, 0, 817))].rgb
81+
r, g, b = Top.Palette[int(map(angle, 0, TAU, 0, 945))].rgb
7982

8083
# Convert color elements from `float` to `int`.
8184
return color(r * 255, g * 255, b * 255)

SpinningTop_HYPE/SpinningTop_HYPE.pde

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Creative Coding
3+
* Week 3, 04 - spinning top: curved motion with sin() and cos()
4+
* by Indae Hwang and Jon McCormack
5+
* Copyright (c) 2014 Monash University
6+
*
7+
* This sketch is the first cut at translating the motion of a spinning top
8+
* to trace a drawing path. This sketch traces a path using sin() and cos()
9+
*
10+
*/
11+
12+
float x, y; // current drawing position
13+
float dx, dy; // change in position at each frame
14+
float rad; // radius for the moving hand
15+
16+
void setup() {
17+
size(500, 500);
18+
19+
// initial position in the centre of the screen
20+
x = width/2;
21+
y = height/2;
22+
23+
// dx and dy are the small change in position each frame
24+
dx = random(-1, 1);
25+
dy = random(-1, 1);
26+
}
27+
28+
29+
void draw() {
30+
fill(#202020, 10);
31+
noStroke();
32+
rect(0, 0, width, height);
33+
rad = radians(frameCount);
34+
35+
// calculate new position
36+
x += dx;
37+
y += dy;
38+
39+
float max = 1;
40+
float min = 0.5;
41+
42+
//When the shape hits the edge of the window, it reverses its direction and changes velocity
43+
if (x > width-100 || x < 100) {
44+
dx = dx > 0 ? -random(min, max) : random(min, max);
45+
}
46+
47+
if (y > height-100 || y < 100) {
48+
dy = dy > 0 ? -random(min, max) : random(min, max);
49+
}
50+
51+
float bx = x + 100 * sin(rad);
52+
float by = y + 100 * cos(rad);
53+
54+
fill(180);
55+
56+
float radius = 100 * sin(rad*0.1);
57+
float handX = bx + radius * sin(rad*3);
58+
float handY = by + radius * cos(rad*3);
59+
60+
stroke(255, 100);
61+
// line(bx, by, handX, handY);
62+
ellipse(handX, handY, 2, 2);
63+
}
64+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'''
2+
Adapted from:
3+
Creative Coding
4+
Week 3, 04 - spinning top: curved motion with sin() and cos()
5+
by Indae Hwang and Jon McCormack
6+
Copyright (c) 2014 Monash University
7+
8+
This sketch is the first cut at translating the motion of a spinning top
9+
to trace a drawing path. This sketch traces a path using sin() and cos()
10+
11+
and ported to Processing.py/Processing 2.1/HYPE
12+
by Ben Alkov, 30 July - 8 Sept 2014
13+
14+
The only thing left from the original sketch is the math describing the motion.
15+
'''
16+
17+
from hype.core.util import H
18+
from hype.extended.drawable import HCanvas
19+
20+
from getPaletteCSV import getPaletteCSV
21+
22+
from top import Top
23+
24+
25+
Top.Palette = getPaletteCSV('Less-Angry_Rainbow_hex.csv')
26+
Top.StrokeWeight = 2
27+
Top.Radius = 1.5
28+
top = None
29+
30+
31+
def setup():
32+
size(512, 512, OPENGL)
33+
frameRate(30)
34+
H.init(this).background(0xff000000)
35+
smooth()
36+
canvas = H.add(HCanvas()).autoClear(False).fade(1)
37+
# Initial position in the center of the screen.
38+
top = Top(width / 2, height / 2)
39+
canvas.add(top.lineDrawable)
40+
canvas.add(top.handDrawable)
41+
canvas.add(top.tipDrawable)
42+
43+
44+
def draw():
45+
top.update(width, height, radians(frameCount))
46+
H.drawStage()
47+
saveFrame('C:/Users/IBM_ADMIN/Documents/frames/####.tif')
48+
if frameCount == 900:
49+
exit()

0 commit comments

Comments
 (0)