Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 applet -> none applet
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
HeavenAgain




PostPosted: Sun Jun 03, 2007 12:08 pm   Post subject: applet -> none applet

ummm, ok, can anyone "translate" the below languange into dr.java? (not in applet form?) so i can run this in my dr.java?
please and thank you Mr. Green
Java:

import java.awt.*;
import java.applet.*;

public class SierpinskiTriangle extends Applet {
    private Graphics g;
    private int dMin=4;    // limit to recursion in pixels

    public void paint(Graphics g) {
        this.g = g;
        int d  = 1024;    // basis (width of the triangle)
        int x0 =   50;    // distance from the left
        int y0 =   50;    // distance from the top
        int h  = (int)(d*Math.sqrt(3)/2);    // height
        // so: suitable for an equilateral triangle
        int xA=x0,      yA=y0+h;    // (bottom-left)
        int xB=x0+d,    yB=y0+h;    // (bottom-right)
        int xC=x0+d/2,  yC=y0;    // equilateral triangle (top-center)
        int[] x = { xA, xB, xC };
        int[] y = { yA, yB, yC };

        drawSierpinskiTriangle( x, y, d/2 );     // start recursion
    }

    private void drawSierpinskiTriangle ( int[] x, int[] y, int d ) {
        if (d<=dMin) g.fillPolygon ( x, y, 3 )// bottom of the recursion
        else {
            // centers of the sides:
            int xMc = (x[0]+x[1])/2,    yMc = (y[0]+y[1])/2;
            int xMb = (x[0]+x[2])/2,    yMb = (y[0]+y[2])/2;
            int xMa = (x[1]+x[2])/2,    yMa = (y[1]+y[2])/2;

            int[] xNew1 = { x[0], xMc, xMb };
            int[] yNew1 = { y[0], yMc, yMb };
            drawSierpinskiTriangle ( xNew1, yNew1, d/2 );    // recursion

            int[] xNew2 = { x[1], xMc, xMa };
            int[] yNew2 = { y[1], yMc, yMa };
            drawSierpinskiTriangle ( xNew2, yNew2, d/2 );    // recursion

            int[] xNew3 = { x[2], xMb, xMa };
            int[] yNew3 = { y[2], yMb, yMa };
            drawSierpinskiTriangle ( xNew3, yNew3, d/2 );    // recursion
        }
    }
}
Sponsor
Sponsor
Sponsor
sponsor
Ultrahex




PostPosted: Sun Jun 03, 2007 6:20 pm   Post subject: Re: applet -> none applet

#1, This is an applet .... you should be able to figure out how to run an applet....
#2, why should we do work for you?
#3, why cant you convert to something else yourself?

#4, here it is, but don't expect us to do it again

Java:

import java.awt.*;
import javax.swing.*;

public class SierpinskiTriangle {

    public static void main (String[]args) {
        new TriFrame();
    }
}

class TriFrame extends JFrame {
    Graphics g;
    int dMin=4;    // limit to recursion in pixels
   
    public TriFrame() {
        super();
        setVisible(true);
        setSize(1100,960);
    }
   
    public void paint(Graphics g) {
        this.g = g;
        int d  = 1024;    // basis (width of the triangle)
        int x0 =   50;    // distance from the left
        int y0 =   50;    // distance from the top
        int h  = (int)(d*Math.sqrt(3)/2);    // height
        // so: suitable for an equilateral triangle
        int xA=x0,      yA=y0+h;    // (bottom-left)
        int xB=x0+d,    yB=y0+h;    // (bottom-right)
        int xC=x0+d/2,  yC=y0;    // equilateral triangle (top-center)
        int[] x = { xA, xB, xC };
        int[] y = { yA, yB, yC };

        drawSierpinskiTriangle( x, y, d/2 );     // start recursion
    }

    private void drawSierpinskiTriangle ( int[] x, int[] y, int d ) {
        if (d<=dMin) g.fillPolygon ( x, y, 3 )// bottom of the recursion
        else {
            // centers of the sides:
            int xMc = (x[0]+x[1])/2,    yMc = (y[0]+y[1])/2;
            int xMb = (x[0]+x[2])/2,    yMb = (y[0]+y[2])/2;
            int xMa = (x[1]+x[2])/2,    yMa = (y[1]+y[2])/2;

            int[] xNew1 = { x[0], xMc, xMb };
            int[] yNew1 = { y[0], yMc, yMb };
            drawSierpinskiTriangle ( xNew1, yNew1, d/2 );    // recursion

            int[] xNew2 = { x[1], xMc, xMa };
            int[] yNew2 = { y[1], yMc, yMa };
            drawSierpinskiTriangle ( xNew2, yNew2, d/2 );    // recursion

            int[] xNew3 = { x[2], xMb, xMa };
            int[] yNew3 = { y[2], yMb, yMa };
            drawSierpinskiTriangle ( xNew3, yNew3, d/2 );    // recursion
        }
    }
}
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: