Author Topic: Easter Egg Decorating  (Read 19868 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Easter Egg Decorating
« on: March 29, 2022, 09:03:33 pm »
For Ken,

Code: QB64: [Select]
  1. _Title "Eggs o Dozens" 'b+ 2022-03-29
  2. Const Xmax = 1200, Ymax = 400, Pi = _Pi
  3. Screen _NewImage(Xmax, Ymax, 32)
  4. _ScreenMove 100, 100
  5. scale = 96
  6.     For y = 100 To 300 Step 200
  7.         For x = 100 To 1100 Step 200
  8.             drawEasterEgg x, y, scale, 0
  9.         Next
  10.     Next
  11.     _Delay 1
  12.  
  13. Sub drawEasterEgg (xc, yc, scale, radianAngle)
  14.     r = Rnd: g = Rnd: b = Rnd
  15.     For x = -1 To 1 Step .01
  16.         For y = -1 To 1 Step .01
  17.             If x < 0 Then c = c + .0005 Else c = c - .0005
  18.             If (x * x + (1.4 ^ x * 1.6 * y) ^ 2 - 1) <= .01 Then
  19.                 If y > 0 Then
  20.                     Color _RGB32(128 * (1 - y) + 128 * (1 - y) * Sin(c * r), 128 * (1 - y) + 128 * (1 - y) * Sin(c * g), 127 * (1 - y) + 127 * (1 - y) * Sin(c * b))
  21.                 Else
  22.                     Color _RGB32(128 + 128 * Sin(c * r), 128 + 128 * Sin(c * g), 127 + 127 * Sin(c * b))
  23.                 End If
  24.                 a = _Atan2(y, x)
  25.                 d = scale * Sqr(x * x + y * y)
  26.                 PSet (xc + d * Cos(a + radianAngle), yc + d * Sin(a + radianAngle))
  27.             End If
  28.         Next
  29.     Next
  30.  
  31.  
  32.  

 
Eggs o Dozens.PNG

« Last Edit: March 29, 2022, 09:29:05 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Easter Egg Decorating
« Reply #1 on: March 30, 2022, 09:44:30 am »
Show off more versatility of drawEasterEgg:
Code: QB64: [Select]
  1. _Title "Eggs o Dozens" 'b+ 2022-03-30 mod
  2. Const Xmax = 1200, Ymax = 400, Pi = _Pi
  3. Screen _NewImage(Xmax, Ymax, 32)
  4. _ScreenMove 100, 100
  5. scale = 96
  6.     Cls
  7.     For y = 100 To 300 Step 200
  8.         For x = 100 To 1100 Step 200
  9.             drawEasterEgg x, y, Rnd * .75 * scale + .25 * scale, Rnd * 2 * Pi
  10.         Next
  11.     Next
  12.     _Delay 1
  13.  
  14. Sub drawEasterEgg (xc, yc, scale, radianAngle)
  15.     r = Rnd: g = Rnd: b = Rnd
  16.     For x = -1 To 1 Step .01
  17.         For y = -1 To 1 Step .01
  18.             If x < 0 Then c = c + .0005 Else c = c - .0005
  19.             If (x * x + (1.4 ^ x * 1.6 * y) ^ 2 - 1) <= .01 Then
  20.                 If y > 0 Then
  21.                     Color _RGB32(128 * (1 - y) + 128 * (1 - y) * Sin(c * r), 128 * (1 - y) + 128 * (1 - y) * Sin(c * g), 127 * (1 - y) + 127 * (1 - y) * Sin(c * b))
  22.                 Else
  23.                     Color _RGB32(128 + 128 * Sin(c * r), 128 + 128 * Sin(c * g), 127 + 127 * Sin(c * b))
  24.                 End If
  25.                 a = _Atan2(y, x)
  26.                 d = scale * Sqr(x * x + y * y)
  27.                 Line (xc + d * Cos(a + radianAngle), yc + d * Sin(a + radianAngle))-Step(1, 1)
  28.             End If
  29.         Next
  30.     Next
  31.  

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Easter Egg Decorating
« Reply #2 on: March 30, 2022, 11:27:40 am »
Code: QB64: [Select]
  1. _Title "Eggs o Dozens" 'b+ 2022-03-29
  2.  
interesting funny title, extremely fluent in the english language

Code: QB64: [Select]
  1. Const Xmax = 1200, Ymax = 400, Pi = _Pi
  2.  
Pi = _Pi, the first piece of genius code one can observes.  A philosophical criticism of the language

Code: QB64: [Select]
  1. If (x * x + (1.4 ^ x * 1.6 * y) ^ 2 - 1) <= .01 Then
  2.  
wow what is this? 1.4 to the power of x times y times 1.6! Wait, this can be written more simply as
Code: QB64: [Select]
  1. If (x * x + (1.4 ^ x * 1.6 * y) ^ 2) <= 1.01 Then
  2.  
...wait a second, this looks like a distance formula.  If one changes it to x*x + y*y < 1 they become circles not eggs! What spectacular mathematical intuition!

Code: QB64: [Select]
  1. a = _Atan2(y, x)
  2. d = scale * Sqr(x * x + y * y)
  3. PSet (xc + d * Cos(a + radianAngle), yc + d * Sin(a + radianAngle))
  4.  
oh dear, polar coordinates again.  What are we doing, bplus? Why not just
Code: QB64: [Select]
  1. PSet (xc + scale * x, yc + scale * y)
  2.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Easter Egg Decorating
« Reply #3 on: March 30, 2022, 11:49:02 am »
For Vince the analyst:

The egg shape formula comes from this:
Quote
Don M. Jacobs, M.D., from Daly City, USA developped a nice egg shape by changing the circle equation x²+y²=1 a little: x² + [1.4^x*1.6y]² = 1. The egg equation is an exponential equation of the type t3.

At LB tsh has nice shape derived from circles, see LB https://libertybasiccom.proboards.com/thread/1954/easter-eggs-anybody
or
JB (towards middle end)
https://justbasiccom.proboards.com/thread/789/graphics-fun?page=2

Pi = _PI  genius LOL! Just making it easier to translate JB code to QB64, only one change with Const instead of changing all Pi's to _Pi in code. Genius is pure laziness.

This:
Code: QB64: [Select]
  1. a = _Atan2(y, x)
  2. d = scale * Sqr(x * x + y * y)
  3. PSet (xc + d * Cos(a + radianAngle), yc + d * Sin(a + radianAngle))
Is for rotating our egg drawing about xc, yc (the middle point of where we want our egg) so the eggs may be angled by radianAngle and some angle besides radianAngle 0 = East

So imagine a little drawing of an egg pointed east from scale. Imagine taking each point around the center, measuring the angle to the center a = _Atan2(y, x)
d = distance x, y to center of plot with (0,0) as origin x -1 to 1, y -1 to 1
So we rotate and scale our image in a little Rotozoom example one pixel at a time.

What's Polar Coordinates about that?

Anyway, that's why it's not just:
Code: QB64: [Select]
  1. PSet (xc + scale * x, yc + scale * y)
  2.  

In fact in 2nd code I found it better to use a Line with a -Step(sq, sq), , BF
 and draw a colored square instead of a pixel.

PS the first post without using the last parameter to angle the eggs was mostly to show Aurel at his forum that the eggs (the coloring bands) had to be symmetric. I wasn't even going to post Easter eggs here but Ken seemed to be getting lonely doing a monolog on Neon Clocks ;-))
« Last Edit: March 30, 2022, 12:10:20 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Easter Egg Decorating
« Reply #4 on: March 30, 2022, 02:32:01 pm »
Those are incredible!!!! Thanks B+!!! :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Easter Egg Decorating
« Reply #5 on: March 30, 2022, 03:50:50 pm »
Hey Ken, I am going to try and get a less "candy-corn" (Spriggsy's term but kinda right on) egg shape going later today. Lot's of time before Easter.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Easter Egg Decorating
« Reply #6 on: March 30, 2022, 05:24:34 pm »
Sounds great, yeah I almost said they looked a little bit like guitar picks, but curved. :) But they are still awesome.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Easter Egg Decorating
« Reply #7 on: March 30, 2022, 05:48:37 pm »
Ken. Technically a "plectrum" is used to strum the strings of a guitar etc., where as a pick, is used to pluck individual strings. But that does not stop people from using either for both purposes...  But I knew what you meant...  ah... trivia.. ya just gotta love it...
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Easter Egg Decorating
« Reply #8 on: March 30, 2022, 09:17:03 pm »
This pretty much matches the Cage Free Eggs I have in the fridge:
 
Cage Free Egg.PNG

Clearly no candy corn shape any more.

What do you think?

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Easter Egg Decorating
« Reply #9 on: March 30, 2022, 10:45:09 pm »
Here's my simple little try at a math formula to produce an egg:

Code: QB64: [Select]
  1. Screen _NewImage(320, 320, 32)
  2. Window (0, -1.5)-(_Pi, 1.5)
  3.  
  4. For x = 0 To _Pi Step 0.001
  5.     'y = Sqr(Abs(Sin(1.3 * x))) 'Try #1 change window to (0,-2)-(_PI, 2)
  6.     y = Sqr(Abs(Sin(x) + 0.1 * (Sin(2 * x))))
  7.     PSet (x, y), -1
  8.     PSet (x, -y), -1

I figure a SIN wave stretched on one end could produce an egg-like shape.  The trick is to figure out the best formula to stretch it properly to make a pretty little "egg" like oval.  ;)

EDIT: Crazy math guys have a whole paper dedicated to this whole egguation!  https://nyjp07.com/index_egg_E.html
« Last Edit: March 30, 2022, 10:54:00 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Easter Egg Decorating
« Reply #10 on: March 31, 2022, 12:11:37 am »
EDIT: Crazy math guys have a whole paper dedicated to this whole egguation!  https://nyjp07.com/index_egg_E.html
hahaha, Steve, egguation!

I was curious if any of those curves have a mathematical biology argument because otherwise there has to be near infinite types of curves that could fit an egg shape.  The easiest is take a photo and fit a polynomial spline.  I found this article for, allegedly, the true egg formula:  https://www.kent.ac.uk/news/science/29620/research-finally-reveals-ancient-universal-equation-for-the-shape-of-an-egg

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Easter Egg Decorating
« Reply #11 on: March 31, 2022, 02:52:21 am »
I looked a little further into egg philosophy and was wondering if there was anything more substantial than "that looks pretty damn close".  It seems you can make fundamental and profound arguments for certain geometric patterns in nature like hexagonal beehives or numerical sequences in phyllotaxis, but has anyone done the same for eggs?  Can you say that there is one fundamental principle that maximizes bird survival (flight dynamics? egg production rate? idk) and here are the geometric implications of it on the egg shape, I don't think anyone has done it.  Is there a 1:1 function matching bird DNA data to egg curve?

It seems what they did do is take some basic geometric shapes (ovoid) that can approximate most eggs experimentally based on a few measurements then generalize to other basic geometric shapes like pyriform to boost your benchmark.  Like if you have a curve that is 99% accurate on a scan or photograph for 99% of all the eggs produced by 99% of all bird species on the planet and it only requires measuring egg height and max diameter (and maybe a couple of more) than it must be pretty damn good and close to true egg geometry? So far, the universal egg equation is allegedly:
Eggequation.jpg


just FYI, the above is just a curve y=f(x) with a bunch of parameters.  the +- in front implies symmetry over the x-axis.  A circle of radius R would be y = +-SQR(R^2 - x^2).  So you'd grab an egg from the fridge, measure L,w,B,D with a tape measure or scale or whatever (I have no idea what those parameters are), plug them in and plot y with respect to x and you should have a curve that is some 99% perfect to the egg you have.  Then, presumably, the actual egg is a surface of revolution of this curve.
« Last Edit: March 31, 2022, 03:05:46 am by _vince »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Easter Egg Decorating
« Reply #12 on: March 31, 2022, 07:12:25 am »
Yeah, a formula is useless if you don't know what the variables are!

@_vince So did you figure what * p(x) was to get the 2nd and 3rd line of that eq?

What is 2D sub L/4 on the 2 line of eq towards the right of center? are you kidding?


I think people have cartoon image of eggs being really pointy at one end. They aren't if you look at them.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Easter Egg Decorating
« Reply #13 on: March 31, 2022, 07:25:13 am »
I think people have cartoon image of eggs being really pointy at one end. They aren't if you look at them.

Looks pretty darn pointed to me!  😁

https://3c1703fe8d.site.internapcdn.net/newman/gfx/news/hires/2017/7-researchersp.jpg
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Easter Egg Decorating
« Reply #14 on: March 31, 2022, 07:28:46 am »
Yeah, a formula is useless if you don't know what the variables are!

@_vince So did you figure what * p(x) was to get the 2nd and 3rd line of that eq?

What is 2D sub L/4 on the 2 line of eq towards the right of center? are you kidding?


I think people have cartoon image of eggs being really pointy at one end. They aren't if you look at them.

Here's a more detailed description of the parameters:  https://nyaspubs.onlinelibrary.wiley.com/doi/10.1111/nyas.14771

The chicken eggs are not pointy but eggs of other bird species are, ie the "pyriform" shape https://bioone.org/journals/the-auk/volume-135/issue-4/AUK-18-38.1/The-pyriform-egg-of-the-Common-Murre-Uria-aalge-is/10.1642/AUK-18-38.1.full

That curve equation is supposed to be universal to all eggs.  From what I gather, you can set p(x) = x for a "good enough" approximation but there are several more complicated variants of p(x) that take into account more species of birds, ie that "pyriform" one