Circles - Live art/background

Tilt to move the circles


--# Main
-- Circs
displayMode(OVERLAY)
displayMode(FULLSCREEN)
supportedOrientations(CurrentOrientation)
-- Use this function to perform your initial setup
function setup()
    minRad,maxRad=20,60
    circs={}
    for i=1,40 do
        table.insert(circs,
        Circ(vec2(math.random(WIDTH),math.random(HEIGHT)),math.random(minRad,maxRad)))
    end
    --masterCol=color(255,255,0)
end

function draw()
    local freq=0.3
    local i=math.floor(ElapsedTime+0.5)%21
    local r=math.sin(freq*(i)+0)*127+128
    local g=math.sin(freq*(i)+2)*127+128
    local b=math.sin(freq*(i)+4)*127+128
    masterCol=color(r,g,b)
        
    background(0)
    blendMode(ADDITIVE)
    pushStyle()
    fill(masterCol.r,masterCol.g,masterCol.b,math.sin(ElapsedTime*4)*32+65)
    rectMode(CORNER)
    noStroke()
    noSmooth()
    rect(0,0,WIDTH,HEIGHT)
    popStyle()
    for i=1,#circs do
        circs[i]:draw()
    end
end


--# Circ
Circ = class()

function Circ:init(pos,rad)
    self.pos=pos
    self.radius=rad
    self.myCol=color(math.random(0,255),math.random(0,255),math.random(0,255),math.random(50,80))
    self.vel=vec2(0,(minRad+maxRad)/2/self.radius*math.random(2)):rotate(math.rad(math.random(360)))
end

function Circ:draw()
    self.pos = self.pos + vec2(Gravity.x*10,Gravity.y*10) + self.vel
    if self.pos.x<0-self.radius then 
        self.pos.x=WIDTH+self.radius 
    elseif self.pos.x>WIDTH+self.radius then 
        self.pos.x=0-self.radius 
    end
    if self.pos.y<0-self.radius then 
        self.pos.y=HEIGHT+self.radius 
    elseif self.pos.y>HEIGHT+self.radius then 
        self.pos.y=0-self.radius 
    end
    fill(masterCol:mix(self.myCol,0.5))
    noStroke()
    ellipseMode(RADIUS)
    ellipse(self.pos.x,self.pos.y,self.radius)
    noFill()
    stroke(255,100)
    strokeWidth(math.random(1,10))
    for i=1,#circs do
        if circs[i]~=self then 
            local d=self.pos:dist(circs[i].pos)
            if d/2<self.radius+circs[i].radius then
                line(self.pos.x,self.pos.y,circs[i].pos.x,circs[i].pos.y)
            end
        end
    end
end

Nice job!

Thanks :slight_smile:

hypnotic… @-)

Yup @-)