www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Plot one pixel in blue on a canvas

reply Alain De Vos <devosalain ymail.com> writes:
I want to plot a pixel in blue at coordinates (100,100) on a 
canvas of size (200,200)
I think i can use the arsd module.
But i have no idea what "dub add" comment I should use.
What i should import
How this demo program would look.
Cfr,
https://www.reddit.com/r/scala/comments/1h2g8a2/simple_graphics_api/
https://www.reddit.com/r/fsharp/comments/1h2g7pv/simple_graphics_api/
Nov 29
next sibling parent reply Sergey <kornburn yandex.ru> writes:
On Friday, 29 November 2024 at 14:02:38 UTC, Alain De Vos wrote:
 I want to plot a pixel in blue at coordinates (100,100) on a 
 canvas of size (200,200)
Check this lib from p0nce maybe https://code.dlang.org/packages/canvasity. So steps should be like: ```bash dub init dub add canvasity ``` Couple of demos are presented in the description.
Nov 29
parent Alain De Vos <devosalain ymail.com> writes:
On Friday, 29 November 2024 at 15:01:12 UTC, Sergey wrote:
 On Friday, 29 November 2024 at 14:02:38 UTC, Alain De Vos wrote:
 I want to plot a pixel in blue at coordinates (100,100) on a 
 canvas of size (200,200)
Check this lib from p0nce maybe https://code.dlang.org/packages/canvasity. So steps should be like: ```bash dub init dub add canvasity ``` Couple of demos are presented in the description.
Can i how the image on screen while i draw ?
Nov 29
prev sibling parent reply Aravinda VK <mail aravindavk.in> writes:
On Friday, 29 November 2024 at 14:02:38 UTC, Alain De Vos wrote:
 I want to plot a pixel in blue at coordinates (100,100) on a 
 canvas of size (200,200)
 I think i can use the arsd module.
 But i have no idea what "dub add" comment I should use.
 What i should import
 How this demo program would look.
 Cfr,
 https://www.reddit.com/r/scala/comments/1h2g8a2/simple_graphics_api/
 https://www.reddit.com/r/fsharp/comments/1h2g7pv/simple_graphics_api/
You can use Chitra library. It is still under active development, working on adding support for text and curves. Refer this documentation to install the dependencies and add Chitra to your project. Chitra is based on Cairo Graphics for 2D graphics and PangoCairo for rendering texts. https://github.com/aravindavk/chitra-d Example for your use case, ```d import chitra; void main() { auto ctx = new Chitra(200, 200); ctx.pixel(100, 100); ctx.saveAs("dot.png"); } ``` Or just run the file without installing it, like below. Create a file `dot.d` with the following content. ```d /+ dub.sdl: dependency "chitra" version="~>0.1.0" +/ import chitra; void main() { auto ctx = new Chitra(200, 200); ctx.pixel(100, 100); ctx.saveAs("dot.png"); } ``` And run as `dub dot.d` Let me know if this works for you. Thanks.
Dec 01
parent Aravinda VK <mail aravindavk.in> writes:
On Sunday, 1 December 2024 at 16:40:56 UTC, Aravinda VK wrote:
 On Friday, 29 November 2024 at 14:02:38 UTC, Alain De Vos wrote:
 I want to plot a pixel in blue at coordinates (100,100) on a 
 canvas of size (200,200)
 I think i can use the arsd module.
 But i have no idea what "dub add" comment I should use.
 What i should import
 How this demo program would look.
 Cfr,
 https://www.reddit.com/r/scala/comments/1h2g8a2/simple_graphics_api/
 https://www.reddit.com/r/fsharp/comments/1h2g7pv/simple_graphics_api/
You can use Chitra library. It is still under active development, working on adding support for text and curves. Refer this documentation to install the dependencies and add Chitra to your project. Chitra is based on Cairo Graphics for 2D graphics and PangoCairo for rendering texts. https://github.com/aravindavk/chitra-d Example for your use case, ```d import chitra; void main() { auto ctx = new Chitra(200, 200); ctx.pixel(100, 100); ctx.saveAs("dot.png"); } ``` Or just run the file without installing it, like below. Create a file `dot.d` with the following content. ```d /+ dub.sdl: dependency "chitra" version="~>0.1.0" +/ import chitra; void main() { auto ctx = new Chitra(200, 200); ctx.pixel(100, 100); ctx.saveAs("dot.png"); } ``` And run as `dub dot.d` Let me know if this works for you. Thanks.
Missed adding color in the above example (Also added the alternate syntax using `with` statement). ```d import chitra; void main() { auto ctx = new Chitra(200, 200); with(ctx) { fill("blue"); pixel(100, 100); saveAs("dot.png"); } } ```
Dec 01