Cardioid - Heart Curve

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
IcarusLives
Posts: 112
Joined: 17 Jan 2016 23:55

Cardioid - Heart Curve

#1 Post by IcarusLives » 04 Mar 2019 08:09

Just wanted to share something neat I found.

http://mathworld.wolfram.com/HeartCurve.html

I attempted to recreate this in batch. Here is my attempt. The algorithm is correct. This is the 6th example.

I tried to "fine tune" the heart to appear more.. hearty..? A deeper point in the top would be nice, but I cannot seem to manage.

Enjoy :)

Image

Code: Select all

@echo off & setlocal enableDelayedExpansion

for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"
set "_SIN=a-a*a/1920*a/312500+a*a/1920*a/15625*a/15625*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000"
set "SIN=(a=((x) * 31416 / 180)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832)  +  (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a)  ), %_SIN%) / 100"
set "COS=(a=(15708 - (x) * 31416 / 180)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832)  +  (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a)  ), %_SIN%) / 10000"

set /a "heartSize=1", "heartHei=13", "heartWid=16", "centerScreen=50", "normalize=1000000"

for /l %%a in (0,1,360) do (
	set "gotPow=1" & for /l %%b in (1,1,3) do set /a "gotPow*=!sin:x=%%a!"
	set /a "x= heartSize * heartWid * gotPow / normalize + centerScreen"
	set /a "y=-heartSize * (heartHei * !cos:x=%%a! - 5 * !cos:x=2*%%a! - 2 * !cos:x=3*%%a! - !cos:x=4*%%a!) + centerScreen"
	<nul set /p "=%esc%[!y!;!x!H%esc%[38;5;9mÛ"
)

pause >nul
Last edited by IcarusLives on 04 Mar 2019 20:23, edited 1 time in total.

Aacini
Expert
Posts: 1596
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: Cardoid - Heart Curve

#2 Post by Aacini » 04 Mar 2019 08:50

Ops! You are using ANSI sequences to move the cursor... :(

This just works in Windows 10, or with an ANSI driver installed. :cry:

Antonio

dbenham
Expert
Posts: 2219
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Cardoid - Heart Curve

#3 Post by dbenham » 04 Mar 2019 09:03

I have never heard of a "cardoid". Did you mean "cardioid"?

That shape is not a cardioid because it has two cusps, where as a true cardioid has one cusp. If the bottom was rounded instead of having a point then it could be a cardioid.

Aacini
Expert
Posts: 1596
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: Cardoid - Heart Curve

#4 Post by Aacini » 04 Mar 2019 09:14

Interesting!

Image

Code: Select all

@echo off
setlocal EnableDelayedExpansion

for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"
set "_SIN=a-a*a/1920*a/312500+a*a/1920*a/15625*a/15625*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000"
set "SIN=(a=((x) * 31416 / 180)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832)  +  (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a)  ), %_SIN%) / 100"
set "COS=(a=(15708 - (x) * 31416 / 180)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832)  +  (-((c-47125)>>31))*((((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a)  ), %_SIN%) / 10000"

set /a "heartSize=1", "heartHei=13", "heartWid=16", "centerScreen=50", "normalize=1000000"

set "line="
for /L %%x in (1,1,70) do set "line=!line! "
for /L %%y in (1,1,70) do set "line[%%y]=%line%"

for /L %%a in (0,1,360) do (
   set "gotPow=1" & for /l %%b in (1,1,3) do set /a "gotPow*=!sin:x=%%a!"
   set /a "x= heartSize * heartWid * gotPow / normalize + centerScreen"
   set /a "y=-heartSize * (heartHei * !cos:x=%%a! - 5 * !cos:x=2*%%a! - 2 * !cos:x=3*%%a! - !cos:x=4*%%a!) + centerScreen"

   set /A "xP1=x+1"
   for /F "tokens=1-3" %%x in ("!x! !y! !xP1!") do set "line[%%y]=!line[%%y]:~0,%%x!@!line[%%y]:~%%z!"
)

cls
color C
for /L %%y in (1,1,70) do echo/!line[%%y]!

pause >nul
Antonio

IcarusLives
Posts: 112
Joined: 17 Jan 2016 23:55

Re: Cardoid - Heart Curve

#5 Post by IcarusLives » 04 Mar 2019 13:26

dbenham wrote:
04 Mar 2019 09:03
I have never heard of a "cardoid". Did you mean "cardioid"?

That shape is not a cardioid because it has two cusps, where as a true cardioid has one cusp. If the bottom was rounded instead of having a point then it could be a cardioid.
Haha, yes that is what I meant. Thank you!

Image

You're also right that a heart and a cardioid are not the same! Sorry for the confusion.

IcarusLives
Posts: 112
Joined: 17 Jan 2016 23:55

Re: Cardoid - Heart Curve

#6 Post by IcarusLives » 04 Mar 2019 13:27

Aacini wrote:
04 Mar 2019 09:14
Interesting!
Thank you for thinking so! And thank you for rewritting a OS friendly version!

misol101
Posts: 363
Joined: 02 May 2016 18:20

Re: Cardioid - Heart Curve

#7 Post by misol101 » 05 Mar 2019 02:39

Thanks again Icarus for inspiration! For cmdgfx users, here is a oneliner:

Code: Select all

cmdgfx_gdi "block 0 100,0,500,70 100,0 -1 0 0 ????=??03 (y+1) & block 0 0,0,500,70 0,0 -1 0 1 - - store(sin(x/3),1)+store((y+16)/16,2)+16*s2*s1*s1*s1+50 store(x/3,1)+store((y+16)/16,2)+13*s2*cos(s1)-5*cos(s1*2)-2*cos(s1*3)-cos(4*s1)+35" f6:0,0,500,70,100,70
Result:
Image

Replace (y+1) with (y+1+x), and we get:

Image

Now add a red palette to the end of the line for that extra Valentine feeling: 000000,110000,220000,330000,440000,550000,660000,770000,880000,990000,aa0000,bb0000,cc0000,dd0000,ee0000

Image

Ok, that's it. Sorry to invade the thread, hope you like it :oops:

Post Reply