#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Twinkle, twinkle, little star

edited December 2011 Posts: 622

I've been more in the mood for snippets with effects rather than even a small project.

Here are some simple stars in the sky for a background.

Here is a still but they do twinkle if you run this.

```-- Twinkle
function setup()
st = {}
ns = 100 -- number of stars
for i = 1,ns do
if math.random(2) == 1 then g = .25 else g = -.25 end
l = 5 + (math.random(39)/4)
st[i] = {g=g,l=l,x=math.random(WIDTH),y=math.random(HEIGHT)}
end
end

function draw()
rect(0,0,1,1)
background(20, 46, 181, 255)
strokeWidth(3)
lineCapMode(SQUARE)
stroke(255, 255, 255, 255)
fill(255, 255, 255, 255)
for i = 1,ns do
if st[i].l <= 5 and math.random(2) == 1 then st[i].g = .25
elseif st[i].l >= 15 and math.random(2) == 1 then st[i].g = -.25 end
st[i].l = st[i].l + st[i].g
ll = (15 - st[i].l)/2
line(st[i].x-st[i].l,st[i].y,st[i].x+st[i].l,st[i].y)
line(st[i].x,st[i].y-st[i].l,st[i].x,st[i].y+st[i].l)
line(st[i].x-ll,st[i].y-ll,st[i].x+ll,st[i].y+ll)
line(st[i].x+ll,st[i].y-ll,st[i].x-ll,st[i].y+ll)
ellipse(st[i].x,st[i].y,6,6)
end
end
```
Tagged:

• Posts: 21

Nice, good as background image:
screenshot

• Posts: 622

• Posts: 381

Nice! Would be better if it has Twinkle Stars song as the music background.

• Posts: 384
• Posts: 21

Ipda41001 sorry, blocks not ready yet.

• Posts: 622

@Fred nice

• Posts: 381

Thank you, @Fred. I knew you will come up.