Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: new to java need help with code asap

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default new to java need help with code asap

    hi guy, this is my first post and i need help with one of my codes asap. I am trying to replace the ellipses and rect with my custom logo. I am having trouble doing that. I know it's sounds very noobish but i guess that's how u learn.
    here is the code. I am using processing to write java
       void setup()  
        { 
          size(400, 400);  
          noStroke(); 
          rectMode(CENTER);
        } 
     
        void mouseDragged()  
        {    
          interact();
        }
     
        void draw () {
        }
        //
        void interact () {
          background(51);  
          fill(255, 80, 190);
          customLogo(width-mouseX, height/2, ((height-mouseY)/2)+10, ((height-mouseY)/2)+10);
          fill(55, 80, 105);
          customLogo(mouseX, height/2, mouseY/2+10, mouseY/2+10); 
          fill(0, 80, 219); 
          customLogo(width-mouseX+random(3), height/2, ((height-mouseY)/2)+10, ((height-mouseY)/2)+10);
          fill(200, 70, 119); 
          customLogo(width-mouseX, height/5, ((height-mouseY)/5)+10, ((height-mouseY)/5)+10);
        }
        void customLogo( ) {
           int x;
           int y;
            int squareSize;
          color fillColor = color (255, 0, 0); // color of square
          color strokeColor = fillColor;
     
          rectMode(CENTER);
          fill(fillColor);
          stroke(strokeColor);
          rect(x, y, squareSize, squareSize);
          textAlign(CENTER);
          fill(255);
          text("U", x, y+10);
        } // function

    I have another assignment with i need help with here are the instructions. I have no idea how to do the connect lines
    i have to write a sketch as the user clicks on the screen, small pulses are created. When the user hits the 'd' key, the pulses are connected together by lines with the first line segment between the first and second points made, the second line segment between the second and third points made, etc. Allow the user the clear the canvas and start over by hitting the space bar. b. Rewrite so that the first connecting line has a stroke of 1, the next a stroke of 2, the third a stroke of 3, etc. c. Rewrite so that the order in which the line is drawn is reversed, i.e., the first line sgement is drawn between the last and next-to-last points, the second line segement is drawn between the next-to-last and third-from-last points, etc
    the code

        // ----------------------------------------------------------------------
        // CUSTOM CLASSES
        // ----------------------------------------------------------------------
        //Pulse is a class that draws a pulsing dot on the screen
        class Pulse {
          /* properties */
          int SCALE = 50;
          int x;    // x-coordinate of the pulse
          int y;    // y-coordinate of the pulse
          float s;  // size of the pulse
          color myColor = color(255, 255, 255); //default color
          /* methods */
          // constructor 1
          public Pulse(int pulseX, int pulseY) {
            x = pulseX;
            y = pulseY;
            s = 5;
          }
          // constructor 2
          public Pulse(int pulseX, int pulseY, int pulseScale) {
            x = pulseX;
            y = pulseY;
            SCALE = pulseScale;
            s = 0;
          }
          // constructor 3
          public Pulse() {
            x = 0;
            y = 0;
            s = 0;
          }
          // constructor 4
          public Pulse(int pulseX, int pulseY, int pulseScale, color newColor) {
            x = pulseX;
            y = pulseY;
            SCALE = pulseScale;
            s = 0;
            myColor = newColor;
          }
          // moves the pulse to the given position
          void move(int newX, int newY) {
            x = newX;
            y = newY;
          }
          // draws the pulse and updates its size
          void display() {
            fill(myColor);
            stroke(0);
            ellipse(x, y, sin(s)*SCALE, sin(s)*SCALE);
            s += 0.1;
          }
        }
        // ----------------------------------------------------------------------
        // GLOBAL VARIABLES
        // ----------------------------------------------------------------------
        int numPulses = 100;
        //counter tracking how many pulse objects have been istantiated
        int pulseArrayCounter = 0;
        //create of any array type pulse pulse array with 1000 elements
        Pulse[] pulseArray = new Pulse[numPulses];
        int xPos, yPos; // x and y coordinates
        // boolean to check when the array is full,set its index to "0" and redraws the pulse.
        boolean arrayIsFull = false;
        // ----------------------------------------------------------------------
        // BUILT-IN FUNCTIONS
        // ----------------------------------------------------------------------
        void setup() {
          size(400, 400);
          smooth();
          color tempColor = color(random(255), random(255), random(255));
        }
        void draw() {
          background(0);
          // draw the pulse
          for (int index = 0; index < pulseArrayCounter; index++) {
            pulseArray[index].display();
          }
        }
        void mouseDragged() {
          stopMessage();
        }
        void mousePressed() {
          stopMessage();
        }
        void stopMessage() {
          color tempColor = color(random(255), random(255), random(255));
          int newScale = int(random(100));
          // initialize a new pulse object
          if (pulseArrayCounter < pulseArray.length) {
            pulseArray[pulseArrayCounter] = new Pulse(mouseX, mouseY, newScale, tempColor);
            pulseArrayCounter++;
          }
          else {
            arrayIsFull = true;
            pulseArrayCounter = 0;
          }
        }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: new to java need help with code asap

    Do you have any specific questions?
    Do you get any error messages? Please copy and paste the full text here.

    You have not posted code that will compile and execute so its impossible for anyone to test your code.

Similar Threads

  1. [SOLVED] Can someone help me with this code asap
    By Darkcore123 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: November 14th, 2011, 11:55 AM
  2. Need some help with this code - Asap
    By Th3T3chGuy in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 10th, 2011, 07:17 AM
  3. Replies: 0
    Last Post: July 19th, 2010, 04:30 PM
  4. Need simple JAVA program fixing ASAP
    By theviper in forum Paid Java Projects
    Replies: 1
    Last Post: April 14th, 2010, 10:59 AM
  5. Replies: 1
    Last Post: April 1st, 2009, 02:47 PM