Cool @david

Btw . Thanks @jmv38

@David Moderators (I’m one, and there are a few others around) can hide posts from view, but the usual way is to edit it to something like “Issue was solved” or some such.

I usually only delete spam posts or obvious double posts.

Thanks so much @dave1707 ! However… you do realise that every answer leads to at least two more questions ;

I’d spent hours trying to get the ‘wait’ to work properly, and just after posting the problem, figured it out, so removed the post. However, I still don’t understand why having this…

```
function draw()
frames = frames + 1
if frames%10 == 0 then
```

at the start of drawing caused the patterns to strobe. I tried a simple routine moving a rectangle around the screen from a table of coordinate values, and it worked fine with the frame delay at the start of draw().

I appreciate the refinements you and @Andrew_Stacey have made and will update mine.

I prefer the way you have it centered full screen - I want the option for parameters available too, so is it easy to have it centered on both screens?

I’m playing around with colours atm so one more question? There doesn’t seem to be a hue, saturation, brightness instruction in Lua - just RGB & Alpha. I tried randomising cols, but a lot of them can be pretty dull… I’d ideally like to have say saturation and brightness at 100% and one parameter slider for Hue. Is this possible?

Thanks guys as always, and for your nice comments too. Much appreciated.

@David Add this if statement to the beginning of draw(). When you switch from FULLSCREEN to parameter view, or parameter view to FULLSCREEN, or rotate the ipad, it will resize and center the image. As for the colors, your limited to r,g,b and alpha. I don’t have the original code that I corrected, so I can’t say exactly why the way you had the wait was causing the strobe effect. I know the delay was too long and the way you had the code arranged wasn’t working, but I would need the original again to give an exact answer.

```
function draw()
background(40,40,50)
if a~=WIDTH/2 then
a = WIDTH/2 -- circle centre (a,b) radius r
b = HEIGHT/2
r = math.min(a,b)
end
```

Thanks @dave1707 ! I will reproduce the effect and post it later today. I think I’ve figured out a way to maintain punchy saturated colours… Looking at Photoshop, with 100% saturation & brightness, starting at R255 G0 B0 blue ramps up in 6’s to B252, B255 at which point red decrements in 6’s till you get R0 G0 B255… and so on… I haven’t worked out how to code that into a function hue(0-100) but can’t be that difficult can it ;-p We’ll see.

@dave1707 Here is the code with the strobing issue. As I said earlier, I wrote a routine to move a rectangle from a table of values, with the delay in exactly the same place and it worked straight away.

```
-- Mystic Rose v3.4 rotation 2 by David Cockram
-- frame delay issues - strobing
function setup()
print("Hello World!")
frames = 0
n = 1
parameter.integer ("points", 2,20,11)
parameter.integer ("rotation", 1, 90, 33)
end
function draw()
frames = frames + 1
if frames%20 == 0 then
background(40, 40, 50)
strokeWidth(1)
-- Do your drawing here
fill(31, 103, 38, 132)
ellipse(380,370,704)
-- points & rotation settings
d = {4,7,15,49,11,33,11,32,16,34,11,26,11,14,6,17,11,16,11,31,6,14,11,34,11,51,11,62,6,6,11,69}
points = d[n]
rotation = d[n+1]
print(n, points, rotation)
a = 380 -- circle centre (a,b) radius r
b = 370
r = 350
angle = 360/points -- angle to increment
w = points*2 -- number of coordinates
c = {} -- table of coords {x1, y1, x2, y2 ... etc}
-- this part works out the coordinates, based on the number of points
for rot = 0, 360, rotation do
for i = 0, points-1 do
t = i*angle + rot
-- put coordinate pairs in a table, c
c[2*i+1] = a + r*math.sin(math.rad(t)) -- x coordinate
c[2*i+2] = b + r*math.cos(math.rad(t)) -- y coordinate
end
-- draw lines. The start value h+2 increments each loop to prevent repeating lines
for h = 1, w-3, 2 do
for i = h+2, w-1, 2 do
line(c[h], c[h+1], c[i], c[i+1])
-- print(h, h+1, i, i+1) -- line drawing key table values to check
end
end
end
n = n+2 -- cycle through table of points & rotation
if n == 33
then n = 1
end
end
end
```

@David I’ll look at your code later and give you an answer. It’s time to get off the iPad and start my day.

@David, you might consider deleting the rotation table, and instead use the built-in rotate function

@David The flickering effect is due to how Codea does its drawing. It has three canvases that it uses in turn so when you don’t redraw stuff each frame then what is there is not reused until the third iteration. Did that make sense?

That’s why you should ensure that you always draw *something* every time that `draw`

is run, even if it is the same as what you drew the previous time.

(There is a way around this which is to use `backingMode(RETAINED)`

in `setup`

, but it is better for you to learn about how Codea draws and how to work with that than how to get round it.)

```
-- Mystic Rose v3.4 rotation 2 by David Cockram
-- frame delay issues - strobing
function setup()
print("Hello World!")
frames = 0
n = 1
parameter.integer ("points", 2,20,11)
parameter.integer ("rotation", 1, 90, 33)
end
function draw()
frames = frames + 1
if frames%20 == 0 then
n = n+2 -- cycle through table of points & rotation
if n == 33
then n = 1
end
end
background(40, 40, 50)
strokeWidth(1)
-- Do your drawing here
fill(31, 103, 38, 132)
ellipse(380,370,704)
-- points & rotation settings
d = {4,7,15,49,11,33,11,32,16,34,11,26,11,14,6,17,11,16,11,31,6,14,11,34,11,51,11,62,6,6,11,69}
points = d[n]
rotation = d[n+1]
print(n, points, rotation)
a = 380 -- circle centre (a,b) radius r
b = 370
r = 350
angle = 360/points -- angle to increment
w = points*2 -- number of coordinates
c = {} -- table of coords {x1, y1, x2, y2 ... etc}
-- this part works out the coordinates, based on the number of points
for rot = 0, 360, rotation do
for i = 0, points-1 do
t = i*angle + rot
-- put coordinate pairs in a table, c
c[2*i+1] = a + r*math.sin(math.rad(t)) -- x coordinate
c[2*i+2] = b + r*math.cos(math.rad(t)) -- y coordinate
end
-- draw lines. The start value h+2 increments each loop to prevent repeating lines
for h = 1, w-3, 2 do
for i = h+2, w-1, 2 do
line(c[h], c[h+1], c[i], c[i+1])
-- print(h, h+1, i, i+1) -- line drawing key table values to check
end
end
end
end
```

Thanks @Andrew_Stacey. I could do with reading up on this tbh… the extent of my knowledge here is that the setup() is performed once (presumably parameters are an exception) and draw() is done 60 times a second. Are there any articles that explain in detail?

I’ve updated the Mystic Rose to v3.5 and tidied it up a bit with the help of you guys… many thx. It now defaults to a normal classic Mystic Rose with 20 points. Moving the rotation slider creates some pretty patterns. I’ve put some of the nicer ones as presets, so switching that on will cycle through them. It now defaults to Full Screen, and finally I’ve scaled the line width proportionally to the #points as thicker lines look better with fewer points.

Next step is to add colour… and I must post this on the Codea Community site… can I use the same login as I use here to get onto that?

```
-- Mystic Rose v3.5 by David Cockram
displayMode (FULLSCREEN)
function setup()
pTab = {17,4,15,11,10,11,16,20,18, 8, 7,11,10,20,10, 6,19,11, 8,14,10,19, 6,11,18,11,14,11, 6,14,11, 8} -- points presets
rTab = {63,7,49,33,75,32,36,66,82,26,13,26,69,48,35,17,72,31,23,39,33,78,14,34,30,51,51,62, 6,86,69,11} -- rotation presets
a = WIDTH/2 -- circle centre (a,b) radius r
b = HEIGHT/2
r = math.min(a,b)-10
frames = 0
n = 1
parameter.boolean("Presets", false)
parameter.integer ("points", 2,40,20)
parameter.integer ("rotation", 1, 360, 360)
end
function draw()
background(91, 59, 44, 50)
if a~=WIDTH/2 then
a = WIDTH/2 -- circle centre (a,b) radius r
b = HEIGHT/2
r = math.min(a,b)-10
end
strokeWidth(2-points/40) -- scale to higher value for fewer points - looks nicer
fill(120, 67, 45, 80)
ellipse(a,b,r*2+4)
if Presets == true then -- switch preset values on/off
points = pTab[n]
rotation = rTab[n]
else end
angle = 360/points -- angle to increment
w = points*2 -- number of coordinates
c = {} -- table of coords {x1, y1, x2, y2 ... etc}
-- this part works out the coordinates, based on the number of points
for rot = 0, 360, rotation do
for i = 0, points-1 do
t = i*angle + rot
-- put coordinate pairs in a table, c
c[2*i+1] = a + r*math.sin(math.rad(t)) -- x coordinate
c[2*i+2] = b + r*math.cos(math.rad(t)) -- y coordinate
end
-- draw lines. The start value h+2 increments each loop to prevent repeating lines
for h = 1, w-3, 2 do
for i = h+2, w-1, 2 do
line(c[h], c[h+1], c[i], c[i+1])
-- print(h, h+1, i, i+1) -- line drawing key table values to check
end
end
end
frames = frames + 1
if frames%20 == 0 then
n = n+1 -- cycle through table of points & rotation
if n > #pTab
then n = 1
end
end
end
```

@David - I’ve written some posts here

http://coolcodea.wordpress.com

And an unfinished ebook here

https://www.dropbox.com/s/t5im6tl14ky5t08/Codea%20for%20beginners.pdf

Which I hope explains the drawing process

@Ignatz I think the PDF ebook should be newbie required reading. There is a lot of info in there. Some things that will even help me.

@Ignatz I did have a quick look through your book to see if it covered the 3-image point about how Codea draws. I didn’t see it (but I didn’t look all that carefully). Is it there? When writing about it to David above then I wanted some reference that I could link to but couldn’t find it on the wiki either.

@Andrew_Stacey - no, I didn’t cover the three image stuff because that is too complex for newbies! I stick to what the user actually sees.

@Ignatz local variables? Are those in there? I must have completly skipped over that section because I don’t remember anything about them.

@Ignatz I know you we’re teasing because of the big smily face, or even without it. But I skimmed thru your ebook and there is a lot of information in there and it would be very useful for the newbies to read. There is information in there that I can learn from also. You did a fantastic job. A link to it should be placed a the top of the forum labeled “Required Reading” and any “simple question” should be responded to with “look in the Required Reading” link.

@dave1707 - I presume you’re talking about the Codea ebook, which is totally unfinished. There is so much to talk about. I’ve pretty much finished the Lua ebook, though, which people should read first.

Thank you for your kind words. Much appreciated.

In turn, I think you are doing an amazing job of supporting new users.