Results 1 to 1 of 1
  1. #1
    stark123 is offline Member
    Join Date
    Nov 2011
    Posts
    1
    Rep Power
    0

    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

    Java Code:
    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

    Java 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;
          }
        }
    Last edited by stark123; 11-13-2011 at 08:08 PM.

Similar Threads

  1. Short java programming, need help ASAP
    By j@y in forum New To Java
    Replies: 7
    Last Post: 11-08-2011, 06:13 PM
  2. Java Balancing Tree, please help right away ASAP !!!!
    By Jumanji245 in forum New To Java
    Replies: 2
    Last Post: 05-31-2011, 01:27 AM
  3. Help I need to make this code simpler ASAP!!
    By Quizzle23 in forum New To Java
    Replies: 5
    Last Post: 03-10-2011, 03:10 AM
  4. problems with java code! (very new - need help asap!)
    By sumkindafreek in forum New To Java
    Replies: 1
    Last Post: 01-07-2009, 06:00 AM
  5. Need Java Help ASAP
    By L-dog in forum New To Java
    Replies: 22
    Last Post: 10-03-2008, 12:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •