Skip to content

Instantly share code, notes, and snippets.

@absoIute
Last active April 7, 2018 17:23
Show Gist options
  • Save absoIute/9661a29a14f59c28ed6023e2ef09d723 to your computer and use it in GitHub Desktop.
Save absoIute/9661a29a14f59c28ed6023e2ef09d723 to your computer and use it in GitHub Desktop.
_mid = 512
_rate = 0
_freq = 0.01
_circle_count = 30
_circle_width = _mid/_circle_count
_circle_offset = 0
_tri_count = 15
_tri_width = _mid/_tri_count
_tri_offset = 0
_rot = 0
_multiplier = 0.02
def setup():
size(_mid, _mid)
noStroke()
frameRate(60)
def equilateral(x, y, s, angle, graphics):
if s >= 0:
h = w = s
wr = w*.5
hr = h*.5
v = [0, 0, 0, 0, 0, 0]
for i in range(0, 6, 2):
angle += 2*THIRD_PI
v[i] = x + wr*cos(angle);
v[i+1] = y + hr*sin(angle);
graphics.triangle(v[0], v[1], v[2], v[3], v[4], v[5])
def draw():
global _circle_offset, _tri_offset, _rot, _multiplier, _freq, _rate
clear()
background(0xff, 0xff, 0xff)
rgb = []
for i in range(0, _circle_count*4, 4):
r = sin(_freq*(_rate+i)) * 0x7f + 0x80
g = sin(_freq*(_rate+i) + 2) * 0x7f + 0x80
b = sin(_freq*(_rate+i) + 4) * 0x7f + 0x80
rgb.append((r, g, b))
_rate += 4
circle = createGraphics(width, height)
circle.noStroke()
triang = createGraphics(width, height)
triang.noStroke()
circle_mask = createGraphics(width, height)
circle_mask.beginDraw()
circle_mask.ellipse(256, 256, _mid, _mid)
circle_mask.endDraw()
tri_mask = createGraphics(width, height)
tri_mask.beginDraw()
equilateral(256, 256, _mid, _multiplier*_rot, tri_mask)
tri_mask.endDraw()
circle.beginDraw()
for i in range(_circle_count - 1, -1, -1):
circle.fill((i%2)*rgb[i][0], (i%2)*rgb[i][1], (i%2)*rgb[i][2])
circle.ellipse(256, 256, i*_circle_width + _circle_offset, i*_circle_width + _circle_offset)
circle.endDraw()
triang.beginDraw()
for i in range(_tri_count+1, 0, -1):
triang.fill((not i%2)*rgb[-i-1][0], (not i%2)*rgb[-i-1][1], (not i%2)*rgb[-i-1][2])
equilateral(256, 256, i*_tri_width - _tri_offset, _multiplier*_rot, triang)
triang.endDraw()
_rot += 1
_circle_offset = (_circle_offset + 2) % (_circle_width * 2)
_tri_offset = (_tri_offset + 2) % (_tri_width * 2)
circle.mask(circle_mask)
triang.mask(tri_mask)
image(circle, 0, 0)
image(triang, 0, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment