Freecode graphics
From Future Skill
Contents
Graphics utility functionality in Freecode creator
For executor version 3
Before you start working go to the settings tab in the Freecode creator and check that your executor version is correct. This guide is created for executor version 3, but some parts might be applicable for other versions as well.
Configuring the canvas
Configuration of the canvas is done through the settings in the Freecode creator. In the graphics there is an option to determine if the implementation should make use of multiple steps or a single step. If you plan on making multiple graphics updates then make sure this option is checked. There is also a background color option which determines what the default background color of the canvas will be. Lastly there is also a resolution option, which determines both the maximum indexes available for placing graphics (possible to use decimals), and what dimensions the canvas will have. If making use of multiple steps, the step time is further used to determine the time spent on each step. Setting up the API In the Freecode creator there is an API tab, where one can add, edit and remove API methods. For it to be possible for the implementation to call a method in the solution, or for a solution to call a method in the Implementation through the API, those methods must be defined here. The comments and information added here will be available to anyone taking part of your challenge or exercise. To see previews of how it will look for them you can look in the preview tab. In order for the solution and implementation to remain compatible with any changes to the names of methods, arguments, or types, all those changes have to be made through this page. Of course you can create any number of methods that are not defined here, but you will only be able to call them internally in that file.
The solution
In the Freecode creator there is a solution tab, this is so you will have the possibility of creating a default solution used for verifying that the implementation works. When a user will attempt to make their own solution, they will be given the boiler plate code you can see in the preview tab.
The implementation
In the implementation tab you can set up the actual code that is used to run the challenge/exercise. The behaviour of the different levels are defined, the canvas data is configured, and scores are set here.
Printing to the console
Print from the solution
To print from the solution to the console just use the regular print statement used by your language. In python3 it would be "print('hello world')".
Print from the implementation
In order to write to the console from the implementation one has to access either the console from the context, or one can access a console linked to a specific solution. Printing to specific solutions can be useful when creating a tournament where multiple solutions compete against each other.
self._context.console.log('Everyone can always see this')
self._context.console.debug('Everyone can see this during development')
solution.console.log('Only the tagged solution can see this')
solution.console.debug('The tagged solution can only see this during development')
If multiple logs will be done it can be useful to temporarily save the console object and use that one.
console = self._context.console
console.log('Everyone can always see this')
Accessing the canvas object
The canvas object which is used to create graphical objects is part of the context. To create a simple red circle placed 5 units into the canvas, sized 2 canvas units, one can use
self._context.canvas.new_circle(2, 'red', x=5, y=5)
To avoid writing “self._context.” every time one can temporarily store the canvas as a separate variable.
canvas = self._context.canvas
canvas.new_circle(2, 'red', x=5, y=5)