{"id":4171,"date":"2022-01-24T14:46:30","date_gmt":"2022-01-24T14:46:30","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=4171"},"modified":"2022-01-24T14:46:31","modified_gmt":"2022-01-24T14:46:31","slug":"11c-wxwidgets-drawing-points","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2022\/01\/24\/11c-wxwidgets-drawing-points\/","title":{"rendered":"11c.wxWidgets &#8211; Drawing Points"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p><em>DrawPoint()<\/em> is the simplest GDI function as it draws a point at the given x,y coordinates.  In the sample code below, we draw 5000 points at random places in a window.<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">points.h<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n\t#include &lt;wx\/wx.h&gt;\n#endif\n\nclass Points: public wxFrame {\n\tpublic:\n\t\tPoints(const wxString &amp;title);\n\t\tvoid onPaint(wxPaintEvent &amp;event);\n\tprivate:\n\t\twxPanel *mPanel;\t\n\t\n};\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">points.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;points.h&quot;\n#include &lt;stdlib.h&gt;\n#include &lt;time.h&gt;\n\nPoints::Points(const wxString &amp;title):\n\twxFrame(NULL, -1, title, wxDefaultPosition, wxSize(500,300)) {\n\tsrand(time(NULL));\n\tBind(wxEVT_PAINT, &amp;Points::onPaint, this);\n\tSetBackgroundColour(wxColour(100,200,10));\n}\n\nvoid Points::onPaint(wxPaintEvent &amp;event) {\n\twxPaintDC dc(this);\n\tint x=0,y=0;\n\twxSize size = GetSize();\n\tfor(int i =0; i &lt; 5000; i++) {\n\t\tx = rand()  % size.x + 1;\n\t\ty = rand() % size.y + 1;\n\t\tdc.DrawPoint(x, y);\n\t}\n\n\n}\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">main.h<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n\t#include &lt;wx\/wx.h&gt;\n#endif\n\nclass Main: public wxApp {\n\n\tpublic:\n\t\tvirtual bool OnInit();\n};\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">main.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;main.h&quot;\n#include &quot;points.h&quot;\n\nIMPLEMENT_APP(Main)\n\nbool Main::OnInit() {\n\tPoints *app = new Points(wxT(&quot;Points&quot;));\n\tapp-&gt;Show(true);\n\n}\n\n<\/pre><\/div>\n\n\n<p>The output is given below<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"300\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-15-20.png\" alt=\"\" class=\"wp-image-4173\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-15-20.png 500w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-15-20-300x180.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW DrawPoint() is the simplest GDI function as it draws a point at the given x,y coordinates. In the sample code below, we draw 5000 <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2022\/01\/24\/11c-wxwidgets-drawing-points\/\" title=\"11c.wxWidgets &#8211; Drawing Points\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":3595,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302,365],"tags":[],"class_list":["post-4171","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cc","category-wxwidgets"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=4171"}],"version-history":[{"count":3,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4171\/revisions"}],"predecessor-version":[{"id":4175,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4171\/revisions\/4175"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/3595"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=4171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=4171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=4171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}