Harmonic Motion

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Harmonic Motion

Post by Nixola »

Here's a .love file my teacher asked me to code, it has a clock, a line that spins and a graph.
Actually I made this post only to ask you: is there a way to make the graph more 'lightly'? It's waaaaaaaaaay too heavy drawin' it like this...
Attachments
Harmonic-0.7.2.love
(14.23 KiB) Downloaded 215 times
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Codex
Party member
Posts: 106
Joined: Tue Mar 06, 2012 6:49 am

Re: Harmonic Motion

Post by Codex »

It's not working for some reason?
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Harmonic Motion

Post by Jasoco »

Works for me. I just don't understand the question. "Lightly"? You mean line thickness? Or color? Because that's all I can gather.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Harmonic Motion

Post by Robin »

If you press "alt", apparently it starts showing a graph. It took me a while to find out.
Help us help you: attach a .love.
User avatar
richapple
Citizen
Posts: 65
Joined: Sun Dec 25, 2011 10:25 am

Re: Harmonic Motion

Post by richapple »

Nixola wrote:is there a way to make the graph more 'lightly'? It's waaaaaaaaaay too heavy drawin' it like this...
I don't clearly understand what you mean, but this is what I did:

The way you draw it:

Code: Select all

for i, v in ipairs(points) do
	love.graphics.circle('fill', v.y, (v.x/2)+332, 1, 4)
end
The way I did it:

Code: Select all

love.graphics.setLineWidth(2)

.. drawing clock and lines

love.graphics.setLineWidth(1)
for i, v in ipairs(points) do
	if i > 1 then
		love.graphics.line(v.y, (v.x/2)+332, points[i-1].y, (points[i-1].x/2)+332)
	end
end
And here's how it looks:
On the left it's how you draw it, by drawing circle every point,
And on the right it's how I draw it, by drawing line through every current and previous point.
Updated, forgot to change line width
Updated, forgot to change line width
comp.png (5.16 KiB) Viewed 2546 times
Looks better, what you think?


Also I think it would be better to shorten this

Code: Select all

if k == '1' or k == '2' or k == '3' or k == '4' or k == '5' or k == '6' or k == '7' or k == '8' or k == '9' then
	speed = tonumber(k)
end
to this:

Code: Select all

if type(tonumber(k)) == "number" then
	speed = k
end
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Harmonic Motion

Post by Robin »

That would be:

Code: Select all

    if type(tonumber(k)) == "number" then
       speed = tonumber(k)
    end
Also, this includes 0, which might not be what the OP wants.

Alternative suggestion:

Code: Select all

    local nk = tonumber(k)
    if type(nk) == "number" and nk > 0 then
       speed = nk
    end
Help us help you: attach a .love.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Harmonic Motion

Post by Nixola »

With 'more lightly' I meant a faster way, 'cause on my netbook (and on my school pcs) showing the graph kills the framerate; that's why I hid the graph by default
(with Ctrl you can hide the variables, and with AltGR you toggle both)
@RichApple and Robin: thanks, I forgot it ^^' I think (and hope) that's faster than 9 ifs
@RichApple only: I decided not to use lines 'cause my pc can't show 1px-wide horizontal or vertical lines, and I forgot that it can show 1px-wide non-horizontal nor vertical lines...
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Harmonic Motion

Post by bartbes »

Code: Select all

local nk = tonumber(k) or k
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Harmonic Motion

Post by tentus »

As I recall, can't love.graphics.line be given any number of coordinates? (Greater than or equal two, of course.) You could change up how the points table works by a little and then pass the whole thing into a single love.graphics.line call.

Here, I've added an example to the wiki that should help you understand. What you'd need to do specifically is replace this:

Code: Select all

table.insert(points, 1, {x = x, y = rtimer*2})
with this:

Code: Select all

points[#points + 1] = rtimer*2
points[#points + 1] = (x / 2) + 332
And then replace this:

Code: Select all

for i, v in ipairs(points) do
	love.graphics.circle('fill', v.y, (v.x/2)+332, 1, 4)
end
with this:

Code: Select all

love.graphics.line(points)
That should render faster. I'm having trouble telling a difference, but then again, I have a full desktop at my disposal- a netbook might see a dramatic improvement.
Kurosuke needs beta testers
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Harmonic Motion

Post by Robin »

bartbes wrote:

Code: Select all

local nk = tonumber(k) or k
You mean

Code: Select all

speed = tonumber(k) or speed
:joker:
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: No registered users and 41 guests