<commit_before>package turtlepath;

import java.io.Serializable;
import java.util.LinkedList;
import gui.init.colorpicker.ColorChangeInterface;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import model.Turtle;
/**
 * @author <NAME> (sml59)
 */
public class Trail extends Canvas implements ColorChangeInterface, Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 9060832315824592272L;
	private GraphicsContext context = getGraphicsContext2D();
	private LinkedList<Moment> history = new LinkedList<Moment>();
	private Color penColor = Color.BLACK;
	private String penColorString = penColor.toString();
	/**
	 * @return the penColorString
	 */
	public String getPenColorString() {
		return penColorString;
	}

	/**
	 * @param penColorString the penColorString to set
	 */
	public void setPenColorString(String penColorString) {
		this.penColorString = penColorString;
	}

	private Turtle turtle;
//  This looks terrible:
//	private ChangeListener<? super Number> listener = new ChangeListener<Number>() {
//        @Override
//        public void changed(ObservableValue<? extends Number> observable, Number oldVal, Number newVal) {
//           System.out.println(" oldVal " + oldVal + " newVal " + newVal);
//           update();
//        }
//	};
	
	public Trail(Turtle t) {
		turtle = t;
		//turtle.move.addListener(listener); -> This looks terrible
		turtle.move.addListener((ob,oV,nV)->update());  //This looks fantastic
		update();
	}
	
	public void update() {
		history.add(new Moment(turtle.getX(), turtle.getY(), turtle.isPenDown(), penColor));
		draw();
	}
	
	public void draw() {
		context.clearRect(0, 0, this.getWidth(), this.getHeight());
		for (int i = 1; i < history.size(); i++) {
			Moment current = history.get(i);
			Moment prev = history.get(i-1);
			context.setStroke(current.getColor());
			if (current.getIsPenDown()) {
				context.strokeLine(prev.getX(), prev.getY(), current.getX(), current.getY());
			}
		}	
	}

	@Override
	public void changeColor(Color color) {
		penColor = color;
	}
}
<commit_msg>fix the trail off issue<commit_after>package turtlepath;

import java.io.Serializable;
import java.util.LinkedList;
import gui.init.colorpicker.ColorChangeInterface;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import model.Turtle;
/**
 * @author <NAME> (sml59)
 */
public class Trail extends Canvas implements ColorChangeInterface, Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 9060832315824592272L;
	private GraphicsContext context = getGraphicsContext2D();
	private LinkedList<Moment> history = new LinkedList<Moment>();
	private Color penColor = Color.BLACK;
	private String penColorString = penColor.toString();
	/**
	 * @return the penColorString
	 */
	public String getPenColorString() {
		return penColorString;
	}

	/**
	 * @param penColorString the penColorString to set
	 */
	public void setPenColorString(String penColorString) {
		this.penColorString = penColorString;
	}

	private Turtle turtle;
//  This looks terrible:
//	private ChangeListener<? super Number> listener = new ChangeListener<Number>() {
//        @Override
//        public void changed(ObservableValue<? extends Number> observable, Number oldVal, Number newVal) {
//           System.out.println(" oldVal " + oldVal + " newVal " + newVal);
//           update();
//        }
//	};
	
	public Trail(Turtle t) {
		turtle = t;
		//turtle.move.addListener(listener); -> This looks terrible
		turtle.move.addListener((ob,oV,nV)->update());  //This looks fantastic
		update();
	}
	
	public void update() {
		history.add(new Moment(turtle.getX(), turtle.getY(), turtle.isPenDown(), penColor));
		draw();
	}
	
	public void draw() {
		context.clearRect(0, 0, this.getWidth(), this.getHeight());
		for (int i = 1; i < history.size(); i++) {
			Moment current = history.get(i);
			Moment prev = history.get(i-1);
			context.setStroke(current.getColor());
			if (current.getIsPenDown()) {
				context.strokeLine(prev.getX() + turtle.screenWidth.get()/2, prev.getY() + turtle.screenHeight.get()/2, current.getX() + turtle.screenWidth.get()/2, current.getY() + turtle.screenHeight.get()/2);
			}
		}	
	}

	@Override
	public void changeColor(Color color) {
		penColor = color;
	}
}

{'fraction_non_alphanumeric': 0.13636363636363635, 'fraction_numerical': 0.01235657546337158, 'mean_word_length': 4.042269187986652, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3918494', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1404, 'n_words': 330}