Instantly share code, notes, and snippets.

# rasmusab/shiny_harmonograph.R

Created June 23, 2015 17:24
Harmonograf in Shiny by Antonio S. Chinchón from https://aschinchon.wordpress.com/2015/06/23/the-2d-harmonograph-in-shiny/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # From https://aschinchon.wordpress.com/2015/06/23/the-2d-harmonograph-in-shiny/ # All code by Antonio S. Chinchón (@aschinchon), just rearranged so that you can directly # run it by copy and pasting it into an R console. library(shiny) CreateDS = function () { f=jitter(sample(c(2,3),4, replace = TRUE)) d=runif(4,0,1e-02) p=runif(4,0,pi) xt = function(t) exp(-d[1]*t)*sin(t*f[1]+p[1])+exp(-d[2]*t)*sin(t*f[2]+p[2]) yt = function(t) exp(-d[3]*t)*sin(t*f[3]+p[3])+exp(-d[4]*t)*sin(t*f[4]+p[4]) t=seq(1, 200, by=.0005) data.frame(t=t, x=xt(t), y=yt(t)) } shinyApp( ui = fluidPage( titlePanel("Mathematical Beauties: The Harmonograph"), sidebarLayout( sidebarPanel( #helpText(), # adding the new div tag to the sidebar tags\$div(class="header", checked=NA, tags\$p("A harmonograph is a mechanical apparatus that employs pendulums to create a geometric image. The drawings created typically are Lissajous curves, or related drawings of greater complexity. The devices, which began to appear in the mid-19th century and peaked in popularity in the 1890s, cannot be conclusively attributed to a single person, although Hugh Blackburn, a professor of mathematics at the University of Glasgow, is commonly believed to be the official inventor. A simple, so-called \"lateral\" harmonograph uses two pendulums to control the movement of a pen relative to a drawing surface. One pendulum moves the pen back and forth along one axis and the other pendulum moves the drawing surface back and forth along a perpendicular axis. By varying the frequency and phase of the pendulums relative to one another, different patterns are created. Even a simple harmonograph as described can create ellipses, spirals, figure eights and other Lissajous figures (Source: Wikipedia)")), tags\$div(class="header", checked=NA, HTML("