Page 10 of 20

Re: Code Doodles!

Posted: Thu Oct 09, 2014 1:35 am
by Zilarrezko
davisdude wrote:I see you watch Coding Math.
Great videos. Very informative.
Yeah, Love him. Pretty much what I wake up every morning hoping for. Not very many prosaic programming concepts and "follow along" videos like his.
HugoBDesigner wrote:Do you mean me? Because I never heard of this channel before :/

EDIT: It's a quite interesting channel, so I think I'll check it more often :)
He was talking about my code doodle before your last one there. It was based off his latest video. I try to apply his videos in an application to something more than what he applied it for, like taking it a bit further. I hope you watch more of it, cause I think he deserves the views.

Re: Code Doodles!

Posted: Thu Oct 09, 2014 2:38 pm
by HugoBDesigner
Well, in case anyone's interested, I updated my "Lights Out" clone. I fixed some stuff there, nothing new...

Re: Code Doodles!

Posted: Thu Nov 27, 2014 8:49 pm
by veethree
So after a pretty long hiatus from programming i've returned and made a useless thing that looks kinda neat.
Image

Then i made another useless thing that looks kinda neat just for good measure. This one is contained in main.lua so i'll just post the code.

Code: Select all

local w, h, f = love.window.getMode()
love.window.setMode(800, 800, f)

screen = {
		width = love.graphics.getWidth(),
		height = love.graphics.getHeight()
	}

love.graphics.setLineWidth(1)
love.graphics.setBackgroundColor(0, 0, 0)

local obj = {}
local count = 128
local orbit_radius = screen.width / 2 / 2
local radius = screen.width / 2 / 2

for i=1, count do
	local a = ((math.pi * 2) / count) * i
	local hue = (255 / count) * i
	local o = {
		x = 0,
		y = 0,
		angle = a,
		rad = radius,
		radius = radius,
		orad = orbit_radius,
		orbit_rad = orbit_radius,
		orbit_speed = 0.5,
		orbit_x = screen.width / 2,
		orbit_y = screen.height / 2,
		color = {
			h = hue,
			s = 255,
			l = 126,
			a = 8
		},
		t = math.pi / 2
	}

	obj[#obj + 1] = o
end

function love.update(dt)
	for i,v in ipairs(obj) do
		v.angle = v.angle + v.orbit_speed * dt
		v.t = v.t + (dt / 2)
		--v.radius = math.abs(math.sin(v.t)) * v.rad
		v.orbit_rad = math.abs(math.sin(v.t)) * v.orad
		v.x = math.cos(v.angle) * v.orbit_rad + v.orbit_x
		v.y = math.sin(v.angle) * v.orbit_rad + v.orbit_y
	end
end

function love.draw()
	love.graphics.setBlendMode("additive")
	for i,v in ipairs(obj) do
		love.graphics.setColor(hsl(v.color.h, v.color.s, v.color.l, v.color.a))
		--love.graphics.circle("fill", v.x, v.y, v.radius)
		local a = v.color.a * 4
		if a > 255 then a = 255 end
		love.graphics.setColor(hsl(v.color.h, v.color.s, v.color.l, a))
		love.graphics.circle("line", v.x, v.y, v.radius)
	end
end

function love.keypressed(key)
	if key == "escape" then love.event.push("quit") end
end

function love.mousepressed(x, y, key)

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

Re: Code Doodles!

Posted: Fri Nov 28, 2014 5:21 am
by undef
It's pretty, I like it :)

Re: Code Doodles!

Posted: Fri Nov 28, 2014 5:38 pm
by Germanunkol
That's a very pretty thing you made, veethree!

Re: Code Doodles!

Posted: Tue Dec 02, 2014 2:25 pm
by BOT-Brad
I made a fun little bezier/quadratic/cubic/... curve creator and thought I'd share it here. The code is a little messy (not optimized at all, but can run fine with even 300+ static points on my crappy laptop), but there are sporadic comments. I hope someone likes it :)

Image

Instructions
Left-Click to add new points
Right-click to remove points
'SPACE' to start and stop the running of the curve creator.
Mousewheel Up and Down to increase/decrease the time the curve is generated in (Defaults to 1 second).
'v' to hide/show the construction lines and points
'p' to pause the construction (when running only).

pretty much none of the controls work when the curve is being generated. You will need to stop the program with 'SPACE' and then make any changes

Hope you like it! I'd love to hear any feedback!

Re: Code Doodles!

Posted: Tue Dec 02, 2014 4:42 pm
by Germanunkol
I've been learning about mass-spring systems and how to numerically solve them. I decided to try it out...

Try playing with the parameters (keys: q, a, w, s, e, d)!

Image
MassSpringSystem.love
(33.67 KiB) Downloaded 244 times
P.S. This can easily be extended for more complex objects, but I'm lazy at the moment, and should get back to studying...

If anyone finds the time, feel free to expand it...

Re: Code Doodles!

Posted: Tue Dec 02, 2014 5:04 pm
by micha
That is much fun. I am wondering: What constraint hinders the whole box from rotating?

Re: Code Doodles!

Posted: Tue Dec 02, 2014 5:56 pm
by Germanunkol
Hm. No constant, just the fact that I implemented it wrong :P

Jokes aside - the example we had in the lecture was only the linear relation between two mass points - I extended it to be 2D, but the two dimensions are currently solved independent of each other. I guess there is a mistake there somewhere.

I'll fiddle around with it some more and if I can't find it, then ask the person giving the lecture.

Thanks for the hint! I hadn't even thought about the fact that it should be rotating.

Re: Code Doodles!

Posted: Tue Dec 16, 2014 7:06 pm
by HugoBDesigner
I was trying a simple image-to-ascii converter. It didn't look so great, but it works, so if anyone wants to use it/fix it/improve it, feel free (credits appreciated but not required).

Image
(disclaimer: I have no rights over this image. I just chose a random 400x400, black-and-white picture on Google)

(Keys: "tab"/"d"/"right" to switch forwards, "shift+tab"/"a"/"left" to switch backwards)