Created
June 27, 2012 14:56
-
-
Save Bri-G/3004619 to your computer and use it in GitHub Desktop.
Koch Tree fractal adapted for iPad from processing
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
-- Dragon curve 3 | |
-- derived form a processing example at | |
-- http://processing.org/learning/topics/tree.html | |
-- adapted for the pad by Bri_G | |
function setup() | |
-- | |
displayMode(FULLSCREEN) | |
Sx = WIDTH/2 | |
Sy = 0 | |
-- initialise the drawing angle | |
theta = 0 | |
-- initial drawing length | |
length = (HEIGHT)/3 | |
end | |
function draw() | |
-- | |
background(0, 0, 0, 255) | |
-- move to horisontal middle of screen at zero height | |
translate(Sx,Sy) | |
-- inialise end of line point | |
S2x = 0 | |
S2y = length | |
-- set up line drawing parameters | |
stroke(255, 255, 255, 255) | |
lineCapMode(ROUND) | |
strokeWidth(3) | |
-- draw first line and move to top of it | |
line(0, 0,S2x,S2y) | |
translate(0, length) | |
-- call the iterative pattern routine | |
dragon(length) | |
end | |
function dragon(length) | |
-- reduce the line length each iteration | |
local size = length*0.66 | |
if size > 2 then | |
-- draw lines in one direction | |
pushMatrix() | |
rotate(theta) | |
line(0,0,0,size) | |
translate(0,size) | |
-- recursive self call | |
dragon(size) | |
popMatrix() | |
-- now draw them in the opposite direction | |
pushMatrix() | |
rotate(-theta) | |
line(0,0,0,size) | |
translate(0,size) | |
-- recursive self call | |
dragon(size) | |
popMatrix() | |
end | |
end | |
function touched(touch) | |
-- adjust the line drawing angle based on x value from CurrentTouch | |
theta = 90*((CurrentTouch.x)/(WIDTH)) | |
-- adjust theta as you approach extremes due to my fat fingers | |
if theta < 2 then theta = 0 end | |
if theta > 88 then theta = 90 end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi All,
This is a nother neat little demo that I saw on Processing at http://processing.org/learning/topics/tree.html.
I had to adapt it quite a bit - in particular I had to force the angles to 0 and 90 degrees to ensure the extreme patterns were obtained. Hope you like it more to follow.
Bri_G