@Ray_Spahn What do you mean by “curve in a different direction” .
@ dave 1707 I meant that having the lines curve Ike a snake but also grow from a certain point and have a tail
Like this picture
http://www.google.com/imgres?imgurl=http://i1.ytimg.com/vi/Vxv2v_Pma1U/mqdefault.jpg&imgrefurl=http://clipne.com/view/stoneocean-anonymous/xC65vhvhPPAHdo8.html&h=180&w=320&tbnid=Gg1Fgy2E0VeiXM:&zoom=1&docid=BGVKeKLNkb18bM&itg=1&ei=AdZ5VOTmPIf2igKAkYGABQ&tbm=isch&ved=0CB4QMygAMAA
I’m sure it can be done, but it will take more time than I want to put into it.
@ dave1707 thank you so much for all you have done especially today
Have a great day and again thank you
@Ray_Spahn - Ah now I have a better idea of what you want.
To be honest I think it’s a fairly complex example, especially if your a new comer to Codea and or programming.
Here’s what I would advise
- Get comfortable with the existing line function
- Get comfortable with using variables to represent the endpoint of a line
- Update those variables so that you can see the line grow and shrink (just keep it to either horizontal or vertical for now)
- Brush up on your maths so you can make a straight line grow and shrink at any given angle (see the sin / cos examples above)
- Brush up on tables so you can have lots of lines all growing and shrinking separately
- Go back to the maths to arrange these lines in a circle
and your pretty much done.
THIS is EXACTLY what I was talking about when I said start with a sketch (or an example video) or an idea of what you want to do and then moving forward step by step
I agree, one step at a time
Right now you are biting off too much
@Ray_Spahn Still not sure if this is what you’re after.
displayMode(FULLSCREEN)
function setup()
count=100
tab={}
end
function draw()
background(255, 184, 0, 255)
count=count+1
if count>30 then
s=math.random(25,50)
count=0
for z=1,360 do
tab[z]=s+math.random(-6,6)
s=tab[z]
end
end
stroke(92, 0, 255, 255)
for z=1,360 do
pushMatrix()
translate(WIDTH/2,HEIGHT/2)
rotate(z)
rect(0,0,3,tab[z]+160)
popMatrix()
end
fill(0, 255, 246, 255)
stroke(255, 0, 166, 255)
strokeWidth(4)
ellipse(WIDTH/2,HEIGHT/2,300)
end
@dave1707 thanks so much for trying again and sticking with working this idea but i was talking about the the link i pasted the lines in the video where the lines grow like you sent me but where they curve and turn into different directions
@dave1707 i was watching the video and thought of how to code that and that is why i am so interestedd in this idea
How about this? (Long press on “new project” and select “paste into project”)
--# Main
-- Circular Spectrum
function setup()
spec = Spectrum(WIDTH / 2, HEIGHT / 2, WIDTH / 4, WIDTH / 16, true, true)
spec2 = Spectrum(WIDTH / 2, HEIGHT / 2, WIDTH / 4, WIDTH / 8, false, false)
spec:generateCache()
spec2:generateCache()
end
function draw()
background(255)
strokeWidth(5)
stroke(0)
for i = 1, 250 do
spec.length[i] = math.max(0, noise(i / 30, i / 30 * math.pi, ElapsedTime * 2) * spec.outer)
spec2.length[i] = math.max(0, noise(i / 15, i / 15 * math.pi, ElapsedTime * 4) * spec2.outer + spec2.outer / 2)
end
spec:draw()
fill(0, 0)
ellipse(WIDTH / 2, HEIGHT / 2, WIDTH / 2 + 7.5, HEIGHT / 2 + 7.5)
spec2:draw()
sprite("Cargo Bot:Codea Icon", WIDTH / 2, HEIGHT / 2, WIDTH / 4 * math.cos(ElapsedTime / math.pi), HEIGHT / 4)
end
--# Spectrum
Spectrum = class()
function Spectrum:init(x, y, inner, outer, continuous, invert)
self.x, self.y = x, y
self.inner, self.outer = inner, outer
self.continuous, self.invert = continuous, invert
self.length = {}
for i = 1, 2 do
self.length[i] = 0
end
self:generateCache()
end
function Spectrum:generateCache()
self.angleCache = {}
for i = 1, #self.length - 1 do
local prog1 = (i - 1) / (#self.length)
local prog2 = (i) / (#self.length)
local rad1 = math.pi * 2 * prog1
local rad2 = math.pi * 2 * prog2
local sin1 = math.sin(rad1)
local cos1 = math.cos(rad1)
local sin2 = math.sin(rad2)
local cos2 = math.cos(rad2)
self.angleCache[i] = {s1 = sin1, c1 = cos1, s2 = sin2, c2 = cos2}
end
end
function Spectrum:draw()
if #self.length ~= #self.angleCache then
self:generateCache()
end
local mult = 1
if self.invert then
mult = -1
end
for i = 1, #self.length - 1 do
local sin1 = self.angleCache[i].s1
local cos1 = self.angleCache[i].c1
local sin2 = self.angleCache[i].s2
local cos2 = self.angleCache[i].c2
if self.continuous then
line(sin1 * self.inner + sin1 * self.length[i] * mult + self.x, cos1 * self.inner + cos1 * self.length[i] * mult + self.y, sin2 * self.inner + sin2 * self.length[i + 1] * mult + self.x, cos2 * self.inner + cos2 * self.length[i + 1] * mult + self.y)
else
line(sin1 * self.inner + self.x, cos1 * self.inner + self.y, sin1 * self.inner + sin1 * self.length[i] * mult + self.x, cos1 * self.inner + cos1 * self.length[i] * mult + self.y)
end
end
local rad1 = math.pi * 2 * ((#self.length - 1) / #self.length)
local rad2 = 0
local sin1 = self.angleCache[#self.length - 1].s2
local cos1 = self.angleCache[#self.length - 1].c2
local sin2 = self.angleCache[1].s1
local cos2 = self.angleCache[1].c1
if self.continuous then
line(sin1 * self.inner + sin1 * self.length[#self.length] * mult + self.x, cos1 * self.inner + cos1 * self.length[#self.length] * mult + self.y, sin2 * self.inner + sin2 * self.length[1] * mult + self.x, cos2 * self.inner + cos2 * self.length[1] * mult + self.y)
else
line(sin1 * self.inner + self.x, cos1 * self.inner + self.y, sin1 * self.inner + sin1 * self.length[#self.length] * mult + self.x, cos1 * self.inner + cos1 * self.length[#self.length] * mult + self.y)
end
end
The class is called Spectrum(). The first two parameters are the X and Y coordinates, the third is the inner length (the distance each line starts from the center), the fourth is the outer length (the distance each line ends at most from the center), the fifth is whether it’s continuous (whether it should be one curved line, or a bunch of straight lines), and the sixth is whether it’s inverted (false = higher line length is further from the center, true = high line length is closer to the center).
@SkyTheCoder i pasted a wrong pictures url this should work and i couldnt figure out why people were coding the wrong ting any way this should work ill check it after i post it
http://bella-beauty.deviantart.com/art/Random-Lines-175794449
or
https://m.youtube.com/watch?v=Vxv2v_Pma1U
- thank you again and the code you sent me was really good thank you for your effort
@Ray_Spahn No problem about the url. It just gave me something else to try. I don’t like the way my latest code works because it always starts over at 1 so there’s sometimes a big difference between the current “1” and the previous “360” value. It’s not a smooth transition.
@Ray_Spahn I like the effect that is being shown in the second link. I think that can be done using Bézier curves in 3D with rotation. I’m not sure if it would look the same and how fast it would run. It’s also something that I’m not going to try anytime soon.
You might be interested in the “Liquid line flow” programs that were posted a while back.
@LoopSpace Thanks for the links. There are some interesting examples in the older discussions. Too bad there isn’t an easy way to find them.