Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8626893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:08:25+00:00 2026-06-12T08:08:25+00:00

import gpdraw.*; import javax.swing.*; import java.lang.Math; public class Koch2 extends JFrame { SketchPad paper;

  • 0
import gpdraw.*;
import javax.swing.*;
import java.lang.Math;


public class Koch2 extends JFrame {

SketchPad paper;
DrawingTool pen;

public Koch2() {

    paper = new SketchPad(600, 600);
    pen = new DrawingTool(paper);

}


public void drawKoch(double sL, int level, double length) {

int x = level - 1;
double y = length / 3;

double z = -1.5 * sL;


if (level < 1) {
    pen.up();
    pen.move(z, 0);
    pen.down();
    pen.setDirection(0);
    pen.forward(sL);
}
else {
    pen.up();
    pen.move(z, 0);
    pen.down();
    pen.setDirection(0);
    pen.forward(length / (Math.pow(3, length)));
    pen.setDirection(60);
    pen.forward(length / (Math.pow(3, length)));
    pen.turnRight(120);
    pen.forward(length / (Math.pow(3, length)));
    pen.turnLeft(60);
    pen.forward(length / (Math.pow(3, length)));
    pen.setDirection(60);
    pen.forward(length / (Math.pow(3, length)));
    pen.turnRight(120);
    pen.forward(length / (Math.pow(3, length)));
    pen.turnRight(120);
    pen.forward(length / (Math.pow(3, length)));
    pen.setDirection(60);
    pen.forward(length / (Math.pow(3, length)));
    pen.turnRight(120);
    pen.forward(length / (Math.pow(3, length)));
    pen.turnLeft(60);
    pen.forward(length / (Math.pow(3, length)));
    pen.setDirection(60);
    pen.forward(length / (Math.pow(3, length)));
    pen.turnRight(120);
    pen.forward(length / (Math.pow(3, length)));


    /*pen.setDirection(0);
    pen.forward(length / (Math.pow(3, length)));
    */

    drawKoch((sL), (x) , (y));

}



}

public static void main(String[] args) {

    new Koch2().drawKoch(300, 6, 300);
}
}

Which sections of this code are faulty? I am trying to figure out how to generate a single template curve and then repeat that many times to make the actual curve. I don’t need to make the actual snowflake just yet, that can wait until after I figure the curve out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:08:26+00:00Added an answer on June 12, 2026 at 8:08 am

    Assuming pen.forward(length / (Math.pow(3, length))); draws a straight line :

    The formation of a Koch curve is recursive. To draw a level n Koch curve, you’ll need to draw four level (n-1) curves. The pseudo code for drawing Koch curves is like this:

    drawKochCurve (length, level):
        if level = 0:
            drawStraightLine(length)
        else:
            drawKochCurve(length / 3, level - 1)
            turnLeft(60)
            drawKochCurve(length / 3, level - 1)
            turnRight(120)
            drawKochCurve(length / 3, level - 1)
            turnLeft(60)
            drawKochCurve(length / 3, level - 1)
    

    In your code, I see there’s one recursive call. Instead of drawing straight lines, you need to draw smaller Koch curves. Draw Straight lines only at the base cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import java.awt.event.*; import javax.swing.*; public class PlannerMain { JFrame frame; JButton makeMap; JPanel panel;
import java.awt.*; import javax.swing.*; import javax.swing.GroupLayout; /** * @author Ene Ion */ public class
import java.util.ArrayList; import java.lang.Math; public class War { ArrayList deck = new ArrayList(0); ArrayList
import java.lang.*; public class GrammerStack extends GrammerStructure implements StringStack { private String structName; private
import gpdraw.*; public class Y2K { // Attributes SketchPad pad; DrawingTool pen; // Constructor
import java.math.BigInteger; import java.util.HashMap; /** * * @author cypronmaya */ public class test {
import java.lang.ref.SoftReference; import java.util.HashMap; import android.graphics.drawable.Drawable; import android.os.Handler; import android.os.Message; public class AsyncImageLoader {
import javax.swing.JOptionPane; public class RotateArrayCircularLL { private Node head=null; public void init() { int
import java.util.*; import java.io.*; import java.util.regex.*; class ZiggyTest2 extends Thread{ String sa; public ZiggyTest2(String
import javax.swing.JOptionPane; public class Mate { double suma (double x1,double x2) {return x1+x2;} double

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.