На главную Наши проекты:
Журнал   ·   Discuz!ML   ·   Wiki   ·   DRKB   ·   Помощь проекту
ПРАВИЛА FAQ Помощь Участники Календарь Избранное RSS
msm.ru
! Следующие правила действуют в данном разделе в дополнение к общим Правилам Форума
1. Здесь обсуждается Java, а не JavaScript! Огромная просьба, по вопросам, связанным с JavaScript, SSI и им подобным обращаться в раздел WWW Masters или, на крайний случай, в Многошум.
2. В случае, если у вас возникают сомнения, в каком разделе следует задать свой вопрос, помещайте его в корневую ветку форума Java. В случае необходимости, он будет перемещен модераторами (с сохранением ссылки в корневом разделе).

3. Запрещается создавать темы с просьбой выполнить какую-то работу за автора темы. Форум является средством общения и общего поиска решения. Вашу работу за Вас никто выполнять не будет.
4. Не рекомендуется создавать несколько несвязанных вопросов в одной теме. Пожалуйста, создавайте по одной теме на вопрос.
Модераторы: dark_barker, wind
  
> Spaceship Angel Software
    # SciFi UI Project

    Name: Jurjius Pacalovas

    Student Number: C17706201

    Fork this repository and use it a starter project for your assignment

    # Description of the assignment#
    I have written software that let you fly on the space it has stars, ship, radar, a circle, audio, galaxies, and buttons.


    # Instructions Just look!

    # How it works

    # Markdown Tutorial

    This is *emphasis*

    This is a bulleted list

    - Main.java
    - MovingCircle.java
    - Radar.java
    - stars.java
    - UI.java

    This is a numbered list

    - Main.java
    - MovingCircle.java
    - Radar.java
    - stars.java
    - UI.java


    # Headings
    ## Headings
    #### Headings
    ##### Headings

    This is code:

    ```Java
    public void render()
    {
    ui.noFill();
    ui.stroke(255);
    ui.rect(x, y, width, height);
    ui.textAlign(PApplet.CENTER, PApplet.CENTER);
    ui.text(text, x + width * 0.5f, y + height * 0.5f);
    }
    ```

    So is this without specifying the language:

    ```
    public void render()
    {
    ui.noFill();
    ui.stroke(255);
    ui.rect(x, y, width, height);
    ui.textAlign(PApplet.CENTER, PApplet.CENTER);
    ui.text(text, x + width * 0.5f, y + height * 0.5f);
    }
    ```

    This is a youtube video:

    [![YouTube](.........................................[/URL])

    Main.java

    ExpandedWrap disabled
      package ie.tudublin;
       
      public class Main
      {  
       
          public void startUI()
          {
              String[] a = {"MAIN"};
              processing.core.PApplet.runSketch( a, new UI());
              
          }
       
          public static void main(String[] args)
          {
              Main main = new Main();
              main.startUI();        
          }
      }

    MovingCircle.java
    ExpandedWrap disabled
      package ie.tudublin;
       
      import processing.core.PApplet;
       
      public class MovingCircle
      {
          private float x;
          private float dx = 1;
          private float y;
          private float diameter;
          private float radius;
          UI ui;
       
          public MovingCircle(UI ui, float x, float y, float diameter)
          {
              this.ui = ui;
              this.x = x;
              this.y = y;
              this.diameter = diameter;
              radius = diameter / 2;
          }
          
          public void render()
          {
              ui.stroke(255);
              ui.noFill();
              ui.ellipse(x, y, diameter, diameter);
              ui.fill(255);
              // Static field
              ui.textAlign(PApplet.CENTER, PApplet.CENTER);
              ui.text("I am a moving circle", x, y);
       
          }
       
          public void update()
          {
              x += dx;
              if ((x > ui.width - radius) || (x < radius))
              {
                  dx *= -1;
              }
          }
      }

    Product.java
    ExpandedWrap disabled
      package ie.tudublin;
       
      import processing.data.*;
       
      public class Product
      {
          private String name;
          private float price;
       
          public Product(String name, float price)
          {
              this.name = name;
              this.price = price;
          }
       
          public String toString()
         {
              return name + "\t" + price;
          }
       
          public Product(TableRow tr)
          {
              // Constructor chaining
              this(tr.getString("Name"), tr.getFloat("Price"));
          }
       
          /**
           * @return the name
           */
          public String getName() {
              return name;
          }
       
          /**
           * @param name the name to set
           */
          public void setName(String name) {
              this.name = name;
          }
       
          /**
           * @return the price
           */
          public float getPrice() {
              return price;
          }
       
          /**
           * @param price the price to set
           */
          public void setPrice(float price) {
              this.price = price;
          }
          
      }


    Radar.java
    ExpandedWrap disabled
      package ie.tudublin;
       
      import processing.core.PApplet;
      import processing.core.PVector;
       
      public class Radar {
          private float radius;
          private PVector pos;
          private float frequency;
          private UI ui;
          private float theta = 0;
       
          public Radar(UI ui, float frequency, float x, float y, float radius) {
              this.ui = ui;
              this.frequency = frequency;
              pos = new PVector(x, y);
              this.radius = radius;
          }
       
          public void render() {
              /*
               * ui.pushMatrix(); ui.noFill(); ui.stroke(0, 200, 0); ui.translate(pos.x,
               * pos.y); ui.rotate(theta); ui.ellipse(0, 0, radius * 2, radius * 2);
               * ui.line(0,0,0,-radius); ui.popMatrix();
               */
       
              ui.noFill();
              ui.ellipse(pos.x, pos.y, radius * 2, radius * 2);
              ui.ellipse(pos.x, pos.y, radius * 3, radius * 3);
              ui.ellipse(pos.x, pos.y, radius * 4, radius * 4);
       
              float x2 = pos.x + (float) Math.sin(theta) * radius * 2;
              float y2 = pos.y - (float) Math.cos(theta) * radius * 2;
              ui.line(pos.x, pos.y, x2, y2);
       
              // Here I have maked to move ships
              float lenu = ui.random(250, ui.width = 540);
              float lonu = ui.random(250, ui.height = 540);
              ui.fill(255, 0, 255);
              ui.ellipse(lenu, lonu, 50, 50);
              ui.ellipse(lenu, lonu, 50, 50);
              ui.ellipse(lenu, lonu, 50, 50);
              ui.ellipse(lenu, lonu, 50, 50);
              ui.ellipse(lenu, lonu, 50, 50);
              ui.noStroke();
       
              float lenj = ui.random(250, ui.width = 540);
              float lonj = ui.random(250, ui.height = 540);
              ui.fill(255, 255, 0);
              ui.ellipse(lenj, lonj, 50, 50);
              ui.ellipse(lenj, lonj, 50, 10);
              ui.ellipse(lenj, lonj, 50, 50);
              ui.ellipse(lenj, lonj, 50, 50);
              ui.ellipse(lenj, lonj, 50, 50);
              ui.noStroke();
       
              float lend = ui.random(250, ui.width = 540);
              float lond = ui.random(250, ui.height = 540);
              ui.fill(123, 123, 212);
              ui.ellipse(lend, lond, 50, 50);
              ui.ellipse(lend, lond, 50, 50);
              ui.ellipse(lend, lond, 50, 50);
              ui.ellipse(lend, lond, 50, 50);
              ui.ellipse(lend, lond, 50, 50);
              ui.noStroke();
          }
       
          float timeDelta = 1.0f / 60.0f;
       
          public void update() {
              theta += PApplet.TWO_PI * timeDelta * frequency;
          }
       
          /**
           * @return the radius
           */
          public float getRadius() {
              return radius;
          }
       
          /**
           * @param radius the radius to set
           */
          public void setRadius(float radius) {
              this.radius = radius;
          }
       
          /**
           * @return the pos
           */
          public PVector getPos() {
              return pos;
          }
       
          /**
           * @param pos the pos to set
           */
          public void setPos(PVector pos) {
              this.pos = pos;
          }
       
          /**
           * @return the frequency
           */
          public float getFrequency() {
              return frequency;
          }
       
          /**
           * @param frequency the frequency to set
           */
          public void setFrequency(float frequency) {
              this.frequency = frequency;
          }
       
      }


    stars.java
    ExpandedWrap disabled
      package ie.tudublin;
       
      import processing.core.PApplet;
       
      public class stars {
       
          PApplet ui;
          float len, lon;
       
          public stars(PApplet ui, float len, float lon) {
       
              this.ui = ui;
              this.len = len;
              this.lon = lon;
          }
       
          public void drawStars() {
              // sets the random value of the stars
              // uses the width and height of screen to do this
              float len = ui.random(0, ui.width = 1000);
              float lon = ui.random(0, ui.height = 1000);
              ui.fill(255, 3);
              ui.rect(0, 0, ui.width, ui.height);
              ui.fill(255, 14, 17);
              ui.ellipse(len, lon, 5, 5);
              ui.fill(255, 255, 0);
              ui.fill(255, 122, 123);
              ui.ellipse(len, lon, 10, 10);
              ui.fill(255, 255, 255);
              ui.fill(255, 255, 0);
              ui.ellipse(len, lon, 7, 5);
       
              ui.fill(len, lon, len);
              ui.ellipse(310, lon, 5, 5);
              ui.ellipse(320, lon, 5, 5);
              ui.ellipse(330, lon, 5, 5);
              ui.ellipse(330, lon, 5, 5);
              ui.ellipse(340, lon, 5, 5);
              ui.ellipse(350, lon, 5, 5);
              ui.ellipse(360, lon, 5, 5);
              ui.ellipse(370, lon, 5, 5);
              ui.ellipse(380, lon, 5, 5);
              ui.ellipse(390, lon, 5, 5);
              ui.ellipse(400, lon, 5, 5);
              ui.ellipse(410, lon, 5, 5);
              ui.ellipse(420, lon, 5, 5);
              ui.ellipse(430, lon, 5, 5);
              ui.ellipse(440, lon, 5, 5);
              ui.ellipse(450, lon, 5, 5);
              ui.ellipse(460, lon, 5, 5);
              ui.ellipse(470, lon, 5, 5);
       
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(350, lon, 5, 5);
              ui.ellipse(360, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(380, lon, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(len, 510, 5, 5);
              ui.ellipse(480, lon, 5, 5);
       
              ui.ellipse(250, lon, 5, 5);
              ui.ellipse(260, lon, 5, 5);
              ui.ellipse(len, 430, 5, 5);
              ui.ellipse(len, 440, 5, 5);
              ui.ellipse(len, 450, 5, 5);
              ui.ellipse(len, 460, 5, 5);
              ui.ellipse(len, 470, 5, 5);
              ui.ellipse(len, 480, 5, 5);
              ui.ellipse(len, 490, 5, 5);
              ui.ellipse(len, 400, 5, 5);
              ui.ellipse(len, 410, 5, 5);
              ui.ellipse(len, 420, 5, 5);
              ui.ellipse(len, 430, 5, 5);
              ui.ellipse(len, 440, 5, 5);
              ui.ellipse(len, 450, 5, 5);
              ui.ellipse(len, 460, 5, 5);
              ui.ellipse(400, lon, 5, 5);
              ui.ellipse(len, 480, 5, 5);
              ui.ellipse(lon, 490, 5, 5);
              ui.ellipse(len, 500, 5, 5);
              ui.ellipse(lon, 410, 5, 5);
              ui.ellipse(450, len, 5, 5);
              ui.ellipse(lon, len, 5, 5);
              ui.ellipse(len, lon, 5, 5);
              ui.ellipse(len, lon, 5, 5);
              ui.ellipse(len, lon, 5, 5);
              ui.ellipse(len, lon, 5, 5);
              ui.ellipse(len, lon, 5, 5);
       
              ui.ellipse(len, lon, 5, 5);
              ui.ellipse(len, lon, 5, 5);
              ui.ellipse(len, lon, 5, 5);
              ui.ellipse(len, lon, 5, 5);
              ui.ellipse(len, lon, 5, 5);
              ui.ellipse(len, lon, 5, 5);
              ui.ellipse(len, lon, 5, 5);
       
              ui.noStroke();
       
              ui.fill(255, 248, 128);
              ui.rect(0, 0, 200, 800);
              ui.rect(700, 800, 200, -800);
              ui.rect(0, 100, 800, -800);
              ui.rect(0, 700, 800, 100);
       
          }
      }

    UI.java
    ExpandedWrap disabled
      package ie.tudublin;
       
      import java.util.ArrayList;
      import processing.core.PApplet;
      import processing.data.Table;
      import processing.data.TableRow;
       
      import ddf.minim.AudioInput;
      import ddf.minim.Minim;
      import ddf.minim.analysis.FFT;
       
      public class UI extends PApplet {
       
          ArrayList<Product> products = new ArrayList<Product>();
       
          MovingCircle mc;
          stars star;
       
          boolean[] keys = new boolean[1024];
       
          public void keyPressed() {
              keys[keyCode] = true;
          }
       
          public void keyReleased() {
              keys[keyCode] = true;
          }
       
          public boolean checkKey(int c) {
              return keys[c] || keys[Character.toUpperCase(c)];
          }
       
          public void settings() {
              size(800, 800);
              // Use fullscreen instead of size to make your interface fullscreen
              // fullScreen(P3D);
       
              minim = new Minim(this);
              ai = minim.getLineIn(Minim.MONO, FRAME_SIZE, SAMPLE_RATE, BITS_PER_SAMPLE);
              fft = new FFT(FRAME_SIZE, SAMPLE_RATE);
       
          }
       
          public void setup() {
       
              mc = new MovingCircle(this, width / 2, height * .75f, 50);
              radar = new Radar(this, 1, width / 2, height / 2, 100);
              star = new stars(this, 0, 0);
       
          }
       
          Radar radar;
       
          void loadProducts() {
              Table table = loadTable("fly.csv", "header");
              for (TableRow tr : table.rows()) {
                  Product p = new Product(tr);
                  products.add(p);
              }
          }
       
          public void mouseClicked() {
              int which = -1;
       
              // The best way!!
              if ((mouseX > border && mouseX < border + buttonWidth)) {
                  if ((mouseY - border) % (buttonHeight + gap) < buttonHeight) {
                      which = (int) ((mouseY - border) / (buttonHeight + gap));
                  }
              }
       
              // This also works
              /*
               * if (mouseX > border && mouseX < border + buttonWidth) { for(int i = 0 ; i <
               * products.size() ; i ++) { float y = border + (i * (buttonHeight + gap)); if
               * (mouseY > y && mouseY < y + buttonHeight) { which = i; break; } } }
               */
              if (which != -1) {
                  System.out.println(products.get(which));
              }
          }
       
          float border = 20;
          float buttonWidth = 200;
          float buttonHeight = 50;
          float gap = 20;
       
          AudioInput ai;
          FFT fft;
          Minim minim;
          public static final int FRAME_SIZE = 1024;
          public static final int SAMPLE_RATE = 44100;
          public static final int BITS_PER_SAMPLE = 16;
       
          void drawProductButtons() {
       
              for (int i = 0; i < products.size(); i++) {
                  Product p = products.get(i);
                  float y = border + (i * (buttonHeight + gap));
                  float x = border;
                  fill(255, 255, 0);
                  stroke(0);
                  rect(x, y, buttonWidth, buttonHeight);
                  textAlign(CENTER, CENTER);
                  fill(0);
                  text(p.getName(), x + buttonWidth * 0.5f, y + buttonHeight * 0.5f);
              }
          }
       
          public void draw() {
              background(0);
       
              mc.update();
              mc.render();
       
              radar.update();
              radar.render();
       
              star.drawStars();
       
              loadProducts();
       
              mouseClicked();
       
              drawProductButtons();
       
              if (checkKey('m')) {
                  stroke(255);
                  float middle = height / 2;
                  for (int i = 0; i < ai.bufferSize(); i++) {
                      stroke(map(i, 0, ai.bufferSize(), 0, 255), 255, 255);
                      line(i, middle, i, middle + ai.left.get(i) * middle);
                  }
       
                  fft.forward(ai.left);
       
                  for (int i = 0; i < fft.specSize(); i++) {
                      stroke(map(i, 0, ai.bufferSize(), 0, 255), 255, 255);
                      line(i, 0, i, fft.getBand(i) * 20);
                  }
              }
       
              if (checkKey('x')) {
                  System.exit(0);
              }
          }
       
      }
    Сообщение отредактировано: Dream2019 -
    0 пользователей читают эту тему (0 гостей и 0 скрытых пользователей)
    0 пользователей:


    Рейтинг@Mail.ru
    [ Script execution time: 0,0372 ]   [ 15 queries used ]   [ Generated: 19.03.24, 07:30 GMT ]