Wednesday

Qt Yin Yang Painting with Changeable Size

Filename: main.cpp
Source code:

#include <QApplication> 
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsEllipseItem>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
 

    const int size = 500;
 

    QGraphicsScene scene;
    scene.setSceneRect( 0.0, 0.0, size+100, size+100 );
 

    QPen penWhite(Qt::white);
    QBrush brushWhite(Qt::white); //QBrush to fill-up shape with the color
 

    QPen penBlack(Qt::black);
    QBrush brushBlack(Qt::black); //QBrush to fill-up shape with the color
 

    //draw white big circle
    QPainterPath whiteBigCirlePainter;
    QPoint pointCircleCenter;
    pointCircleCenter.setX((size+100)/2);
    pointCircleCenter.setY((size+100)/2);
    whiteBigCirlePainter.addEllipse(pointCircleCenter, size/2, size/2);
    scene.addPath(whiteBigCirlePainter, penWhite, brushWhite);
 

    //draw black big semicircle to the right
    QPainterPath rightBlackSemicirclePath;
    rightBlackSemicirclePath.arcMoveTo((size+100)/2.0 - (size/2.0),
                                       (size+100)/2.0 - (size/2.0),
                                       size, size, 270);
    rightBlackSemicirclePath.arcTo((size+100)/2.0 - (size/2.0),
                                   (size+100)/2.0 - (size/2.0),
                                   size, size, 270, 180);
    scene.addPath(rightBlackSemicirclePath, penBlack, brushBlack);
 

    //draw black circle bottom
    QPainterPath blackCircleBottomPainter;
    QPoint pointCircleBottomCenter;
    pointCircleBottomCenter.setX((size+100)/2.0);
    pointCircleBottomCenter.setY((size+100)/2.0 + size/4.0);
    blackCircleBottomPainter.addEllipse(pointCircleBottomCenter, size/2/2, size/2/2);
    scene.addPath(blackCircleBottomPainter, penBlack, brushBlack);
 

    //draw white circle top
    QPainterPath whiteCircleTopPainter;
    QPoint pointCircleTopCenter;
    pointCircleTopCenter.setX((size+100)/2.0);
    pointCircleTopCenter.setY((size+100)/2.0 - size/4.0);
    whiteCircleTopPainter.addEllipse(pointCircleTopCenter, size/2/2, size/2/2);
    scene.addPath(whiteCircleTopPainter, penWhite, brushWhite);
 

    //draw white circle bottom eye
    QPainterPath whiteCircleBottomEyePainter;
    QPoint pointCircleBottomEyeCenter;
    pointCircleBottomEyeCenter.setX((size+100)/2.0);
    pointCircleBottomEyeCenter.setY((size+100)/2.0 + size/4.0);
    whiteCircleBottomEyePainter.addEllipse(pointCircleBottomEyeCenter, size/2/2/2/2, size/2/2/2/2);
    scene.addPath(whiteCircleBottomEyePainter, penWhite, brushWhite);
 

    //draw black circle top eye
    QPainterPath blackCircleTopEyePainter;
    QPoint pointCircleTopEyeCenter;
    pointCircleTopEyeCenter.setX((size+100)/2.0);
    pointCircleTopEyeCenter.setY((size+100)/2.0 - size/4.0);
    blackCircleTopEyePainter.addEllipse(pointCircleTopEyeCenter, size/2/2/2/2, size/2/2/2/2);
    scene.addPath(blackCircleTopEyePainter, penBlack, brushBlack);
 

    //draw big circle black outline
    QPainterPath bigCircleBlackOutlinePainter;
    bigCircleBlackOutlinePainter.addEllipse(pointCircleCenter, size/2, size/2);
    scene.addPath(bigCircleBlackOutlinePainter, penBlack, Qt::NoBrush);
 

    QGraphicsView view( &scene );
    view.setRenderHint(QPainter::Antialiasing); //antialias edges of primitives if possible
    view.setRenderHint(QPainter::HighQualityAntialiasing); //an OpenGL-specific rendering hint
    view.setWindowTitle("My Yin Yang Painting");
    view.show();
 

    return app.exec();
}
 
 
Project Output:

Sunday

Linux Mint Cinnamon: Install Qt for C++ GUI Programming

Start Menu > Administration > Software Manager

Search box > type > Qt-sdk
Double-click the Qt-sdk displayed result on one of the rows
Click the button Install
Wait until the download and installation actions completed

Start Menu > Programming > Qt Creator
Try to write some programs

Tuesday

Linux Mint Cinnamon: How to run Raptor Flowchart Programming App on Linux Mint using Wine Software?

How to run Raptor Flowchart Programming App on Linux Mint using Wine Software?

Start Menu > Administration > Software Manager
Enter your password to perform administrative tasks

Search box > type > Wine

Double-click the row Wine
Wine is Microsoft windows compatibility layer (meta-package)

Click the button Install
Wait until installation has finished

Start Menu > Wine > Configure Wine
Install “Wine Mono Installer”, click the button Install
Install “Wine Gecko Installer”, click the button Install
Wait until two installations have finished

Download Raptor portable app at
http://raptor.martincarlisle.com/RaptorPortable_4.0_Revision_6.paf.exe
Save the RaptorPortable_4.0_Revision_6.paf.exe in the home directory
Right-click “RaptorPortable_4.0_Revision_6.paf.exe” > Open With > Wine Windows Program Loader
Click the button Finish to finish the unzip process

To run the Raptor app on Linux Mint:
-- Right-click the RaptorPortable.exe in the RaptorPortable directory
-- Select "Open With" > "Wine Windows Program Loader"

Save your empty flowchart as the rap file extension
Draw a flowchart and check by yourself if your paper drawn flowchart is correct

Getting Started with C++ 2017 using gcc v6.1.0 32-bit

Steps are as follows:

Download gcc v6.1.0 32-bit from
ftp://ftp.equation.com/gcc/gcc-6.1.0-32.exe
Filename: gcc-6.1.0-32.exe

Install gcc 32-bit to "C:\gcc-6.1.0-32"

Please log off and log in again to configure the gcc for all users on this operating system.

Download and install Notepad++ from
https://notepad-plus-plus.org/download/

Open Notepad++
Save the new file as "cpp2017_eg1.cpp"

Filename: cpp2017_eg1.cpp
File content:
/********************/
#define __STDCPP_WANT_MATH_SPEC_FUNCS__ 1 //betaf(), beta()
#include <iostream>
#include <string>
#include <experimental/string_view>
#include <cmath>
using namespace std;

int main()

    cout << __cplusplus << endl; //201500

    //Hexadecimal literals
    int hex1 = 0xA;  
    cout << hex1 << endl; //10  
  
    experimental::string_view v = "hello world";
    v = v.substr(7);
    cout << v << endl; //orld

    //Mathematical special functions from C++ 2017
    cout << betaf(4.0f, 2.0f) << endl; //0.05

    int n = 4;
    int k = 2;
    cout << 1/( (n+1)*beta(n-k+1, k+1) ) << endl; //6
    // C(4,2)=4!/(2!2!)=4x3/2=6
  
    cout << expint(1) << endl; //1.89512, exponential integral
    cout << riemann_zeta(2) << endl; //1.64493          
  
    return 0;
}

/********************/

Program output: Open command prompt window

C:\my_folder_path> g++ --version
g++ (GCC) 6.1.0

C:\my_folder_path> g++ -std=c++17 cpp2017_eg1.cpp -o a.exe

C:\my_folder_path> a.exe
201500
10
orld
0.05
6
1.89512
1.64493

Step to uninstall GCC downloaded from
http://www.equation.com/servlet/equation.cmd?fa=fortran

* Open the system “Environment Variables” frame
* Delete the system variable named “EQ_LIBRARY_PATH” which contains the following variable value "C:\gcc-6.1.0-32\i686-pc-mingw32\lib"
* Delete the following two system path values from the system variable named “Path”:
*** "C:\gcc-6.1.0-32\bin;”
*** “C:\gcc-6.1.0-32\libexec\gcc\i686-pc-mingw32\6.1.0;"
* Delete the directory at “C:\gcc-6.1.0-32”

Friday

Qt C++: Solution for “error: variable 'QPointer label' has initializer but incomplete type”

Qt C++: Solution for “error: variable 'QPointer<QLabel> label' has initializer but incomplete type”

C++ Code with Error message:

void MainWindow::on_pushButton_clicked()
{
  QPointer<QLabel> label = ui->label1;

  label->setText("Label 1 text changed");
}

Solution:

You need to include the “#include <QPointer>“ at the top section in this implementation file.
 

Qt C++: Solution for “error: only constructors take member initializers” and “warning: no return statement in function returning non-void [-Wreturn-type]”

Qt C++: Solution for “error: only constructors take member initializers” and “warning: no return statement in function returning non-void [-Wreturn-type]”

C++ Code with Error and Warning messages:

class ClassName
{
private:
  QString s;
  double d;
public:
  ClassKName(QString s="noName", double d=0.0) : s(s), d(d)
  {
  }
};

Solution:

The constructor name is different from the class name.
Rename the constructor name ClassKName to be the same with ClassName without the extra letter ‘K’.
 

Wednesday

Qt C++: Programming Fundamental Concepts: if-else statement

Program title: if-else statement

C++ Code:

#include <QApplication> 

#include <QDebug>
#include <QMainWindow> //QMainWindow *window
#include <QLabel>
#include <QHBoxLayout> //layout->addWidget(label)
#include <QWidget> //centralWidget->setLayout(layout)
#include <QInputDialog>
#include <QString>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QMainWindow *window = new QMainWindow();

    QLabel *label = new QLabel("No Result");

    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(label);

    QWidget *centralWidget = new QWidget(window); //centralWidget parent is the window
    centralWidget->setLayout(layout);

    window->setCentralWidget(centralWidget);
    window->setWindowTitle("My Main Window");
    window->resize(400, 400);
    window->show();

    int n = QInputDialog::getInt(window, "Input Dialog",
                                 "Enter a percentage", 25, //25 is the default value
                                 0, 100, 1); //min, max, step

    if(n>=50) {
        qDebug() << "Percentage is greater than or equal to fifty";
        QString s = "Percentage is greater than or equal to fifty";        
        label->setText(s);
    }
    else {
        qDebug() << "Percentage is less than fifty";
        QString s = "Percentage is less than fifty";
        label->setText(s);
    }

    return app.exec();
} 

Program Output: Vertical Toolbar > Run 

Advantages:
-- input dialog: built-in spin box for integer input
-- input dialog: can set default value
-- input dialog: built-in regular expression and input validation
-- input dialog: prevent input error

Monday

FuzzyCLIPS: Certainty Factor example

Enter the following code statement-by-statement in the FuzzyCLIPS's Dialog Window:

FuzzyCLIPS> (defrule organism-is-streptococcus
(declare (CF 0.7))
(stain positive)
(morphology coccus)
(growth chains)
=>
(assert (organism streptococcus))
)

FuzzyCLIPS> (assert (stain positive) CF 0.5)
FuzzyCLIPS> (assert (morphology coccus) CF 0.6)
FuzzyCLIPS> (assert (growth chains) CF 0.3)

FuzzyCLIPS> (run)
FuzzyCLIPS> (facts)
f-0     (stain positive) CF 0.50
f-1     (morphology coccus) CF 0.60
f-2     (growth chains) CF 0.30
f-3     (organism streptococcus) CF 0.21
For a total of 4 facts.

The certainty factor of the conclusion using hand calculations
= min(0,5,0.6,0.3) * 0.7
= 0.3 * 0.7 = 0.21

FuzzyCLIPS: How to change the program icon

Download the FuzzyCLIPS icon below to your computer and rename it to "fzclipswin.ico" with .ico file extension name. Copy this file to C:\Windows\System32\fzclipswin.ico.



Right-click on the fzclipwin.exe at C:\FuzzyCLIPS\pc-prjct\VC++\fzClips\fzclipswin\Release\fzclipswin.exe, select "Send to | Desktop (create shortcut)"

Right-click the fzclipwin shortcut on the desktop, select Properties.
Tab on the Shortcut.
Click on the button "Change Icon".
Browse to "C:\Windows\System32\fzclipswin.ico" and click the button OK.

Friday

OMNeT++: "Error in module (cModule) (id=1) during network setup..." Solution

Problem:

Frame title: Confirm
Frame content:
Error in module (cModule) "network name in ned file" (id=1) during network setup: Class "class name in cc file and simple name in ned file" not found -- perhaps its code was not linked in, or the class wasn't registered with Register_Class(), or in the case of modules and channels, with Define_Module()/Define_Channel().

Solution:

Right-click the project > select Build Project
In the console frame, you should get the following successful message: 12:34:56 Build Finished (took 5s.864ms)

Right-click the project > Run As > OMNeT++ Simulation

Monday

How to learn and interact with Mathematics on the browser using GeoGebra?

-- Browse to
http://app.geogebra.org/
-- Click on the Algebra link
--  On the left input textfield, type the following and then hit the enter key:
---- c =1
---- m = 2
---- y=mx + c
-- Click on "Toolbar > Angle of two lines with alpha icon > Slope". Click on the line to view the slope in triangle form
-- Go to the slider, drag to the left or drag to the right to change the c or m values
-- Other than Algebra section, try other Mathematics sections like Geometry, Spreadsheet, CAS, 3D Graphics, and Probability

An example from the above steps:


 

References
-- Animation: Move a Point, https://www.geogebra.org/m/n5ddtD86
-- Draw two functions in one graph with restricted domains, https://www.geogebra.org/m/GXC4GVEE

Thursday

LibreOffice Writer: Do not Hyphen or Dash to break a word

Steps are:
-- Highlight a paragraph
-- Right-click and select Paragraph
-- Tab on "Text Flow"
-- Under Hyphenation section, untick the check box Automatically
Yeah

If a hater attacked your age and not the goodness of you

Whether young or old, I've always been known what endures. I've known the very idea of people that were all created equal and deserv...