my program
in
Contributed Library Questions
•
2 years ago
I make a program.
Now I have a few questions because there are a lot bugs in my program.
So is in the third screen (state D) the button wrong. how can I fix that?
By state W there must be a random word for 0,9 sec but it isn't. And how can it appear left or right and not from 200 until 400?
An other problem is that in the textfield a person must typ the word that they saw before but how can I program that whhen it word is good there is a screen "the word is good' and when its wrong 'the word is wrong try again'.
Can someone help me?
- import controlP5.*;
- PFont fontA;
- int rectX, rectY; // Position of square button
- int circleX, circleY; // Position of circle button
- int rectSizeh = 40; // Diameter of rect
- int rectSizew = 100;
- color rectColor, baseColor;
- color rectHighlight;
- color currentColor;
- boolean rectOver = false;
- String tekst1, tekst2;
- char State;
- int timeOffset;
- float timeToNextk;
- float timeToNextw;
- float timeToNexte;
- import controlP5.*;
- ControlP5 controlP5;
- String textValue = "";
- Textfield myTextfield;
- Woorden[] woorden = new Woorden[300];
- /*
- STATES:
- E = Beginscherm --
- B = Begin1 --
- D = Begin2 --
- K = Kruis --
- W = Woord --
- T = Antwoord --
- G = Goed --
- F = Fout --
- N = einde --
- */
- void setup() {
- size(600, 600);
- background(255);
- timeToNextk = random (3000, 5000);
- timeToNextw = (3000);
- timeToNexte = (7000);
- State = 'E';
- }
- void draw() {
- if (State == 'E') {
- background(255);
- runWoordHerkenning();
- for (int i = 0; i < 250; i = i +15 ) {
- woorden[i] = new Woorden(random(width), random(height));
- }
- for (int i = 0; i < 250; i = i+15 ) {
- woorden[i].display();
- }
- if (timeToNexte <= millis()-timeOffset) {
- State = 'B';
- }
- }
- if (State == 'B') {
- background(255);
- displayKruis(width/2, height/2, 0);
- runtekst ();
- drawknop ();
- ;
- }
- if (State == 'D') {
- background(255);
- displayKruis(width/2, height/2, 0);
- runtekst2 ();
- drawknop ();
- ;
- }
- if (State == 'K') {
- background(255);
- float m = millis();
- noStroke();
- displayKruis(width/2, height/2, (m % 300));
- if (timeToNextk <= millis()-timeOffset) {
- State = 'W';
- ;
- }
- }
- if (State == 'W') {
- background(255);
- woord () ;
- if (timeToNextw <= millis()-timeOffset) {
- State = 'T';
- }
- if (State == 'T') {
- background(255);
- runtekstantwoord();
- controlP5 = new ControlP5(this);
- myTextfield = controlP5.addTextfield("Antwoord", 100, 200, 400, 20);
- myTextfield.setFocus(true);
- myTextfield.setColorBackground(color(190, 190, 240)); //Background text field
- myTextfield.setColorCaptionLabel(color(255)); // text nietzichtbaar
- myTextfield.setColorActive(color(0)); //stroke
- myTextfield.setColorValue(color(0)); //tekst in hokje
- // void controlEvent(ControlEvent theEvent) {
- // println(theEvent.controller().name()+": "+theEvent.controller().stringValue()); //printen antwoord (is nog wat fout mee)
- //}
- }
- }
- }
- void mousePressed() {
- switch(State) {
- case 'B':
- State = 'D';
- break;
- case 'D':
- State = 'K';
- /* setting the baseline for the timer
- this is being used in draw()
- to switch to WAIT after a while */
- timeOffset = millis();
- break;
- }
- }
- class Woorden {
- // variables
- float x, y;
- // constructor
- Woorden(float tempX, float tempY) {
- x = tempX;
- y = tempY;
- }
- // Move the text
- // Display
- void display() {
- fontA = loadFont("Arial-BoldMT-12.vlw");
- textFont(fontA, 12);
- fill (0,0, random (50,255));
- String[] words = {
- "computer", "test", "woorden", "psychologie", "herkenning", "onthouden", "typen"
- };
- int index = int(random(words.length)); // same as int(random(6))
- text(words[index], x, y);
- }
- }
- void runWoordHerkenning() {
- fontA = loadFont("Arial-BoldMT-40.vlw");
- // de font en de grootte van het lettertype
- textFont(fontA, 40);
- fill (110,90,255);
- text("WoordherkenningsTest", 55, 300);
- }
- void drawknop()
- {
- rectColor = color(190,190,240);
- rectHighlight = color(110,90,255);
- baseColor = color(255);
- currentColor = baseColor;
- rectX = width/2-(rectSizew/2);
- rectY = 500;
- update(mouseX, mouseY);
- if (rectOver) {
- fill(rectHighlight);
- }
- else {
- fill(rectColor);
- }
- stroke(0);
- rect(rectX, rectY, rectSizew, rectSizeh);
- fill(0); // black
- text("Continue", rectX+10, rectY+25);
- }
- void update(int x, int y)
- {
- if ( overRect(rectX, rectY, rectSizew, rectSizeh) ) {
- rectOver = true;
- }
- else {
- rectOver = false;
- }
- }
- boolean overRect(int x, int y, int width, int height)
- {
- if (mouseX >= x && mouseX <= x+width &&
- mouseY >= y && mouseY <= y+height) {
- return true;
- }
- else {
- return false;
- }
- }
- void displayKruis(float x, float y, float c) {
- int w = 20;
- int h = 100;
- rectMode(CENTER);
- fill (c);
- rect(x, y, w, h);
- rect(x, y, h, w);
- fill(110,90,255);
- ellipse(x, y, 10, 10);
- rectMode(CORNERS);
- }
- // GLOBAL
- int x = 30;
- // FUNCTIONS
- void runtekst() {
- fontA = loadFont("Arial-BoldMT-16.vlw");
- // de font en de grootte van het lettertype
- textFont(fontA, 16);
- rectMode (CORNER);
- tekst1 = "In het volgende experiment, word een kruis getoond. Daarna volgt een woord dat verschijnt aan de linker of rechterkant van het kruis. Het woord verschijnt snel. Als je het woord kan lezen,dan kan je daarna het woord typen. Als het woord te snel verschijnt dan druk op ENTER en probeer opnieuw. Elke keer wanneer het woord verschijnt, verschijnt het wat langer in beeld." ;
- tekst2 = "Voor het onderzoek is het van belang dat je je ogen richt op het knipperende kruis.";
- fill (0);
- text(tekst1, x, 60, 500, 500);
- }
- void runtekst2() {
- fontA = loadFont("Arial-BoldMT-16.vlw");
- // de font en de grootte van het lettertype
- textFont(fontA, 16);
- fill (0);
- text("Voor het onderzoek is het van belang dat je je ogen richt op het knipperende kruis.", x, 60, 540, 400);
- }
- void runtekstantwoord() {
- fontA = loadFont("Arial-BoldMT-16.vlw");
- // de font en de grootte van het lettertype
- textFont(fontA, 16);
- fill (0);
- text("Hieronder kan je het woord invullen wat je net zag.", x, 140, 540, 400);
- }
- void runtekstgoed() {
- fontA = loadFont("Arial-BoldMT-16.vlw");
- // de font en de grootte van het lettertype
- textFont(fontA, 16);
- fill (0, 225, 0);
- text("Het woord is GOED. Druk op ENTER om naar de volgende te gaan.", x, 60, 540, 400);
- }
- void runtekstfout() {
- fontA = loadFont("Arial-BoldMT-16.vlw");
- // de font en de grootte van het lettertype
- textFont(fontA, 16);
- fill (225, 0, 0);
- text("Het woord is FOUT. Druk op ENTER om het opnieuw te proberen.", x, 60, 540, 400);
- }
- void woord () {
- float kant;
- float links = (100);
- float rechts = (500);
- kant = random (links, rechts);
- fontA = loadFont("Arial-BoldMT-16.vlw");
- textFont(fontA, 16);
- fill (0);
- String[] words = {
- "smaak", "tafels", "friet", "print", "licht", "geval", "paard", "laars", "plots", "kapel"
- };
- int index = int(random(words.length)); // same as int(random(10))
- println(words[index]); // prints one of the six words
- text(words[index], kant, 300);
- }
1