在处理中添加延迟

时间:2018-01-03 21:14:23

标签: random processing

所以我是Processing的新手,基本上我正在做一个程序,当它运行时,它会打开一个包含4个不同图像的窗口,每个图像都有下面的描述。在下面的方法中,我创建了两个随机方法,一个用于评论编号,另一个用于评论评论,我希望每个电影都不会一直生成评论 - 更像是随机弹出,因为它也会导致想要全部阅读它们的混乱很多。另外,为了检查天气,我可以将字符串和整数的数组一起添加到评论号的平均值。

以下是代码,非常感谢您的帮助。谢谢。

import g4p_controls.*;
import ddf.minim.*;

PFont font;
PImage img1,img2; // background images for two different windows
PImage fimg1, fimg2, fimg3, fimg4, fimg5, fimg6; //images of movies
int rectX,rectY;

GButton btn;
GWindow window;

Minim minim;
AudioPlayer player;

String[] rev_film1 = {"The Best Wolverine Movie","Logan is another level","Disappointment","Such a sad farewell"}; //Logan
String[] rev_film2 = {"A scary movie that isn't scary.","Terrifyingly brilliant.","The perfect blend of comedy and horror","The IT Factor"}; //IT
String[] rev_film3 = {"Soul-less,Confused,Loud.","Devastatingly Disappointed","A technical masterpiece","A visual wonder that lacks depth"}; //Dunkirk
String[] rev_film4 = {"Disgrace", "Worst Star Wars movie", "TERRIBLE","A Betrayal to the Legacy"}; //Starwars


int[] rat_film1 = {9,8,2,2}; 


float r;

void setup()
{
  size(1150,600,JAVA2D);
  surface.setTitle(" - The Theatre of Dreams Database - ");
  font = loadFont("BerlinSansFB-Reg-48.vlw");
  img1 = loadImage("film2.jpg");
  background(img1);

  btn = new GButton(this,900,350,100,50, "Enter Website");

  minim = new Minim(this);
  player = minim.loadFile("sound.mp3");
  player.play();
}

void draw()
{
  fill(255);
  textFont(font,32);
  text("Welcome to", 850, 85);
  text("The Theatre of Dreams", 760, 175);
  text("Database", 870, 220);
}

void handleButtonEvents(GButton button, GEvent event) 
{
  if (button == btn && event == GEvent.CLICKED) 
  {
    createWindow();
    btn.setEnabled(false);
  }
}

void createWindow() // creating new window with mouse click
{
  window =  GWindow.getWindow(this, " - Top 4 Movies in 2017 - ", 100, 50, 1150, 600, JAVA2D);
  window.addDrawHandler(this, "windowDraw");
  window.addOnCloseHandler(this, "windowClosing"); 
  window.setActionOnClose(GWindow.CLOSE_WINDOW);
}

void windowDraw(PApplet app, GWinData data)
{
  img2 = loadImage("film3.jpg");
  app.background(img2);

  app.text(" - Top 4 Movies in 2017 - ",440,85);
  app.fill(255);
  app.textFont(font,25);

  fimg1 = loadImage("logan.jpg");
  fimg2 = loadImage("it.jpg");
  fimg3 = loadImage("dunkirk.jpg");
  fimg4 = loadImage("starwars.jpg");

  //////////Film 1 - LOGAN
    app.image(fimg1,5,140,180,170);
    app.text("Rating: 8.1 / 10",5,340); //fixed rating

    app.text("Genres: Action | Drama", 5, 365);
    app.text("| Sci-Fi | Thriller",5,390);

    //Ratings that are constantly changing using the random function
    for (int i = 0; i < 50; i++) 
    {
      r = random(0, 6);
    }

    String user = "Ratings by users: " + nf(r,0,1) + " / 10";
    app.text(user, 5,430);

    // the random function of the comments
    int index = int(random(rev_film1.length)); 
    String user11 = "Reviews: " + "\n" + rev_film1[index];
    app.text(user11, 5,460);


  ////////////////////Film 2 - IT
    app.image(fimg2,960,360,180,170);
    app.text("Rating: 7.6 / 10", 700,400);
    app.text("Genres: Drama | Horror",700,430);
    app.text("| Thriller",700,460);

  //Ratings that are constantly changing using the random function
    for (int i = 0; i < 50; i++) 
    {
      r = random(5, 10);
    }
    String user2 = "Ratings by users: " + nf(r,0,1) + " / 10";
    app.text(user2, 700,500);
    int index2 = int(random(rev_film2.length)); // the random function of the comments
    String user22 = "Reviews: " + "\n" + rev_film2[index2];
    app.text(user22, 700,540);



  /////////Film 3 - DUNKIRK
    app.image(fimg3,320,250,180,170);
    app.text("Rating: 8.1 / 10",320,445); //fixed rating

    app.text("Genres: Action | Drama", 320, 470);
    app.text("| History | Thriller | War",320,495);

    //Ratings that are constantly changing using the random function
    for (int i = 0; i < 50; i++) 
    {
    r = random(0, 5);
    }

    String user3 = "Ratings by users: " + nf(r,0,1) + " / 10";
    app.text(user3, 320,530);
    int index3 = int(random(rev_film3.length)); // the random function of the comments
    String user33 = "Reviews: " + "\n" + rev_film3[index3];
    app.text(user33, 320,560);


  /////////////Film 4 - STAR WARS
    app.image(fimg4,570,120,180,170);
    app.text("Rating: 7.6 / 10", 760,140); //fixed rating

    app.text("Genres: Action | Adventure | Fantasy ", 760,168); 
    app.text("| Sci-Fi", 760,195);

    //Ratings that are constantly changing using the random function
    for (int i = 0; i < 50; i++) 
    {
      r = random(0, 2);
    }

    String user4 = "Ratings by users: " + nf(r,0,1) + " / 10";
    app.text(user4, 760,220);
    int index4 = int(random(rev_film4.length)); // the random function of the comments
    String user44 = "Reviews: " + "\n" + rev_film4[index4];
    app.text(user44, 760,250);
}


public void windowClosing(GWindow w)
{
  btn.setEnabled(false);
  player.close();
  minim.stop();
  exit();
}

1 个答案:

答案 0 :(得分:0)

请尝试发布MCVE而不是完整的程序。例如,尝试创建一个每X秒显示一个圆圈的简单草图。这样我们就可以专注于您的问题,而不是与您的问题无关的所有额外内容。

但是要回答你的问题,你可以使用millis()函数或frameCount变量来检查已经过了多少时间,然后每X秒或每X帧做一次。

相关帖子:

有关详细信息,请参阅the Processing reference

如果您仍然无法使其正常运行,请在新问题中发布MCVE(不是您的完整项目!),我们将从那里开始。祝你好运。