I like these, I'll have to try it myself some day.
Sheepolution, your numbering is off, you've got two number 5's in here.
Code Doodles!
- Sheepolution
- Party member
- Posts: 264
- Joined: Mon Mar 04, 2013 9:31 am
- Location: The Netherlands
- Contact:
Re: Code Doodles!
What the hell, you're right. My whole life is a lie now..
Re: Code Doodles!
Hello, This is my first post ever. I kinda made something that could be considered a Code Doodle, it's kinda bad though ... I was wondering if somebody maybe got some tips for me how to make it shorter, or how to make it better or something .. thanks in advance. (space to move btw).
Code: Select all
function love.load()
line = {x1 = 10, y1 = 200, x2 = 10, y2 = 400}
line2 = {x1 = 790, y1 = 200, x2 = 790, y2 = 400}
xspeed = 3000
yspeed = 3000
xspeed2 = 3000
yspeed2 = 3000
end
function love.update(dt)
if love.keyboard.isDown(" ") then
line.x1 = line.x1 + xspeed * dt
if line.x1 > 790 then
xspeed = 0
yspeed = 3000
line.x1 = 791
line.x2 = line.x2 + yspeed * dt
end
if line.x2 > 790 then
line.x2 = 791
yspeed = 0
xspeed = 3000
xspeed = -xspeed
end
if line.x1 < 10 then
line.x1 = 9
xspeed = 0
yspeed = 3000
line.x2 = line.x2 - yspeed * dt
end
if line.x2 < 10 then
line.x2 = 9
yspeed = 0
xspeed = 3000
line.x2 = line.x2 + yspeed * dt
end
-----------------------------------------
line2.x1 = line2.x1 + xspeed2 * dt
if line2.x1 > 790 then
xspeed2 = 0
yspeed2 = 3000
line2.x1 = 791
line2.x2 = line2.x2 + yspeed2 * dt
end
if line2.x2 > 790 then
line2.x2 = 791
yspeed2 = 0
xspeed2 = 3000
xspeed2 = -xspeed2
end
if line2.x1 < 10 then
line2.x1 = 9
xspeed2 = 0
yspeed2 = 3000
line2.x2 = line2.x2 - yspeed2 * dt
end
if line2.x2 < 10 then
line2.x2 = 9
yspeed2 = 0
xspeed2 = 3000
line2.x2 = line2.x2 + yspeed2 * dt
end
end
end
function love.draw()
love.graphics.setColor(math.random(255),math.random(255),math.random(255))
love.graphics.line(line.x1,line.y1,line.x2,line.y2)
love.graphics.circle("fill", line2.x1, line2.y1, 5, 5)
love.graphics.circle("fill", line2.x2, line2.y2, 5, 5)
love.graphics.setColor(math.random(255),math.random(255),math.random(255))
love.graphics.line(line2.x1,line2.y1,line2.x2,line2.y2)
love.graphics.circle("fill", line.x1, line.y1, 5, 5)
love.graphics.circle("fill", line.x2, line.y2, 5, 5)
love.graphics.setColor(255,255,255)
end
Re: Code Doodles!
Colorful noise.
it moves and potentially lags depending on your system.
it moves and potentially lags depending on your system.
Code: Select all
screen = {
width = love.graphics.getWidth(),
height = love.graphics.getHeight()
}
--Settings
local cell_size = 6.25
local width = math.floor(screen.width / cell_size)
local height = math.floor(screen.height / cell_size)
local noise_scale = 0.05
local z_speed = 4
local z = 0
local grid = {}
function love.load()
for y=0, height-1 do
grid[y] = {}
for x=0, width-1 do
grid[y][x] = {
value = 0
}
end
end
end
function love.update(dt)
z = z + z_speed * dt
for y=0, height-1 do
for x=0, width-1 do
grid[y][x].value = love.math.noise(x * noise_scale, y * noise_scale, z * noise_scale) * 255
end
end
love.window.setTitle(love.timer.getFPS())
end
function love.draw()
for y=0, height-1 do
for x=0, width-1 do
local cell = grid[y][x]
love.graphics.setColor(hsl(cell.value, 255, 126, 255))
love.graphics.rectangle("fill", x * cell_size, y * cell_size, cell_size, cell_size)
end
end
end
function love.keypressed(key)
if key == "escape" then love.event.push("quit") end
end
function hsl(h, s, l, a)
if s<=0 then return l,l,l,a end
h, s, l = h/256*6, s/255, l/255
local c = (1-math.abs(2*l-1))*s
local x = (1-math.abs(h%2-1))*c
local m,r,g,b = (l-.5*c), 0,0,0
if h < 1 then r,g,b = c,x,0
elseif h < 2 then r,g,b = x,c,0
elseif h < 3 then r,g,b = 0,c,x
elseif h < 4 then r,g,b = 0,x,c
elseif h < 5 then r,g,b = x,0,c
else r,g,b = c,0,x
end return (r+m)*255,(g+m)*255,(b+m)*255,a
end
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: Code Doodles!
My first: Blobs
Code: Select all
--[[ CODE DOODLE #1 by DaedalusYoung ]]--
--[[ Blobs ]]--
local colour = {}
local blobs = {}
local spawning = true
local width, height = 800, 600
function colour.alpha(t, a)
local r, g, b = unpack(t)
a = a or 127
return { r, g, b, a }
end
local function makeblob(size)
size = size or 50
return { colour = love.math.random(15), x = love.math.random(-200, width + 200), y = love.math.random(-150, height + 150), size = love.math.random(size / 2.5, size), decayspeed = love.math.random(1, 15), wait = love.math.random(5) }
end
local function randomcolour()
return { (love.math.random(8) * 16) + 127, (love.math.random(8) * 16) + 127, (love.math.random(8) * 16) + 127 }
end
function love.load()
width, height = love.window.getWidth(), love.window.getHeight()
for x = 1, 15 do
colour[x] = randomcolour()
end
for x = 1, 200 do
blobs[x] = makeblob(love.math.random(50))
end
end
function love.update(dt)
local zeroblobs = 0
for x = 1, 200 do
blobs[x].size = blobs[x].size - (dt * blobs[x].decayspeed)
blobs[x].x = blobs[x].x + (400 - blobs[x].x) * (dt / (blobs[x].size / 2))
blobs[x].y = blobs[x].y + (300 - blobs[x].y) * (dt / (blobs[x].size / 2))
blobs[x].decayspeed = blobs[x].decayspeed + (dt * 4)
if blobs[x].size <= 0 then
blobs[x].size = 0
if spawning then
blobs[x].wait = blobs[x].wait - dt
if blobs[x].wait <= 0 then
blobs[x] = makeblob()
end
else
zeroblobs = math.floor(zeroblobs + 1.5)
end
end
end
if zeroblobs == 200 then
for x = 1, 15 do
colour[x] = randomcolour()
end
for x = 1, 200 do
blobs[x] = makeblob(love.math.random(50))
end
spawning = true
end
end
function love.draw()
love.graphics.setBlendMode('additive')
for x = 1, 200 do
love.graphics.setColor(colour.alpha(colour[blobs[x].colour], blobs[x].size * 5.1))
love.graphics.circle('fill', blobs[x].x, blobs[x].y, blobs[x].size, blobs[x].size * 0.75)
love.graphics.setColor(255,255,255, blobs[x].size * 2.55)
love.graphics.circle('fill', blobs[x].x - (blobs[x].size * 0.3), blobs[x].y - (blobs[x].size * 0.3), blobs[x].size * 0.5, blobs[x].size * 0.75)
end
end
function love.mousepressed()
spawning = false
end
Re: Code Doodles!
These are really cool! I need to make some.
- substitute541
- Party member
- Posts: 484
- Joined: Fri Aug 24, 2012 9:04 am
- Location: Southern Leyte, Visayas, Philippines
- Contact:
Re: Code Doodles!
Wooo, springy nodes!
By the way, ridiculous things WILL happen if you set the maxDist variable too high.
Edit 1: Optimized code a bit.
Version 2:
By the way, ridiculous things WILL happen if you set the maxDist variable too high.
Edit 1: Optimized code a bit.
Code: Select all
local screen = {}
function love.load()
screen.width = love.window.getWidth()
screen.height = love.window.getHeight()
nodeList = {}
nodeRadius = 2
numNodes = 100
for i=1, numNodes do
local node = {}
node.x = math.random()*screen.width
node.y = math.random()*screen.height
local v = math.random()*150
local th = math.random()*2*math.pi
node.vx = v*math.cos(th)
node.vy = v*math.sin(th)
nodeList[i] = node
end
phyClock = {}
phyClock.curTime = 0
springConstant = 75
maxDist = 100
end
function love.update(dt)
-- do physics at about 100 frames per second
while phyClock.curTime < dt do
phyClock.curTime = phyClock.curTime + 0.01
for i=1, numNodes do
local A = nodeList[i]
for j=i+1, numNodes do
local B = nodeList[j]
local dx = (A.x-B.x)
local dy = (A.y-B.y)
local dist = dx^2 + dy^2
if dist < maxDist*maxDist then
local ang = math.atan2(dy, dx)
local falloff = 1-dist/(maxDist*maxDist)
local F = springConstant*falloff
A.vx = A.vx - F*math.cos(ang)*0.01
A.vy = A.vy - F*math.sin(ang)*0.01
B.vx = B.vx + F*math.cos(ang)*0.01
B.vy = B.vy + F*math.sin(ang)*0.01
end
end
end
for i=1, numNodes do
local node = nodeList[i]
node.x = node.x + node.vx*0.01
node.y = node.y + node.vy*0.01
if node.x+nodeRadius < 0 then
node.x = screen.width + nodeRadius
elseif node.x-nodeRadius > screen.width then
node.x = -nodeRadius
end
if node.y+nodeRadius < 0 then
node.y = screen.height + nodeRadius
elseif node.y-nodeRadius > screen.height then
node.y = -nodeRadius
end
end
end
phyClock.curTime = phyClock.curTime - dt
end
function love.draw()
for i=1, numNodes do
love.graphics.setColor(255, 255, 255)
local node = nodeList[i]
love.graphics.circle("fill", node.x, node.y, nodeRadius)
for j=i+1, numNodes do
local b = nodeList[j]
local dist = (node.x-b.x)^2 + (node.y-b.y)^2
local falloff = math.max((1-dist/(maxDist*maxDist)), 0)
if falloff > 0 then
--love.graphics.setColor(255, 255, 255, falloff*192)
love.graphics.setColor(HSL(falloff*255, 255, 128, falloff*255))
love.graphics.line(node.x, node.y, b.x, b.y)
end
end
end
end
-- Converts HSL to RGB. (input and output range: 0 - 255)
function HSL(h, s, l, a)
if s<=0 then return l,l,l,a end
h, s, l = h/256*6, s/255, l/255
local c = (1-math.abs(2*l-1))*s
local x = (1-math.abs(h%2-1))*c
local m,r,g,b = (l-.5*c), 0,0,0
if h < 1 then r,g,b = c,x,0
elseif h < 2 then r,g,b = x,c,0
elseif h < 3 then r,g,b = 0,c,x
elseif h < 4 then r,g,b = 0,x,c
elseif h < 5 then r,g,b = x,0,c
else r,g,b = c,0,x
end return (r+m)*255,(g+m)*255,(b+m)*255,a
end
Code: Select all
local screen = {}
function love.load()
screen.width = love.window.getWidth()
screen.height = love.window.getHeight()
nodeList = {}
nodeRadius = 2
numNodes = 150
for i=1, numNodes do
local node = {}
node.x = math.random()*screen.width
node.y = math.random()*screen.height
local v = math.random()*200
local th = math.random()*2*math.pi
node.vx = v*math.cos(th)
node.vy = v*math.sin(th)
nodeList[i] = node
end
phyClock = {}
phyClock.curTime = 0
springConstant = 75
maxDist = 120
curTime = 0
end
function love.update(dt)
-- do physics at about 100 frames per second
curTime = curTime + dt
while phyClock.curTime < dt do
phyClock.curTime = phyClock.curTime + 0.01
for i=1, numNodes do
local A = nodeList[i]
for j=i+1, numNodes do
local B = nodeList[j]
local dx = (A.x-B.x)
local dy = (A.y-B.y)
local dist = dx^2 + dy^2
if dist < maxDist*maxDist then
local ang = math.atan2(dy, dx)
local falloff = 1-dist/(maxDist*maxDist)
local F = springConstant*falloff
A.vx = A.vx - F*math.cos(ang)*0.01
A.vy = A.vy - F*math.sin(ang)*0.01
B.vx = B.vx + F*math.cos(ang)*0.01
B.vy = B.vy + F*math.sin(ang)*0.01
end
end
end
for i=1, numNodes do
local node = nodeList[i]
node.x = node.x + node.vx*0.01
node.y = node.y + node.vy*0.01
if node.x+nodeRadius < 0 then
node.x = screen.width + nodeRadius
elseif node.x-nodeRadius > screen.width then
node.x = -nodeRadius
end
if node.y+nodeRadius < 0 then
node.y = screen.height + nodeRadius
elseif node.y-nodeRadius > screen.height then
node.y = -nodeRadius
end
end
end
phyClock.curTime = phyClock.curTime - dt
end
function love.draw()
love.graphics.setBlendMode("additive")
for i=1, numNodes do
love.graphics.setColor(0, 255, 255)
local node = nodeList[i]
love.graphics.circle("fill", node.x, node.y, nodeRadius)
for j=i+1, numNodes do
local b = nodeList[j]
local dist = (node.x-b.x)^2 + (node.y-b.y)^2
local falloff = math.max((1-dist/(maxDist*maxDist)), 0)
if falloff > 0 then
--love.graphics.setColor(255, 255, 255, falloff*192)
love.graphics.setColor(HSL((falloff*255+curTime*32)%255, 255, 128, falloff*255))
--love.graphics.setLineWidth(falloff*nodeRadius*2)
love.graphics.line(node.x, node.y, b.x, b.y)
end
end
end
end
-- Converts HSL to RGB. (input and output range: 0 - 255)
function HSL(h, s, l, a)
if s<=0 then return l,l,l,a end
h, s, l = h/256*6, s/255, l/255
local c = (1-math.abs(2*l-1))*s
local x = (1-math.abs(h%2-1))*c
local m,r,g,b = (l-.5*c), 0,0,0
if h < 1 then r,g,b = c,x,0
elseif h < 2 then r,g,b = x,c,0
elseif h < 3 then r,g,b = 0,c,x
elseif h < 4 then r,g,b = 0,x,c
elseif h < 5 then r,g,b = x,0,c
else r,g,b = c,0,x
end return (r+m)*255,(g+m)*255,(b+m)*255,a
end
Last edited by substitute541 on Wed Apr 09, 2014 8:51 am, edited 3 times in total.
Currently designing themes for WordPress.
Sometimes lurks around the forum.
Sometimes lurks around the forum.
-
- Party member
- Posts: 712
- Joined: Fri Jun 22, 2012 4:54 pm
- Contact:
Re: Code Doodles!
That's soooo pretty!
Favourite one so far, I think.
Favourite one so far, I think.
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
- Sheepolution
- Party member
- Posts: 264
- Joined: Mon Mar 04, 2013 9:31 am
- Location: The Netherlands
- Contact:
Re: Code Doodles!
Holy shit these are all so cool! It's fun to experiment with them.
Re: Code Doodles!
Code: Select all
function love.load()
points={}
currentPoint=1
end
function love.update(dt)
if love.keyboard.isDown("right") then
points[currentPoint].x=points[currentPoint].x+100*dt
elseif love.keyboard.isDown("left") then
points[currentPoint].x=points[currentPoint].x-100*dt
end
if love.keyboard.isDown("up") then
points[currentPoint].y=points[currentPoint].y-100*dt
elseif love.keyboard.isDown("down") then
points[currentPoint].y=points[currentPoint].y+100*dt
end
end
function love.keypressed(key)
if key=="backspace" then
table.remove(points,currentPoint)
end
if love.keyboard.isDown("lctrl") and key=="tab" then
currentPoint=currentPoint-1
if currentPoint<1 then
currentPoint=#points
end
elseif key=="tab" then
currentPoint=currentPoint+1
if currentPoint>#points then
currentPoint=1
end
end
end
function love.mousepressed(x,y,button)
if button=="l" then
table.insert(points,{x=love.mouse.getX(),y=love.mouse.getY()})
end
end
function love.draw()
for i=1,#points do
love.graphics.setColor(255,0,0)
if i<#points then
love.graphics.line(points[i].x,points[i].y,points[i+1].x,points[i+1].y)
else
love.graphics.line(points[i].x,points[i].y,points[1].x,points[1].y)
if currentPoint==1 then
love.graphics.setColor(255,255,255)
love.graphics.circle("fill",points[1].x,points[1].y,4)
end
end
if currentPoint==i then
love.graphics.setColor(255,255,255)
else
love.graphics.setColor(255,0,0)
end
love.graphics.circle("fill",points[i].x,points[i].y,4)
end
end
- Attachments
-
- main.love
- (615 Bytes) Downloaded 228 times
Who is online
Users browsing this forum: Bing [Bot] and 1 guest