SlideShare a Scribd company logo
1 of 4
Download to read offline
I need help making a recursive Koch snowflake. Im using python. I needed to make a snowflake
that uses 6 recursions. I did that part, the part Im having trouble with is coloring each of
recursions a different color. here is what I have so far.
//-------------koch snowflake
void setup() {
size(600, 600);
background(255);
stroke(0);
//frameRate(1);
//colorMode(HSB, 8, 100, 100);
}
int i = 1;
void draw() {
Koch(width/2, height/2, width*0.7, i);
}
void Koch(float X, float Y, float D, int order) {
colorMode(HSB, 8, 100, 100);
fill(0, 128/order, 128);
pushMatrix();
translate(X, Y);
translate(-D/2, D/3*sin(PI/3));
Koch(D, order);
translate(D, 0);
rotate(-2*PI/3);
Koch(D, order);
translate(D, 0);
rotate(-2*PI/3);
Koch(D, order);
popMatrix();
}
void Koch(float X, int order) {
if (order == 1) {
order++;
Koch(X/3, order);
pushMatrix();
translate(X/3, 0);
rotate(PI/3);
Koch(X/3, order);
translate(X/3, 0);
rotate(-2*PI/3);
Koch(X/3, order);
translate(X/3, 0);
rotate(PI/3);
Koch(X/3, order);
popMatrix();
}
if (order == 2) {
order++;
Koch(X/3, order);
pushMatrix();
translate(X/3, 0);
rotate(PI/3);
Koch(X/3, order);
translate(X/3, 0);
rotate(-2*PI/3);
Koch(X/3, order);
translate(X/3, 0);
rotate(PI/3);
Koch(X/3, order);
popMatrix();
}
if (order == 3) {
order++;
Koch(X/3, order);
pushMatrix();
translate(X/3, 0);
rotate(PI/3);
Koch(X/3, order);
translate(X/3, 0);
rotate(-2*PI/3);
Koch(X/3, order);
translate(X/3, 0);
rotate(PI/3);
Koch(X/3, order);
popMatrix();
}
if (order == 4) {
order++;
Koch(X/3, order);
pushMatrix();
translate(X/3, 0);
rotate(PI/3);
Koch(X/3, order);
translate(X/3, 0);
rotate(-2*PI/3);
Koch(X/3, order);
translate(X/3, 0);
rotate(PI/3);
Koch(X/3, order);
popMatrix();
}
else {
order = order - 1;
beginShape();
vertex(0, 0);
vertex(X/3, 0);
vertex(X/2, X/3*sin(PI/3));
vertex(2*X/3, 0);
vertex(X, 0);
endShape();
}
}
Solution
Try to implement in

More Related Content

Similar to I need help making a recursive Koch snowflake. Im using python. I ne.pdf

Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
Kevin Hoyt
 
wavelet decomposition process code in matlabSolution WAVE.pdf
wavelet decomposition process code in matlabSolution WAVE.pdfwavelet decomposition process code in matlabSolution WAVE.pdf
wavelet decomposition process code in matlabSolution WAVE.pdf
brijeshagarwa329898l
 
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docxNewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
curwenmichaela
 
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docxCOMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
TashiBhutia12
 

Similar to I need help making a recursive Koch snowflake. Im using python. I ne.pdf (20)

Know more processing
Know more processingKnow more processing
Know more processing
 
Proga 0608
Proga 0608Proga 0608
Proga 0608
 
Processing and Processing.js
Processing and Processing.jsProcessing and Processing.js
Processing and Processing.js
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
 
Proga 0601
Proga 0601Proga 0601
Proga 0601
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
 
wavelet decomposition process code in matlabSolution WAVE.pdf
wavelet decomposition process code in matlabSolution WAVE.pdfwavelet decomposition process code in matlabSolution WAVE.pdf
wavelet decomposition process code in matlabSolution WAVE.pdf
 
Intro to HTML5 Canvas
Intro to HTML5 CanvasIntro to HTML5 Canvas
Intro to HTML5 Canvas
 
Proga 090525
Proga 090525Proga 090525
Proga 090525
 
PBL1-v1-013e.pptx
PBL1-v1-013e.pptxPBL1-v1-013e.pptx
PBL1-v1-013e.pptx
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
 
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
 
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docxNewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
 
Building a Visualization Language
Building a Visualization LanguageBuilding a Visualization Language
Building a Visualization Language
 
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docxCOMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Internal workshop es6_2015
Internal workshop es6_2015Internal workshop es6_2015
Internal workshop es6_2015
 

More from kostikjaylonshaewe47

Which of the following are true More than one answer may be correct.pdf
Which of the following are true More than one answer may be correct.pdfWhich of the following are true More than one answer may be correct.pdf
Which of the following are true More than one answer may be correct.pdf
kostikjaylonshaewe47
 
What was the Noble Prize winning advance that saved the magnetic rec.pdf
What was the Noble Prize winning advance that saved the magnetic rec.pdfWhat was the Noble Prize winning advance that saved the magnetic rec.pdf
What was the Noble Prize winning advance that saved the magnetic rec.pdf
kostikjaylonshaewe47
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdf
kostikjaylonshaewe47
 
Table 14.2 Primitive and Advanced Features of Nonvascular Plants as T.pdf
Table 14.2 Primitive and Advanced Features of Nonvascular Plants as T.pdfTable 14.2 Primitive and Advanced Features of Nonvascular Plants as T.pdf
Table 14.2 Primitive and Advanced Features of Nonvascular Plants as T.pdf
kostikjaylonshaewe47
 
report “Rabbits and Wolves”Discuss the changes in parameters and how.pdf
report “Rabbits and Wolves”Discuss the changes in parameters and how.pdfreport “Rabbits and Wolves”Discuss the changes in parameters and how.pdf
report “Rabbits and Wolves”Discuss the changes in parameters and how.pdf
kostikjaylonshaewe47
 
number of lines should be included in the last page of the paper aft.pdf
number of lines should be included in the last page of the paper aft.pdfnumber of lines should be included in the last page of the paper aft.pdf
number of lines should be included in the last page of the paper aft.pdf
kostikjaylonshaewe47
 
Modify the code below so that two separate listener classes are used .pdf
Modify the code below so that two separate listener classes are used .pdfModify the code below so that two separate listener classes are used .pdf
Modify the code below so that two separate listener classes are used .pdf
kostikjaylonshaewe47
 

More from kostikjaylonshaewe47 (20)

Which of the following organisms are similar to amoeboids in their lo.pdf
Which of the following organisms are similar to amoeboids in their lo.pdfWhich of the following organisms are similar to amoeboids in their lo.pdf
Which of the following organisms are similar to amoeboids in their lo.pdf
 
Which of the following are true More than one answer may be correct.pdf
Which of the following are true More than one answer may be correct.pdfWhich of the following are true More than one answer may be correct.pdf
Which of the following are true More than one answer may be correct.pdf
 
What was the Noble Prize winning advance that saved the magnetic rec.pdf
What was the Noble Prize winning advance that saved the magnetic rec.pdfWhat was the Noble Prize winning advance that saved the magnetic rec.pdf
What was the Noble Prize winning advance that saved the magnetic rec.pdf
 
What is difference between the Tariff and tax SolutionDifferen.pdf
What is difference between the Tariff and tax  SolutionDifferen.pdfWhat is difference between the Tariff and tax  SolutionDifferen.pdf
What is difference between the Tariff and tax SolutionDifferen.pdf
 
What are the most likely point in nutrient media preparation or later.pdf
What are the most likely point in nutrient media preparation or later.pdfWhat are the most likely point in nutrient media preparation or later.pdf
What are the most likely point in nutrient media preparation or later.pdf
 
Toss a fair coin three times. Let X denote the number of heads in fi.pdf
Toss a fair coin three times. Let X denote the number of heads in fi.pdfToss a fair coin three times. Let X denote the number of heads in fi.pdf
Toss a fair coin three times. Let X denote the number of heads in fi.pdf
 
TIA-569 lists six different areas or spaces where cabling is run. Li.pdf
TIA-569 lists six different areas or spaces where cabling is run. Li.pdfTIA-569 lists six different areas or spaces where cabling is run. Li.pdf
TIA-569 lists six different areas or spaces where cabling is run. Li.pdf
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdf
 
There are two large plants in the authors’ yard a yucca tree and an.pdf
There are two large plants in the authors’ yard a yucca tree and an.pdfThere are two large plants in the authors’ yard a yucca tree and an.pdf
There are two large plants in the authors’ yard a yucca tree and an.pdf
 
The seaport town of New Monopoly has become extremely popular with sh.pdf
The seaport town of New Monopoly has become extremely popular with sh.pdfThe seaport town of New Monopoly has become extremely popular with sh.pdf
The seaport town of New Monopoly has become extremely popular with sh.pdf
 
The figure below shows a series of SNP loci (A-O) loci for two strai.pdf
The figure below shows a series of SNP loci (A-O) loci for two strai.pdfThe figure below shows a series of SNP loci (A-O) loci for two strai.pdf
The figure below shows a series of SNP loci (A-O) loci for two strai.pdf
 
The climatic stability hypothesis for the change in biodiversity with.pdf
The climatic stability hypothesis for the change in biodiversity with.pdfThe climatic stability hypothesis for the change in biodiversity with.pdf
The climatic stability hypothesis for the change in biodiversity with.pdf
 
Table 14.2 Primitive and Advanced Features of Nonvascular Plants as T.pdf
Table 14.2 Primitive and Advanced Features of Nonvascular Plants as T.pdfTable 14.2 Primitive and Advanced Features of Nonvascular Plants as T.pdf
Table 14.2 Primitive and Advanced Features of Nonvascular Plants as T.pdf
 
Solar energy is channeled by molecular vibration from... to the ..pdf
Solar energy is channeled by molecular vibration from... to the ..pdfSolar energy is channeled by molecular vibration from... to the ..pdf
Solar energy is channeled by molecular vibration from... to the ..pdf
 
report “Rabbits and Wolves”Discuss the changes in parameters and how.pdf
report “Rabbits and Wolves”Discuss the changes in parameters and how.pdfreport “Rabbits and Wolves”Discuss the changes in parameters and how.pdf
report “Rabbits and Wolves”Discuss the changes in parameters and how.pdf
 
prove thisSolutionSuppose that A is a product of element.pdf
prove thisSolutionSuppose that A is a product of element.pdfprove thisSolutionSuppose that A is a product of element.pdf
prove thisSolutionSuppose that A is a product of element.pdf
 
Our task this week is to diagnose patients who come in with various .pdf
Our task this week is to diagnose patients who come in with various .pdfOur task this week is to diagnose patients who come in with various .pdf
Our task this week is to diagnose patients who come in with various .pdf
 
number of lines should be included in the last page of the paper aft.pdf
number of lines should be included in the last page of the paper aft.pdfnumber of lines should be included in the last page of the paper aft.pdf
number of lines should be included in the last page of the paper aft.pdf
 
Modify the code below so that two separate listener classes are used .pdf
Modify the code below so that two separate listener classes are used .pdfModify the code below so that two separate listener classes are used .pdf
Modify the code below so that two separate listener classes are used .pdf
 
Lie detector tests are notoriously flawed. Assume that a particular .pdf
Lie detector tests are notoriously flawed.  Assume that a particular .pdfLie detector tests are notoriously flawed.  Assume that a particular .pdf
Lie detector tests are notoriously flawed. Assume that a particular .pdf
 

Recently uploaded

QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 

Recently uploaded (20)

21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 

I need help making a recursive Koch snowflake. Im using python. I ne.pdf

  • 1. I need help making a recursive Koch snowflake. Im using python. I needed to make a snowflake that uses 6 recursions. I did that part, the part Im having trouble with is coloring each of recursions a different color. here is what I have so far. //-------------koch snowflake void setup() { size(600, 600); background(255); stroke(0); //frameRate(1); //colorMode(HSB, 8, 100, 100); } int i = 1; void draw() { Koch(width/2, height/2, width*0.7, i); } void Koch(float X, float Y, float D, int order) { colorMode(HSB, 8, 100, 100); fill(0, 128/order, 128); pushMatrix(); translate(X, Y); translate(-D/2, D/3*sin(PI/3)); Koch(D, order); translate(D, 0); rotate(-2*PI/3); Koch(D, order); translate(D, 0); rotate(-2*PI/3); Koch(D, order); popMatrix(); }
  • 2. void Koch(float X, int order) { if (order == 1) { order++; Koch(X/3, order); pushMatrix(); translate(X/3, 0); rotate(PI/3); Koch(X/3, order); translate(X/3, 0); rotate(-2*PI/3); Koch(X/3, order); translate(X/3, 0); rotate(PI/3); Koch(X/3, order); popMatrix(); } if (order == 2) { order++; Koch(X/3, order); pushMatrix(); translate(X/3, 0); rotate(PI/3); Koch(X/3, order); translate(X/3, 0); rotate(-2*PI/3); Koch(X/3, order); translate(X/3, 0); rotate(PI/3); Koch(X/3, order); popMatrix();
  • 3. } if (order == 3) { order++; Koch(X/3, order); pushMatrix(); translate(X/3, 0); rotate(PI/3); Koch(X/3, order); translate(X/3, 0); rotate(-2*PI/3); Koch(X/3, order); translate(X/3, 0); rotate(PI/3); Koch(X/3, order); popMatrix(); } if (order == 4) { order++; Koch(X/3, order); pushMatrix(); translate(X/3, 0); rotate(PI/3); Koch(X/3, order); translate(X/3, 0); rotate(-2*PI/3); Koch(X/3, order); translate(X/3, 0); rotate(PI/3); Koch(X/3, order); popMatrix();
  • 4. } else { order = order - 1; beginShape(); vertex(0, 0); vertex(X/3, 0); vertex(X/2, X/3*sin(PI/3)); vertex(2*X/3, 0); vertex(X, 0); endShape(); } } Solution Try to implement in